discorb 0.19.0 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
@@ -1,246 +1,311 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Discorb
|
4
|
-
#
|
5
|
-
# Represents a channel in guild.
|
6
|
-
# @abstract
|
7
|
-
#
|
8
|
-
class GuildChannel < Channel
|
9
|
-
# @return [Integer] The position of the channel as integer.
|
10
|
-
attr_reader :position
|
11
|
-
# @return [Hash{Discorb::Role, Discorb::Member => PermissionOverwrite}] The permission overwrites of the channel.
|
12
|
-
attr_reader :permission_overwrites
|
13
|
-
|
14
|
-
# @!attribute [r] mention
|
15
|
-
# @return [String] The mention of the channel.
|
16
|
-
#
|
17
|
-
# @!attribute [r] parent
|
18
|
-
# @macro client_cache
|
19
|
-
# @return [Discorb::CategoryChannel] The parent of channel.
|
20
|
-
# @return [nil] If the channel is not a child of category.
|
21
|
-
#
|
22
|
-
# @!attribute [r] guild
|
23
|
-
# @return [Discorb::Guild] The guild of channel.
|
24
|
-
# @macro client_cache
|
25
|
-
|
26
|
-
include Comparable
|
27
|
-
@channel_type = nil
|
28
|
-
|
29
|
-
#
|
30
|
-
# Compares position of two channels.
|
31
|
-
#
|
32
|
-
# @param [Discorb::GuildChannel] other The channel to compare.
|
33
|
-
#
|
34
|
-
# @return [-1, 0, 1] -1 if the channel is at lower than the other, 1 if the channel is at highter than the other.
|
35
|
-
#
|
36
|
-
def <=>(other)
|
37
|
-
return nil unless other.respond_to?(:position)
|
38
|
-
|
39
|
-
@position <=> other.position
|
40
|
-
end
|
41
|
-
|
42
|
-
#
|
43
|
-
# Checks if the channel is same as another.
|
44
|
-
#
|
45
|
-
# @param [Discorb::GuildChannel] other The channel to check.
|
46
|
-
#
|
47
|
-
# @return [Boolean] `true` if the channel is same as another.
|
48
|
-
#
|
49
|
-
def ==(other)
|
50
|
-
return false unless other.respond_to?(:id)
|
51
|
-
|
52
|
-
@id == other.id
|
53
|
-
end
|
54
|
-
|
55
|
-
#
|
56
|
-
# Stringifies the channel.
|
57
|
-
#
|
58
|
-
# @return [String] The name of the channel with `#`.
|
59
|
-
#
|
60
|
-
def to_s
|
61
|
-
"##{@name}"
|
62
|
-
end
|
63
|
-
|
64
|
-
def mention
|
65
|
-
"<##{@id}>"
|
66
|
-
end
|
67
|
-
|
68
|
-
def parent
|
69
|
-
return nil unless @parent_id
|
70
|
-
|
71
|
-
@client.channels[@parent_id]
|
72
|
-
end
|
73
|
-
|
74
|
-
alias category parent
|
75
|
-
|
76
|
-
def guild
|
77
|
-
@client.guilds[@guild_id]
|
78
|
-
end
|
79
|
-
|
80
|
-
def inspect
|
81
|
-
"#<#{self.class} \"##{@name}\" id=#{@id}>"
|
82
|
-
end
|
83
|
-
|
84
|
-
#
|
85
|
-
# Deletes the channel.
|
86
|
-
# @async
|
87
|
-
#
|
88
|
-
# @param [String] reason The reason of deleting the channel.
|
89
|
-
#
|
90
|
-
# @return [Async::Task<self>] The deleted channel.
|
91
|
-
#
|
92
|
-
def delete(reason: nil)
|
93
|
-
Async do
|
94
|
-
@client
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
#
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
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
|
-
@client
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
#
|
200
|
-
#
|
201
|
-
# @
|
202
|
-
#
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Discorb
|
4
|
+
#
|
5
|
+
# Represents a channel in guild.
|
6
|
+
# @abstract
|
7
|
+
#
|
8
|
+
class GuildChannel < Channel
|
9
|
+
# @return [Integer] The position of the channel as integer.
|
10
|
+
attr_reader :position
|
11
|
+
# @return [Hash{Discorb::Role, Discorb::Member => PermissionOverwrite}] The permission overwrites of the channel.
|
12
|
+
attr_reader :permission_overwrites
|
13
|
+
|
14
|
+
# @!attribute [r] mention
|
15
|
+
# @return [String] The mention of the channel.
|
16
|
+
#
|
17
|
+
# @!attribute [r] parent
|
18
|
+
# @macro client_cache
|
19
|
+
# @return [Discorb::CategoryChannel] The parent of channel.
|
20
|
+
# @return [nil] If the channel is not a child of category.
|
21
|
+
#
|
22
|
+
# @!attribute [r] guild
|
23
|
+
# @return [Discorb::Guild] The guild of channel.
|
24
|
+
# @macro client_cache
|
25
|
+
|
26
|
+
include Comparable
|
27
|
+
@channel_type = nil
|
28
|
+
|
29
|
+
#
|
30
|
+
# Compares position of two channels.
|
31
|
+
#
|
32
|
+
# @param [Discorb::GuildChannel] other The channel to compare.
|
33
|
+
#
|
34
|
+
# @return [-1, 0, 1] -1 if the channel is at lower than the other, 1 if the channel is at highter than the other.
|
35
|
+
#
|
36
|
+
def <=>(other)
|
37
|
+
return nil unless other.respond_to?(:position)
|
38
|
+
|
39
|
+
@position <=> other.position
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
43
|
+
# Checks if the channel is same as another.
|
44
|
+
#
|
45
|
+
# @param [Discorb::GuildChannel] other The channel to check.
|
46
|
+
#
|
47
|
+
# @return [Boolean] `true` if the channel is same as another.
|
48
|
+
#
|
49
|
+
def ==(other)
|
50
|
+
return false unless other.respond_to?(:id)
|
51
|
+
|
52
|
+
@id == other.id
|
53
|
+
end
|
54
|
+
|
55
|
+
#
|
56
|
+
# Stringifies the channel.
|
57
|
+
#
|
58
|
+
# @return [String] The name of the channel with `#`.
|
59
|
+
#
|
60
|
+
def to_s
|
61
|
+
"##{@name}"
|
62
|
+
end
|
63
|
+
|
64
|
+
def mention
|
65
|
+
"<##{@id}>"
|
66
|
+
end
|
67
|
+
|
68
|
+
def parent
|
69
|
+
return nil unless @parent_id
|
70
|
+
|
71
|
+
@client.channels[@parent_id]
|
72
|
+
end
|
73
|
+
|
74
|
+
alias category parent
|
75
|
+
|
76
|
+
def guild
|
77
|
+
@client.guilds[@guild_id]
|
78
|
+
end
|
79
|
+
|
80
|
+
def inspect
|
81
|
+
"#<#{self.class} \"##{@name}\" id=#{@id}>"
|
82
|
+
end
|
83
|
+
|
84
|
+
#
|
85
|
+
# Deletes the channel.
|
86
|
+
# @async
|
87
|
+
#
|
88
|
+
# @param [String] reason The reason of deleting the channel.
|
89
|
+
#
|
90
|
+
# @return [Async::Task<self>] The deleted channel.
|
91
|
+
#
|
92
|
+
def delete(reason: nil)
|
93
|
+
Async do
|
94
|
+
@client
|
95
|
+
.http
|
96
|
+
.request(
|
97
|
+
Route.new(
|
98
|
+
base_url.wait.to_s,
|
99
|
+
"//webhooks/:webhook_id/:token",
|
100
|
+
:delete
|
101
|
+
),
|
102
|
+
{},
|
103
|
+
audit_log_reason: reason
|
104
|
+
)
|
105
|
+
.wait
|
106
|
+
@deleted = true
|
107
|
+
self
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
alias close delete
|
112
|
+
alias destroy delete
|
113
|
+
|
114
|
+
#
|
115
|
+
# Moves the channel to another position.
|
116
|
+
# @async
|
117
|
+
#
|
118
|
+
# @param [Integer] position The position to move the channel.
|
119
|
+
# @param [Boolean] lock_permissions Whether to lock the permissions of the channel.
|
120
|
+
# @param [Discorb::CategoryChannel] parent The parent of channel.
|
121
|
+
# @param [String] reason The reason of moving the channel.
|
122
|
+
#
|
123
|
+
# @return [Async::Task<self>] The moved channel.
|
124
|
+
#
|
125
|
+
def move(
|
126
|
+
position,
|
127
|
+
lock_permissions: false,
|
128
|
+
parent: Discorb::Unset,
|
129
|
+
reason: nil
|
130
|
+
)
|
131
|
+
Async do
|
132
|
+
# @type var payload: Hash[Symbol, untyped]
|
133
|
+
payload = { position: position }
|
134
|
+
payload[:lock_permissions] = lock_permissions
|
135
|
+
payload[:parent_id] = parent&.id if parent != Discorb::Unset
|
136
|
+
@client
|
137
|
+
.http
|
138
|
+
.request(
|
139
|
+
Route.new(
|
140
|
+
"/guilds/#{@guild_id}/channels",
|
141
|
+
"//guilds/:guild_id/channels",
|
142
|
+
:patch
|
143
|
+
),
|
144
|
+
payload,
|
145
|
+
audit_log_reason: reason
|
146
|
+
)
|
147
|
+
.wait
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
#
|
152
|
+
# Set the channel's permission overwrite.
|
153
|
+
# @async
|
154
|
+
#
|
155
|
+
# @param [Discorb::Role, Discorb::Member] target The target of the overwrite.
|
156
|
+
# @param [String] reason The reason of setting the overwrite.
|
157
|
+
# @param [{Symbol => Boolean}] perms The permission overwrites to replace.
|
158
|
+
#
|
159
|
+
# @return [Async::Task<void>] The task.
|
160
|
+
#
|
161
|
+
def set_permissions(target, reason: nil, **perms)
|
162
|
+
Async do
|
163
|
+
allow_value = @permission_overwrites[target]&.allow_value.to_i
|
164
|
+
deny_value = @permission_overwrites[target]&.deny_value.to_i
|
165
|
+
perms.each do |perm, value|
|
166
|
+
allow_value[Discorb::Permission.bits[perm]] = 1 if value == true
|
167
|
+
deny_value[Discorb::Permission.bits[perm]] = 1 if value == false
|
168
|
+
end
|
169
|
+
payload = {
|
170
|
+
allow: allow_value,
|
171
|
+
deny: deny_value,
|
172
|
+
type: target.is_a?(Member) ? 1 : 0
|
173
|
+
}
|
174
|
+
@client
|
175
|
+
.http
|
176
|
+
.request(
|
177
|
+
Route.new(
|
178
|
+
"/channels/#{@id}/permissions/#{target.id}",
|
179
|
+
"//channels/:channel_id/permissions/:target_id",
|
180
|
+
:put
|
181
|
+
),
|
182
|
+
payload,
|
183
|
+
audit_log_reason: reason
|
184
|
+
)
|
185
|
+
.wait
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
alias modify_permissions set_permissions
|
190
|
+
alias modify_permisssion set_permissions
|
191
|
+
alias edit_permissions set_permissions
|
192
|
+
alias edit_permission set_permissions
|
193
|
+
|
194
|
+
#
|
195
|
+
# Delete the channel's permission overwrite.
|
196
|
+
# @async
|
197
|
+
#
|
198
|
+
# @param [Discorb::Role, Discorb::Member] target The target of the overwrite.
|
199
|
+
# @param [String] reason The reason of deleting the overwrite.
|
200
|
+
#
|
201
|
+
# @return [Async::Task<void>] The task.
|
202
|
+
#
|
203
|
+
def delete_permissions(target, reason: nil)
|
204
|
+
Async do
|
205
|
+
@client
|
206
|
+
.http
|
207
|
+
.request(
|
208
|
+
Route.new(
|
209
|
+
"/channels/#{@id}/permissions/#{target.id}",
|
210
|
+
"//channels/:channel_id/permissions/:target_id",
|
211
|
+
:delete
|
212
|
+
),
|
213
|
+
{},
|
214
|
+
audit_log_reason: reason
|
215
|
+
)
|
216
|
+
.wait
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
alias delete_permission delete_permissions
|
221
|
+
alias destroy_permissions delete_permissions
|
222
|
+
alias destroy_permission delete_permissions
|
223
|
+
|
224
|
+
#
|
225
|
+
# Fetch the channel's invites.
|
226
|
+
# @async
|
227
|
+
#
|
228
|
+
# @return [Async::Task<Array<Discorb::Invite>>] The invites in the channel.
|
229
|
+
#
|
230
|
+
def fetch_invites
|
231
|
+
Async do
|
232
|
+
_resp, data =
|
233
|
+
@client
|
234
|
+
.http
|
235
|
+
.request(
|
236
|
+
Route.new(
|
237
|
+
"/channels/#{@id}/invites",
|
238
|
+
"//channels/:channel_id/invites",
|
239
|
+
:get
|
240
|
+
)
|
241
|
+
)
|
242
|
+
.wait
|
243
|
+
data.map { |invite| Invite.new(@client, invite, false) }
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
#
|
248
|
+
# Create an invite in the channel.
|
249
|
+
# @async
|
250
|
+
#
|
251
|
+
# @param [Integer] max_age The max age of the invite.
|
252
|
+
# @param [Integer] max_uses The max uses of the invite.
|
253
|
+
# @param [Boolean] temporary Whether the invite is temporary.
|
254
|
+
# @param [Boolean] unique Whether the invite is unique.
|
255
|
+
# @note if it's `false` it may return existing invite.
|
256
|
+
# @param [String] reason The reason of creating the invite.
|
257
|
+
#
|
258
|
+
# @return [Async::Task<Invite>] The created invite.
|
259
|
+
#
|
260
|
+
def create_invite(
|
261
|
+
max_age: nil,
|
262
|
+
max_uses: nil,
|
263
|
+
temporary: false,
|
264
|
+
unique: false,
|
265
|
+
reason: nil
|
266
|
+
)
|
267
|
+
Async do
|
268
|
+
_resp, data =
|
269
|
+
@client
|
270
|
+
.http
|
271
|
+
.request(
|
272
|
+
Route.new(
|
273
|
+
"/channels/#{@id}/invites",
|
274
|
+
"//channels/:channel_id/invites",
|
275
|
+
:post
|
276
|
+
),
|
277
|
+
{
|
278
|
+
max_age: max_age,
|
279
|
+
max_uses: max_uses,
|
280
|
+
temporary: temporary,
|
281
|
+
unique: unique
|
282
|
+
},
|
283
|
+
audit_log_reason: reason
|
284
|
+
)
|
285
|
+
.wait
|
286
|
+
Invite.new(@client, data, false)
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
private
|
291
|
+
|
292
|
+
def _set_data(data)
|
293
|
+
@guild_id = data[:guild_id]
|
294
|
+
@position = data[:position]
|
295
|
+
@permission_overwrites =
|
296
|
+
if data[:permission_overwrites]
|
297
|
+
data[:permission_overwrites].to_h do |ow|
|
298
|
+
[
|
299
|
+
(ow[:type] == 1 ? guild.roles : guild.members)[ow[:id]],
|
300
|
+
PermissionOverwrite.new(ow[:allow].to_i, ow[:deny].to_i)
|
301
|
+
]
|
302
|
+
end
|
303
|
+
else
|
304
|
+
{}
|
305
|
+
end
|
306
|
+
@parent_id = data[:parent_id]
|
307
|
+
|
308
|
+
super
|
309
|
+
end
|
310
|
+
end
|
311
|
+
end
|