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/permission.rb
CHANGED
@@ -1,291 +1,305 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Discorb
|
4
|
-
#
|
5
|
-
# Represents a permission per guild.
|
6
|
-
# ## Flag fields
|
7
|
-
#
|
8
|
-
# | Field | Value |
|
9
|
-
# |-------|-------|
|
10
|
-
# |`1 << 0`|`:create_instant_invite`|
|
11
|
-
# |`1 << 1`|`:kick_members`|
|
12
|
-
# |`1 << 2`|`:ban_members`|
|
13
|
-
# |`1 << 3`|`:administrator`|
|
14
|
-
# |`1 << 4`|`:manage_channels`|
|
15
|
-
# |`1 << 5`|`:manage_guild`|
|
16
|
-
# |`1 << 6`|`:add_reactions`|
|
17
|
-
# |`1 << 7`|`:view_audit_log`|
|
18
|
-
# |`1 << 8`|`:priority_speaker`|
|
19
|
-
# |`1 << 9`|`:stream`|
|
20
|
-
# |`1 << 10`|`:view_channel`|
|
21
|
-
# |`1 << 11`|`:send_messages`|
|
22
|
-
# |`1 << 12`|`:send_tts_messages`|
|
23
|
-
# |`1 << 13`|`:manage_messages`|
|
24
|
-
# |`1 << 14`|`:embed_links`|
|
25
|
-
# |`1 << 15`|`:attach_files`|
|
26
|
-
# |`1 << 16`|`:read_message_history`|
|
27
|
-
# |`1 << 17`|`:mention_everyone`|
|
28
|
-
# |`1 << 18`|`:use_external_emojis`|
|
29
|
-
# |`1 << 19`|`:view_guild_insights`|
|
30
|
-
# |`1 << 20`|`:connect`|
|
31
|
-
# |`1 << 21`|`:speak`|
|
32
|
-
# |`1 << 22`|`:mute_members`|
|
33
|
-
# |`1 << 23`|`:deafen_members`|
|
34
|
-
# |`1 << 24`|`:move_members`|
|
35
|
-
# |`1 << 25`|`:use_vad`|
|
36
|
-
# |`1 << 26`|`:change_nickname`|
|
37
|
-
# |`1 << 27`|`:manage_nicknames`|
|
38
|
-
# |`1 << 28`|`:manage_roles`|
|
39
|
-
# |`1 << 29`|`:manage_webhooks`|
|
40
|
-
# |`1 << 30`|`:manage_emojis`|
|
41
|
-
# |`1 << 31`|`:use_slash_commands`|
|
42
|
-
# |`1 << 32`|`:request_to_speak`|
|
43
|
-
# |`1 << 34`|`:manage_threads`|
|
44
|
-
# |`1 << 35`|`:use_public_threads`|
|
45
|
-
# |`1 << 36`|`:use_private_threads`|
|
46
|
-
#
|
47
|
-
class Permission < Flag
|
48
|
-
@bits = {
|
49
|
-
create_instant_invite: 0,
|
50
|
-
kick_members: 1,
|
51
|
-
ban_members: 2,
|
52
|
-
administrator: 3,
|
53
|
-
manage_channels: 4,
|
54
|
-
manage_guild: 5,
|
55
|
-
add_reactions: 6,
|
56
|
-
view_audit_log: 7,
|
57
|
-
priority_speaker: 8,
|
58
|
-
stream: 9,
|
59
|
-
view_channel: 10,
|
60
|
-
send_messages: 11,
|
61
|
-
send_tts_messages: 12,
|
62
|
-
manage_messages: 13,
|
63
|
-
embed_links: 14,
|
64
|
-
attach_files: 15,
|
65
|
-
read_message_history: 16,
|
66
|
-
mention_everyone: 17,
|
67
|
-
use_external_emojis: 18,
|
68
|
-
view_guild_insights: 19,
|
69
|
-
connect: 20,
|
70
|
-
speak: 21,
|
71
|
-
mute_members: 22,
|
72
|
-
deafen_members: 23,
|
73
|
-
move_members: 24,
|
74
|
-
use_vad: 25,
|
75
|
-
change_nickname: 26,
|
76
|
-
manage_nicknames: 27,
|
77
|
-
manage_roles: 28,
|
78
|
-
manage_webhooks: 29,
|
79
|
-
manage_emojis: 30,
|
80
|
-
use_slash_commands: 31,
|
81
|
-
request_to_speak: 32,
|
82
|
-
manage_threads: 34,
|
83
|
-
use_public_threads: 35,
|
84
|
-
use_private_threads: 36,
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
# @!attribute [r]
|
97
|
-
# @return [
|
98
|
-
# @!attribute [r]
|
99
|
-
# @return [
|
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
|
-
end
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
end
|
162
|
-
|
163
|
-
alias
|
164
|
-
|
165
|
-
def
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
def
|
174
|
-
|
175
|
-
end
|
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
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
self[
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Discorb
|
4
|
+
#
|
5
|
+
# Represents a permission per guild.
|
6
|
+
# ## Flag fields
|
7
|
+
#
|
8
|
+
# | Field | Value |
|
9
|
+
# |-------|-------|
|
10
|
+
# |`1 << 0`|`:create_instant_invite`|
|
11
|
+
# |`1 << 1`|`:kick_members`|
|
12
|
+
# |`1 << 2`|`:ban_members`|
|
13
|
+
# |`1 << 3`|`:administrator`|
|
14
|
+
# |`1 << 4`|`:manage_channels`|
|
15
|
+
# |`1 << 5`|`:manage_guild`|
|
16
|
+
# |`1 << 6`|`:add_reactions`|
|
17
|
+
# |`1 << 7`|`:view_audit_log`|
|
18
|
+
# |`1 << 8`|`:priority_speaker`|
|
19
|
+
# |`1 << 9`|`:stream`|
|
20
|
+
# |`1 << 10`|`:view_channel`|
|
21
|
+
# |`1 << 11`|`:send_messages`|
|
22
|
+
# |`1 << 12`|`:send_tts_messages`|
|
23
|
+
# |`1 << 13`|`:manage_messages`|
|
24
|
+
# |`1 << 14`|`:embed_links`|
|
25
|
+
# |`1 << 15`|`:attach_files`|
|
26
|
+
# |`1 << 16`|`:read_message_history`|
|
27
|
+
# |`1 << 17`|`:mention_everyone`|
|
28
|
+
# |`1 << 18`|`:use_external_emojis`|
|
29
|
+
# |`1 << 19`|`:view_guild_insights`|
|
30
|
+
# |`1 << 20`|`:connect`|
|
31
|
+
# |`1 << 21`|`:speak`|
|
32
|
+
# |`1 << 22`|`:mute_members`|
|
33
|
+
# |`1 << 23`|`:deafen_members`|
|
34
|
+
# |`1 << 24`|`:move_members`|
|
35
|
+
# |`1 << 25`|`:use_vad`|
|
36
|
+
# |`1 << 26`|`:change_nickname`|
|
37
|
+
# |`1 << 27`|`:manage_nicknames`|
|
38
|
+
# |`1 << 28`|`:manage_roles`|
|
39
|
+
# |`1 << 29`|`:manage_webhooks`|
|
40
|
+
# |`1 << 30`|`:manage_emojis`|
|
41
|
+
# |`1 << 31`|`:use_slash_commands`|
|
42
|
+
# |`1 << 32`|`:request_to_speak`|
|
43
|
+
# |`1 << 34`|`:manage_threads`|
|
44
|
+
# |`1 << 35`|`:use_public_threads`|
|
45
|
+
# |`1 << 36`|`:use_private_threads`|
|
46
|
+
#
|
47
|
+
class Permission < Flag
|
48
|
+
@bits = {
|
49
|
+
create_instant_invite: 0,
|
50
|
+
kick_members: 1,
|
51
|
+
ban_members: 2,
|
52
|
+
administrator: 3,
|
53
|
+
manage_channels: 4,
|
54
|
+
manage_guild: 5,
|
55
|
+
add_reactions: 6,
|
56
|
+
view_audit_log: 7,
|
57
|
+
priority_speaker: 8,
|
58
|
+
stream: 9,
|
59
|
+
view_channel: 10,
|
60
|
+
send_messages: 11,
|
61
|
+
send_tts_messages: 12,
|
62
|
+
manage_messages: 13,
|
63
|
+
embed_links: 14,
|
64
|
+
attach_files: 15,
|
65
|
+
read_message_history: 16,
|
66
|
+
mention_everyone: 17,
|
67
|
+
use_external_emojis: 18,
|
68
|
+
view_guild_insights: 19,
|
69
|
+
connect: 20,
|
70
|
+
speak: 21,
|
71
|
+
mute_members: 22,
|
72
|
+
deafen_members: 23,
|
73
|
+
move_members: 24,
|
74
|
+
use_vad: 25,
|
75
|
+
change_nickname: 26,
|
76
|
+
manage_nicknames: 27,
|
77
|
+
manage_roles: 28,
|
78
|
+
manage_webhooks: 29,
|
79
|
+
manage_emojis: 30,
|
80
|
+
use_slash_commands: 31,
|
81
|
+
request_to_speak: 32,
|
82
|
+
manage_threads: 34,
|
83
|
+
use_public_threads: 35,
|
84
|
+
use_private_threads: 36,
|
85
|
+
use_external_stickers: 37,
|
86
|
+
send_messages_in_threads: 38,
|
87
|
+
use_embedded_activities: 39,
|
88
|
+
moderate_members: 40
|
89
|
+
}.freeze
|
90
|
+
end
|
91
|
+
|
92
|
+
#
|
93
|
+
# Represents a permission per channel.
|
94
|
+
#
|
95
|
+
class PermissionOverwrite
|
96
|
+
# @!attribute [r] allow
|
97
|
+
# @return [Discorb::Permission] The allowed permissions.
|
98
|
+
# @!attribute [r] deny
|
99
|
+
# @return [Discorb::Permission] The denied permissions.
|
100
|
+
# @!attribute [r] allow_value
|
101
|
+
# @return [Integer] The allowed permissions as an integer.
|
102
|
+
# @!attribute [r] deny_value
|
103
|
+
# @return [Integer] The denied permissions as an integer.
|
104
|
+
|
105
|
+
@raw_bits = {
|
106
|
+
create_instant_invite: 0,
|
107
|
+
kick_members: 1,
|
108
|
+
ban_members: 2,
|
109
|
+
administrator: 3,
|
110
|
+
manage_channels: 4,
|
111
|
+
manage_guild: 5,
|
112
|
+
add_reactions: 6,
|
113
|
+
view_audit_log: 7,
|
114
|
+
priority_speaker: 8,
|
115
|
+
stream: 9,
|
116
|
+
view_channel: 10,
|
117
|
+
send_messages: 11,
|
118
|
+
send_tts_messages: 12,
|
119
|
+
manage_messages: 13,
|
120
|
+
embed_links: 14,
|
121
|
+
attach_files: 15,
|
122
|
+
read_message_history: 16,
|
123
|
+
mention_everyone: 17,
|
124
|
+
use_external_emojis: 18,
|
125
|
+
view_guild_insights: 19,
|
126
|
+
connect: 20,
|
127
|
+
speak: 21,
|
128
|
+
mute_members: 22,
|
129
|
+
deafen_members: 23,
|
130
|
+
move_members: 24,
|
131
|
+
use_vad: 25,
|
132
|
+
change_nickname: 26,
|
133
|
+
manage_nicknames: 27,
|
134
|
+
manage_roles: 28,
|
135
|
+
manage_webhooks: 29,
|
136
|
+
manage_emojis: 30,
|
137
|
+
use_slash_commands: 31,
|
138
|
+
request_to_speak: 32,
|
139
|
+
manage_threads: 34,
|
140
|
+
use_public_threads: 35,
|
141
|
+
use_private_threads: 36
|
142
|
+
}.freeze
|
143
|
+
@bits = @raw_bits.transform_values { |v| 1 << v }.freeze
|
144
|
+
|
145
|
+
#
|
146
|
+
# Initializes a new PermissionOverwrite.
|
147
|
+
# @private
|
148
|
+
#
|
149
|
+
# @param allow [Integer] The allowed permissions.
|
150
|
+
# @param deny [Integer] The denied permissions.
|
151
|
+
#
|
152
|
+
def initialize(allow, deny)
|
153
|
+
@allow = allow
|
154
|
+
@deny = deny
|
155
|
+
end
|
156
|
+
|
157
|
+
def allow
|
158
|
+
self.class.bits.keys.filter do |field|
|
159
|
+
@allow & self.class.bits[field] != 0
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
alias +@ allow
|
164
|
+
|
165
|
+
def deny
|
166
|
+
self.class.bits.keys.filter do |field|
|
167
|
+
@deny & self.class.bits[field] != 0
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
alias -@ deny
|
172
|
+
|
173
|
+
def allow_value
|
174
|
+
@allow
|
175
|
+
end
|
176
|
+
|
177
|
+
def deny_value
|
178
|
+
@deny
|
179
|
+
end
|
180
|
+
|
181
|
+
def inspect
|
182
|
+
"#<#{self.class} allow=#{allow} deny=#{deny}>"
|
183
|
+
end
|
184
|
+
|
185
|
+
#
|
186
|
+
# Converts the permission overwrite to a hash.
|
187
|
+
#
|
188
|
+
# @return [Hash] The permission overwrite as a hash.
|
189
|
+
#
|
190
|
+
def to_hash
|
191
|
+
self.class.bits.keys.to_h do |field|
|
192
|
+
[
|
193
|
+
field,
|
194
|
+
if @allow & self.class.bits[field] != 0
|
195
|
+
true
|
196
|
+
elsif @deny & self.class.bits[field] != 0
|
197
|
+
false
|
198
|
+
end
|
199
|
+
]
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
#
|
204
|
+
# Union of the permission overwrites.
|
205
|
+
#
|
206
|
+
# @param [Discorb::PermissionOverwrite] other The other permission overwrite.
|
207
|
+
#
|
208
|
+
# @return [Discorb::PermissionOverwrite] The union of the permission overwrites.
|
209
|
+
#
|
210
|
+
def +(other)
|
211
|
+
result = to_hash
|
212
|
+
self.class.bits.each_key do |field|
|
213
|
+
next if other[field].nil?
|
214
|
+
result[field] = (
|
215
|
+
other[field] ||
|
216
|
+
raise(KeyError, "field #{field} not found in #{other.inspect}")
|
217
|
+
)
|
218
|
+
end
|
219
|
+
self.class.from_hash(result)
|
220
|
+
end
|
221
|
+
|
222
|
+
#
|
223
|
+
# Returns whether overwrite of the given field.
|
224
|
+
#
|
225
|
+
# @param [Symbol] field The field to check.
|
226
|
+
#
|
227
|
+
# @return [true, false, nil] Whether the field is allowed, denied or not set.
|
228
|
+
#
|
229
|
+
def [](field)
|
230
|
+
if @allow & self.class.bits[field] != 0
|
231
|
+
true
|
232
|
+
elsif @deny & self.class.bits[field] != 0
|
233
|
+
false
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
#
|
238
|
+
# Sets the given field to the given value.
|
239
|
+
#
|
240
|
+
# @param [Symbol] key The field to set.
|
241
|
+
# @param [Boolean] bool The value to set.
|
242
|
+
#
|
243
|
+
def []=(key, bool)
|
244
|
+
case bool
|
245
|
+
when true
|
246
|
+
@allow |= self.class.bits[key]
|
247
|
+
@deny &= ~self.class.bits[key]
|
248
|
+
when false
|
249
|
+
@allow &= ~self.class.bits[key]
|
250
|
+
@deny |= self.class.bits[key]
|
251
|
+
else
|
252
|
+
@allow &= ~self.class.bits[key]
|
253
|
+
@deny &= ~self.class.bits[key]
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
#
|
258
|
+
# (see Flag#method_missing)
|
259
|
+
#
|
260
|
+
def method_missing(method, bool = nil)
|
261
|
+
if self.class.bits.key?(method)
|
262
|
+
self[method]
|
263
|
+
elsif self.class.bits.key?(method.to_s.delete_suffix("=").to_sym)
|
264
|
+
key = method.to_s.delete_suffix("=").to_sym
|
265
|
+
self[key] = bool
|
266
|
+
else
|
267
|
+
super
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
def respond_to_missing?(method, _arg)
|
272
|
+
self.class.bits.key?(method.to_s.delete_suffix("=").to_sym) ? true : super
|
273
|
+
end
|
274
|
+
|
275
|
+
class << self
|
276
|
+
# @private
|
277
|
+
attr_reader :bits
|
278
|
+
|
279
|
+
#
|
280
|
+
# Initializes a permission overwrite from a hash.
|
281
|
+
#
|
282
|
+
# @param [Hash] hash The hash to initialize the permission overwrite from.
|
283
|
+
#
|
284
|
+
# @return [Discorb::PermissionOverwrite] The permission overwrite.
|
285
|
+
#
|
286
|
+
def from_hash(hash)
|
287
|
+
allow = 0
|
288
|
+
deny = 0
|
289
|
+
hash
|
290
|
+
.filter do |k, v|
|
291
|
+
self.class.bits.keys.include?(k) && [true, false].include?(v)
|
292
|
+
end
|
293
|
+
.each do |k, v|
|
294
|
+
if v
|
295
|
+
allow += self.class.bits[k]
|
296
|
+
else
|
297
|
+
deny += self.class.bits[k]
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
new(allow, deny)
|
302
|
+
end
|
303
|
+
end
|
304
|
+
end
|
305
|
+
end
|