discorb 0.19.0 → 0.20.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/build_version.yml +2 -2
- data/.rubocop.yml +12 -75
- data/Changelog.md +10 -0
- data/Rakefile +482 -454
- data/lib/discorb/allowed_mentions.rb +68 -72
- data/lib/discorb/app_command/command.rb +466 -398
- data/lib/discorb/app_command/common.rb +65 -25
- data/lib/discorb/app_command/handler.rb +304 -266
- data/lib/discorb/app_command.rb +5 -5
- data/lib/discorb/application.rb +198 -197
- data/lib/discorb/asset.rb +101 -101
- data/lib/discorb/attachment.rb +134 -119
- data/lib/discorb/audit_logs.rb +412 -385
- data/lib/discorb/automod.rb +279 -269
- data/lib/discorb/channel/base.rb +107 -108
- data/lib/discorb/channel/category.rb +32 -32
- data/lib/discorb/channel/container.rb +44 -44
- data/lib/discorb/channel/dm.rb +26 -28
- data/lib/discorb/channel/guild.rb +311 -246
- data/lib/discorb/channel/stage.rb +156 -140
- data/lib/discorb/channel/text.rb +430 -336
- data/lib/discorb/channel/thread.rb +374 -325
- data/lib/discorb/channel/voice.rb +85 -79
- data/lib/discorb/channel.rb +5 -5
- data/lib/discorb/client.rb +635 -621
- data/lib/discorb/color.rb +178 -182
- data/lib/discorb/common.rb +168 -164
- data/lib/discorb/components/button.rb +107 -106
- data/lib/discorb/components/select_menu.rb +157 -145
- data/lib/discorb/components/text_input.rb +103 -106
- data/lib/discorb/components.rb +68 -66
- data/lib/discorb/dictionary.rb +135 -135
- data/lib/discorb/embed.rb +404 -398
- data/lib/discorb/emoji.rb +309 -302
- data/lib/discorb/emoji_table.rb +16099 -8857
- data/lib/discorb/error.rb +131 -131
- data/lib/discorb/event.rb +360 -314
- data/lib/discorb/event_handler.rb +39 -39
- data/lib/discorb/exe/about.rb +17 -17
- data/lib/discorb/exe/irb.rb +72 -67
- data/lib/discorb/exe/new.rb +323 -315
- data/lib/discorb/exe/run.rb +69 -68
- data/lib/discorb/exe/setup.rb +57 -55
- data/lib/discorb/exe/show.rb +12 -12
- data/lib/discorb/extend.rb +25 -45
- data/lib/discorb/extension.rb +89 -83
- data/lib/discorb/flag.rb +126 -128
- data/lib/discorb/gateway.rb +984 -804
- data/lib/discorb/gateway_events.rb +670 -638
- data/lib/discorb/gateway_requests.rb +45 -48
- data/lib/discorb/guild.rb +2115 -1626
- data/lib/discorb/guild_template.rb +280 -241
- data/lib/discorb/http.rb +247 -232
- data/lib/discorb/image.rb +42 -42
- data/lib/discorb/integration.rb +169 -161
- data/lib/discorb/intents.rb +161 -163
- data/lib/discorb/interaction/autocomplete.rb +76 -62
- data/lib/discorb/interaction/command.rb +279 -224
- data/lib/discorb/interaction/components.rb +114 -104
- data/lib/discorb/interaction/modal.rb +36 -32
- data/lib/discorb/interaction/response.rb +379 -336
- data/lib/discorb/interaction/root.rb +271 -257
- data/lib/discorb/interaction.rb +5 -5
- data/lib/discorb/invite.rb +154 -153
- data/lib/discorb/member.rb +344 -311
- data/lib/discorb/message.rb +615 -544
- data/lib/discorb/message_meta.rb +197 -186
- data/lib/discorb/modules.rb +371 -290
- data/lib/discorb/permission.rb +305 -291
- data/lib/discorb/presence.rb +352 -346
- data/lib/discorb/rate_limit.rb +81 -76
- data/lib/discorb/reaction.rb +55 -54
- data/lib/discorb/role.rb +272 -240
- data/lib/discorb/shard.rb +76 -74
- data/lib/discorb/sticker.rb +193 -171
- data/lib/discorb/user.rb +205 -188
- data/lib/discorb/utils/colored_puts.rb +16 -16
- data/lib/discorb/utils.rb +12 -16
- data/lib/discorb/voice_state.rb +305 -281
- data/lib/discorb/webhook.rb +537 -507
- data/lib/discorb.rb +62 -56
- data/sig/discorb/application.rbs +2 -0
- data/sig/discorb/automod.rbs +10 -1
- data/sig/discorb/guild.rbs +2 -0
- data/sig/discorb/message.rbs +2 -0
- data/sig/discorb/user.rbs +22 -20
- metadata +2 -2
data/lib/discorb/user.rb
CHANGED
@@ -1,188 +1,205 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Discorb
|
4
|
-
#
|
5
|
-
# Represents a user of discord.
|
6
|
-
#
|
7
|
-
class User < DiscordModel
|
8
|
-
# @return [Boolean] Whether the user is verified.
|
9
|
-
attr_reader :verified
|
10
|
-
# @return [String] The user's username.
|
11
|
-
attr_reader :username
|
12
|
-
alias name username
|
13
|
-
# @return [Discorb::Snowflake] The user's ID.
|
14
|
-
attr_reader :id
|
15
|
-
# @return [Discorb::User::Flag] The user's flags.
|
16
|
-
attr_reader :flag
|
17
|
-
# @return [String] The user's discriminator.
|
18
|
-
attr_reader :discriminator
|
19
|
-
# @return [Discorb::Asset, Discorb::DefaultAvatar] The user's avatar.
|
20
|
-
attr_reader :avatar
|
21
|
-
# @return [Boolean] Whether the user is a bot.
|
22
|
-
attr_reader :bot
|
23
|
-
alias bot? bot
|
24
|
-
# @return [Time] The time the user was created.
|
25
|
-
attr_reader :created_at
|
26
|
-
|
27
|
-
include Discorb::Messageable
|
28
|
-
|
29
|
-
# @!attribute [r] mention
|
30
|
-
# @return [String] The user's mention.
|
31
|
-
|
32
|
-
#
|
33
|
-
# Initializes a new user.
|
34
|
-
# @private
|
35
|
-
#
|
36
|
-
# @param [Discorb::Client] client The client.
|
37
|
-
# @param [Hash] data The user data.
|
38
|
-
#
|
39
|
-
def initialize(client, data)
|
40
|
-
@client = client
|
41
|
-
@data = {}
|
42
|
-
@dm_channel_id = nil
|
43
|
-
_set_data(data)
|
44
|
-
end
|
45
|
-
|
46
|
-
#
|
47
|
-
# Format the user as `Username#Discriminator` style.
|
48
|
-
#
|
49
|
-
# @return [String] The formatted username.
|
50
|
-
#
|
51
|
-
def to_s
|
52
|
-
"#{@username}##{@discriminator}"
|
53
|
-
end
|
54
|
-
|
55
|
-
def mention
|
56
|
-
"<@#{@id}>"
|
57
|
-
end
|
58
|
-
|
59
|
-
alias to_s_user to_s
|
60
|
-
|
61
|
-
def inspect
|
62
|
-
"#<#{self.class} #{self}>"
|
63
|
-
end
|
64
|
-
|
65
|
-
#
|
66
|
-
# Whether the user is a owner of the client.
|
67
|
-
# @async
|
68
|
-
#
|
69
|
-
# @param [Boolean] strict Whether don't allow if the user is a member of the team.
|
70
|
-
#
|
71
|
-
# @return [Async::Task<Boolean>] Whether the user is a owner of the client.
|
72
|
-
#
|
73
|
-
def bot_owner?(strict: false)
|
74
|
-
Async do
|
75
|
-
app = @client.fetch_application.wait
|
76
|
-
if app.team.nil?
|
77
|
-
app.owner == self
|
78
|
-
elsif strict
|
79
|
-
app.team.owner == self
|
80
|
-
else
|
81
|
-
app.team.members.any? { |m| m.user == self }
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
alias app_owner? bot_owner?
|
87
|
-
|
88
|
-
#
|
89
|
-
# Returns the dm channel id of the user.
|
90
|
-
# @private
|
91
|
-
#
|
92
|
-
# @return [Async::Task<Discorb::Snowflake>] A task that resolves to the channel id.
|
93
|
-
#
|
94
|
-
def channel_id
|
95
|
-
Async do
|
96
|
-
next @dm_channel_id if @dm_channel_id
|
97
|
-
|
98
|
-
_resp, dm_channel =
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
#
|
112
|
-
#
|
113
|
-
#
|
114
|
-
# |`1 <<
|
115
|
-
# |`1 <<
|
116
|
-
# |`1 <<
|
117
|
-
# |`1 <<
|
118
|
-
# |`1 <<
|
119
|
-
# |`1 <<
|
120
|
-
# |`1 <<
|
121
|
-
#
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
@
|
152
|
-
@
|
153
|
-
@
|
154
|
-
@
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Discorb
|
4
|
+
#
|
5
|
+
# Represents a user of discord.
|
6
|
+
#
|
7
|
+
class User < DiscordModel
|
8
|
+
# @return [Boolean] Whether the user is verified.
|
9
|
+
attr_reader :verified
|
10
|
+
# @return [String] The user's username.
|
11
|
+
attr_reader :username
|
12
|
+
alias name username
|
13
|
+
# @return [Discorb::Snowflake] The user's ID.
|
14
|
+
attr_reader :id
|
15
|
+
# @return [Discorb::User::Flag] The user's flags.
|
16
|
+
attr_reader :flag
|
17
|
+
# @return [String] The user's discriminator.
|
18
|
+
attr_reader :discriminator
|
19
|
+
# @return [Discorb::Asset, Discorb::DefaultAvatar] The user's avatar.
|
20
|
+
attr_reader :avatar
|
21
|
+
# @return [Boolean] Whether the user is a bot.
|
22
|
+
attr_reader :bot
|
23
|
+
alias bot? bot
|
24
|
+
# @return [Time] The time the user was created.
|
25
|
+
attr_reader :created_at
|
26
|
+
|
27
|
+
include Discorb::Messageable
|
28
|
+
|
29
|
+
# @!attribute [r] mention
|
30
|
+
# @return [String] The user's mention.
|
31
|
+
|
32
|
+
#
|
33
|
+
# Initializes a new user.
|
34
|
+
# @private
|
35
|
+
#
|
36
|
+
# @param [Discorb::Client] client The client.
|
37
|
+
# @param [Hash] data The user data.
|
38
|
+
#
|
39
|
+
def initialize(client, data)
|
40
|
+
@client = client
|
41
|
+
@data = {}
|
42
|
+
@dm_channel_id = nil
|
43
|
+
_set_data(data)
|
44
|
+
end
|
45
|
+
|
46
|
+
#
|
47
|
+
# Format the user as `Username#Discriminator` style.
|
48
|
+
#
|
49
|
+
# @return [String] The formatted username.
|
50
|
+
#
|
51
|
+
def to_s
|
52
|
+
"#{@username}##{@discriminator}"
|
53
|
+
end
|
54
|
+
|
55
|
+
def mention
|
56
|
+
"<@#{@id}>"
|
57
|
+
end
|
58
|
+
|
59
|
+
alias to_s_user to_s
|
60
|
+
|
61
|
+
def inspect
|
62
|
+
"#<#{self.class} #{self}>"
|
63
|
+
end
|
64
|
+
|
65
|
+
#
|
66
|
+
# Whether the user is a owner of the client.
|
67
|
+
# @async
|
68
|
+
#
|
69
|
+
# @param [Boolean] strict Whether don't allow if the user is a member of the team.
|
70
|
+
#
|
71
|
+
# @return [Async::Task<Boolean>] Whether the user is a owner of the client.
|
72
|
+
#
|
73
|
+
def bot_owner?(strict: false)
|
74
|
+
Async do
|
75
|
+
app = @client.fetch_application.wait
|
76
|
+
if app.team.nil?
|
77
|
+
app.owner == self
|
78
|
+
elsif strict
|
79
|
+
app.team.owner == self
|
80
|
+
else
|
81
|
+
app.team.members.any? { |m| m.user == self }
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
alias app_owner? bot_owner?
|
87
|
+
|
88
|
+
#
|
89
|
+
# Returns the dm channel id of the user.
|
90
|
+
# @private
|
91
|
+
#
|
92
|
+
# @return [Async::Task<Discorb::Snowflake>] A task that resolves to the channel id.
|
93
|
+
#
|
94
|
+
def channel_id
|
95
|
+
Async do
|
96
|
+
next @dm_channel_id if @dm_channel_id
|
97
|
+
|
98
|
+
_resp, dm_channel =
|
99
|
+
@client
|
100
|
+
.http
|
101
|
+
.request(
|
102
|
+
Route.new("/users/@me/channels", "//users/@me/channels", :post),
|
103
|
+
{ recipient_id: @id }
|
104
|
+
)
|
105
|
+
.wait
|
106
|
+
@dm_channel_id = dm_channel[:id]
|
107
|
+
@dm_channel_id
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
#
|
112
|
+
# Represents the user's flags.
|
113
|
+
# ## Flag fields
|
114
|
+
# |`1 << 0`|`:staff`|
|
115
|
+
# |`1 << 1`|`:partner`|
|
116
|
+
# |`1 << 2`|`:hypesquad`|
|
117
|
+
# |`1 << 3`|`:bug_hunter_level_1`|
|
118
|
+
# |`1 << 6`|`:hypesquad_online_house_1`|
|
119
|
+
# |`1 << 7`|`:hypesquad_online_house_2`|
|
120
|
+
# |`1 << 8`|`:hypesquad_online_house_3`|
|
121
|
+
# |`1 << 9`|`:premium_early_supporter`|
|
122
|
+
# |`1 << 10`|`:team_psuedo_user`|
|
123
|
+
# |`1 << 14`|`:bug_hunter_level_2`|
|
124
|
+
# |`1 << 16`|`:verified_bot`|
|
125
|
+
# |`1 << 17`|`:verified_developer`|
|
126
|
+
# |`1 << 18`|`:certified_moderator`|
|
127
|
+
# |`1 << 19`|`:bot_http_interactions`|
|
128
|
+
#
|
129
|
+
class Flag < Discorb::Flag
|
130
|
+
@bits = {
|
131
|
+
staff: 0,
|
132
|
+
partner: 1,
|
133
|
+
hypesquad: 2,
|
134
|
+
bug_hunter_level_1: 3,
|
135
|
+
hypesquad_online_house_1: 6,
|
136
|
+
hypesquad_online_house_2: 7,
|
137
|
+
hypesquad_online_house_3: 8,
|
138
|
+
premium_early_supporter: 9,
|
139
|
+
team_psuedo_user: 10,
|
140
|
+
bug_hunter_level_2: 14,
|
141
|
+
verified_bot: 16,
|
142
|
+
verified_developer: 17,
|
143
|
+
certified_moderator: 18,
|
144
|
+
bot_http_interactions: 19
|
145
|
+
}.freeze
|
146
|
+
end
|
147
|
+
|
148
|
+
private
|
149
|
+
|
150
|
+
def _set_data(data)
|
151
|
+
@username = data[:username]
|
152
|
+
@verified = data[:verified]
|
153
|
+
@id = Snowflake.new(data[:id])
|
154
|
+
@flag = User::Flag.new(data[:public_flags] | (data[:flags] || 0))
|
155
|
+
@discriminator = data[:discriminator]
|
156
|
+
@avatar =
|
157
|
+
(
|
158
|
+
if data[:avatar]
|
159
|
+
Asset.new(self, data[:avatar])
|
160
|
+
else
|
161
|
+
DefaultAvatar.new(data[:discriminator])
|
162
|
+
end
|
163
|
+
)
|
164
|
+
@bot = data[:bot] || false
|
165
|
+
@raw_data = data
|
166
|
+
@client.users[@id] = self unless data[:no_cache]
|
167
|
+
@created_at = @id.timestamp
|
168
|
+
@data.update(data)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
#
|
173
|
+
# Represents a client user.
|
174
|
+
#
|
175
|
+
class ClientUser < User
|
176
|
+
#
|
177
|
+
# Edit the client user.
|
178
|
+
# @async
|
179
|
+
# @macro edit
|
180
|
+
#
|
181
|
+
# @param [String] name The new username.
|
182
|
+
# @param [Discorb::Image] avatar The new avatar.
|
183
|
+
#
|
184
|
+
# @return [Async::Task<void>] The task.
|
185
|
+
#
|
186
|
+
def edit(name: Discorb::Unset, avatar: Discorb::Unset)
|
187
|
+
Async do
|
188
|
+
payload = {}
|
189
|
+
payload[:username] = name unless name == Discorb::Unset
|
190
|
+
if avatar == Discorb::Unset
|
191
|
+
# Nothing
|
192
|
+
elsif avatar.nil?
|
193
|
+
payload[:avatar] = nil
|
194
|
+
else
|
195
|
+
payload[:avatar] = avatar.to_s
|
196
|
+
end
|
197
|
+
@client
|
198
|
+
.http
|
199
|
+
.request(Route.new("/users/@me", "//users/@me", :patch), payload)
|
200
|
+
.wait
|
201
|
+
self
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
@@ -1,16 +1,16 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# @private
|
4
|
-
def sputs(text)
|
5
|
-
puts "\e[92m#{text}\e[m"
|
6
|
-
end
|
7
|
-
|
8
|
-
# @private
|
9
|
-
def eputs(text)
|
10
|
-
puts "\e[91m#{text}\e[m"
|
11
|
-
end
|
12
|
-
|
13
|
-
# @private
|
14
|
-
def iputs(text)
|
15
|
-
puts "\e[90m#{text}\e[m"
|
16
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# @private
|
4
|
+
def sputs(text)
|
5
|
+
puts "\e[92m#{text}\e[m"
|
6
|
+
end
|
7
|
+
|
8
|
+
# @private
|
9
|
+
def eputs(text)
|
10
|
+
puts "\e[91m#{text}\e[m"
|
11
|
+
end
|
12
|
+
|
13
|
+
# @private
|
14
|
+
def iputs(text)
|
15
|
+
puts "\e[90m#{text}\e[m"
|
16
|
+
end
|
data/lib/discorb/utils.rb
CHANGED
@@ -1,16 +1,12 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Discorb
|
4
|
-
# @private
|
5
|
-
module Utils
|
6
|
-
def try(object, message, ...)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
module_function :try
|
15
|
-
end
|
16
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Discorb
|
4
|
+
# @private
|
5
|
+
module Utils
|
6
|
+
def try(object, message, ...)
|
7
|
+
object.respond_to?(message) ? object.send(message, ...) : object
|
8
|
+
end
|
9
|
+
|
10
|
+
module_function :try
|
11
|
+
end
|
12
|
+
end
|