discorb 0.18.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 +25 -0
- data/Gemfile +4 -4
- data/README.md +2 -1
- data/Rakefile +482 -459
- data/Steepfile +8 -6
- data/docs/application_command.md +1 -0
- data/docs/events.md +2 -2
- data/docs/voice_events.md +6 -6
- data/lib/discorb/allowed_mentions.rb +68 -72
- data/lib/discorb/app_command/command.rb +466 -394
- data/lib/discorb/app_command/common.rb +65 -25
- data/lib/discorb/app_command/handler.rb +304 -265
- 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 -623
- 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 -794
- 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 -330
- data/lib/discorb/interaction/root.rb +271 -118
- 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 -289
- 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/activity.rbs +1 -0
- data/sig/discorb/allowed_mentions.rbs +1 -0
- data/sig/discorb/app_command/base.rbs +7 -1
- data/sig/discorb/application.rbs +6 -0
- data/sig/discorb/asset.rbs +2 -0
- data/sig/discorb/attachment.rbs +8 -0
- data/sig/discorb/audit_log.rbs +7 -0
- data/sig/discorb/automod.rbs +32 -6
- data/sig/discorb/avatar.rbs +1 -0
- data/sig/discorb/channel/base.rbs +8 -1
- data/sig/discorb/channel/category.rbs +1 -0
- data/sig/discorb/channel/container.rbs +4 -0
- data/sig/discorb/channel/stage.rbs +4 -0
- data/sig/discorb/channel/text.rbs +2 -2
- data/sig/discorb/channel/thread.rbs +11 -0
- data/sig/discorb/channel/voice.rbs +2 -0
- data/sig/discorb/client.rbs +21 -20
- data/sig/discorb/color.rbs +6 -0
- data/sig/discorb/component/base.rbs +1 -0
- data/sig/discorb/component/button.rbs +2 -0
- data/sig/discorb/component/select_menu.rbs +4 -0
- data/sig/discorb/component/text_input.rbs +1 -0
- data/sig/discorb/custom_emoji.rbs +5 -1
- data/sig/discorb/dictionary.rbs +2 -0
- data/sig/discorb/discord_model.rbs +2 -0
- data/sig/discorb/embed.rbs +7 -0
- data/sig/discorb/emoji.rbs +1 -0
- data/sig/discorb/event_handler.rbs +2 -1
- data/sig/discorb/extension.rbs +13 -12
- data/sig/discorb/flag.rbs +2 -0
- data/sig/discorb/gateway.rbs +5 -0
- data/sig/discorb/guild.rbs +8 -4
- data/sig/discorb/guild_template.rbs +1 -1
- data/sig/discorb/http.rbs +4 -1
- data/sig/discorb/image.rbs +2 -0
- data/sig/discorb/integration.rbs +1 -1
- data/sig/discorb/intents.rbs +4 -3
- data/sig/discorb/interaction/base.rbs +36 -0
- data/sig/discorb/interaction/message_component.rbs +1 -2
- data/sig/discorb/interaction/modal.rbs +1 -2
- data/sig/discorb/interaction/responder.rbs +49 -49
- data/sig/discorb/invite.rbs +1 -1
- data/sig/discorb/member.rbs +2 -0
- data/sig/discorb/message.rbs +8 -1
- data/sig/discorb/messageable.rbs +1 -4
- data/sig/discorb/partial_emoji.rbs +3 -0
- data/sig/discorb/permissions.rbs +7 -0
- data/sig/discorb/presence.rbs +2 -0
- data/sig/discorb/reaction.rbs +5 -1
- data/sig/discorb/role.rbs +7 -1
- data/sig/discorb/scheduled_event.rbs +2 -1
- data/sig/discorb/shard.rbs +2 -1
- data/sig/discorb/snowflake.rbs +2 -0
- data/sig/discorb/stage_instance.rbs +9 -3
- data/sig/discorb/sticker.rbs +1 -1
- data/sig/discorb/unicode_emoji.rbs +4 -0
- data/sig/discorb/user.rbs +24 -20
- data/sig/discorb/webhook.rbs +17 -6
- data/sig/discorb/welcome_screen.rbs +1 -0
- data/sig/override.rbs +2 -0
- metadata +3 -3
data/lib/discorb/dictionary.rb
CHANGED
@@ -1,135 +1,135 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Discorb
|
4
|
-
#
|
5
|
-
# Extended hash class. This is used for storing pair of ID and object.
|
6
|
-
#
|
7
|
-
class Dictionary
|
8
|
-
# @return [Integer] The maximum number of items in the dictionary.
|
9
|
-
attr_accessor :limit
|
10
|
-
|
11
|
-
#
|
12
|
-
# Initialize a new Dictionary.
|
13
|
-
#
|
14
|
-
# @param [Hash] hash A hash of items to add to the dictionary.
|
15
|
-
# @param [Integer] limit The maximum number of items in the dictionary.
|
16
|
-
# @param [false, Proc] sort Whether to sort the items in the dictionary.
|
17
|
-
#
|
18
|
-
def initialize(hash = {}, limit: nil, sort: false)
|
19
|
-
@cache = hash.transform_keys(&:to_s)
|
20
|
-
@limit = limit
|
21
|
-
@sort = sort
|
22
|
-
@cache = @cache.sort_by(&@sort).to_h if @sort
|
23
|
-
end
|
24
|
-
|
25
|
-
#
|
26
|
-
# Registers a new item in the dictionary.
|
27
|
-
#
|
28
|
-
# @param [#to_s] id The ID of the item.
|
29
|
-
# @param [Object] body The item to register.
|
30
|
-
#
|
31
|
-
# @return [self] The dictionary.
|
32
|
-
#
|
33
|
-
def register(id, body)
|
34
|
-
@cache[id.to_s] = body
|
35
|
-
@cache = @cache.sort_by(&@sort).to_h if @sort
|
36
|
-
@cache.delete(@cache.keys[0]) if !@limit.nil? && @cache.size > @limit
|
37
|
-
self
|
38
|
-
end
|
39
|
-
|
40
|
-
#
|
41
|
-
# Merges another dictionary into this one.
|
42
|
-
#
|
43
|
-
# @param [Discorb::Dictionary] other The dictionary to merge.
|
44
|
-
#
|
45
|
-
def merge(other)
|
46
|
-
@cache.merge!(other.to_h)
|
47
|
-
end
|
48
|
-
|
49
|
-
#
|
50
|
-
# Removes an item from the dictionary.
|
51
|
-
#
|
52
|
-
# @param [#to_s] id The ID of the item to remove.
|
53
|
-
#
|
54
|
-
def remove(id)
|
55
|
-
@cache.delete(id.to_s)
|
56
|
-
end
|
57
|
-
|
58
|
-
alias delete remove
|
59
|
-
|
60
|
-
#
|
61
|
-
# Get an item from the dictionary.
|
62
|
-
#
|
63
|
-
# @param [#to_s] id The ID of the item.
|
64
|
-
# @return [Object] The item.
|
65
|
-
# @return [nil] if the item was not found.
|
66
|
-
#
|
67
|
-
# @overload get(index)
|
68
|
-
# @param [Integer] index The index of the item.
|
69
|
-
#
|
70
|
-
# @return [Object] The item.
|
71
|
-
# @return [nil] if the item is not found.
|
72
|
-
#
|
73
|
-
def get(id)
|
74
|
-
res = @cache[id.to_s]
|
75
|
-
if res.nil? && id.is_a?(Integer) && id < @cache.length
|
76
|
-
@cache.values[id]
|
77
|
-
else
|
78
|
-
res
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
#
|
83
|
-
# Convert the dictionary to a hash.
|
84
|
-
#
|
85
|
-
def to_h
|
86
|
-
@cache
|
87
|
-
end
|
88
|
-
|
89
|
-
#
|
90
|
-
# Returns the values of the dictionary.
|
91
|
-
#
|
92
|
-
# @return [Array] The values of the dictionary.
|
93
|
-
#
|
94
|
-
def values
|
95
|
-
@cache.values
|
96
|
-
end
|
97
|
-
|
98
|
-
#
|
99
|
-
# Checks if the dictionary has an ID.
|
100
|
-
#
|
101
|
-
# @param [#to_s] id The ID to check.
|
102
|
-
#
|
103
|
-
# @return [Boolean] `true` if the dictionary has the ID, `false` otherwise.
|
104
|
-
#
|
105
|
-
def has?(id)
|
106
|
-
!self[id].nil?
|
107
|
-
end
|
108
|
-
|
109
|
-
#
|
110
|
-
# Send a message to the array of values.
|
111
|
-
#
|
112
|
-
def method_missing(name, ...)
|
113
|
-
if values.respond_to?(name)
|
114
|
-
values.send(name, ...)
|
115
|
-
else
|
116
|
-
super
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
def respond_to_missing?(name, ...)
|
121
|
-
if values.respond_to?(name)
|
122
|
-
true
|
123
|
-
else
|
124
|
-
super
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
alias [] get
|
129
|
-
alias []= register
|
130
|
-
|
131
|
-
def inspect
|
132
|
-
"#<#{self.class} #{values.length} items>"
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Discorb
|
4
|
+
#
|
5
|
+
# Extended hash class. This is used for storing pair of ID and object.
|
6
|
+
#
|
7
|
+
class Dictionary
|
8
|
+
# @return [Integer] The maximum number of items in the dictionary.
|
9
|
+
attr_accessor :limit
|
10
|
+
|
11
|
+
#
|
12
|
+
# Initialize a new Dictionary.
|
13
|
+
#
|
14
|
+
# @param [Hash] hash A hash of items to add to the dictionary.
|
15
|
+
# @param [Integer] limit The maximum number of items in the dictionary.
|
16
|
+
# @param [false, Proc] sort Whether to sort the items in the dictionary.
|
17
|
+
#
|
18
|
+
def initialize(hash = {}, limit: nil, sort: false)
|
19
|
+
@cache = hash.transform_keys(&:to_s)
|
20
|
+
@limit = limit
|
21
|
+
@sort = sort
|
22
|
+
@cache = @cache.sort_by(&@sort).to_h if @sort
|
23
|
+
end
|
24
|
+
|
25
|
+
#
|
26
|
+
# Registers a new item in the dictionary.
|
27
|
+
#
|
28
|
+
# @param [#to_s] id The ID of the item.
|
29
|
+
# @param [Object] body The item to register.
|
30
|
+
#
|
31
|
+
# @return [self] The dictionary.
|
32
|
+
#
|
33
|
+
def register(id, body)
|
34
|
+
@cache[id.to_s] = body
|
35
|
+
@cache = @cache.sort_by(&@sort).to_h if @sort
|
36
|
+
@cache.delete(@cache.keys[0]) if !@limit.nil? && @cache.size > @limit
|
37
|
+
self
|
38
|
+
end
|
39
|
+
|
40
|
+
#
|
41
|
+
# Merges another dictionary into this one.
|
42
|
+
#
|
43
|
+
# @param [Discorb::Dictionary] other The dictionary to merge.
|
44
|
+
#
|
45
|
+
def merge(other)
|
46
|
+
@cache.merge!(other.to_h)
|
47
|
+
end
|
48
|
+
|
49
|
+
#
|
50
|
+
# Removes an item from the dictionary.
|
51
|
+
#
|
52
|
+
# @param [#to_s] id The ID of the item to remove.
|
53
|
+
#
|
54
|
+
def remove(id)
|
55
|
+
@cache.delete(id.to_s)
|
56
|
+
end
|
57
|
+
|
58
|
+
alias delete remove
|
59
|
+
|
60
|
+
#
|
61
|
+
# Get an item from the dictionary.
|
62
|
+
#
|
63
|
+
# @param [#to_s] id The ID of the item.
|
64
|
+
# @return [Object] The item.
|
65
|
+
# @return [nil] if the item was not found.
|
66
|
+
#
|
67
|
+
# @overload get(index)
|
68
|
+
# @param [Integer] index The index of the item.
|
69
|
+
#
|
70
|
+
# @return [Object] The item.
|
71
|
+
# @return [nil] if the item is not found.
|
72
|
+
#
|
73
|
+
def get(id)
|
74
|
+
res = @cache[id.to_s]
|
75
|
+
if res.nil? && id.is_a?(Integer) && id < @cache.length
|
76
|
+
@cache.values[id]
|
77
|
+
else
|
78
|
+
res
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
#
|
83
|
+
# Convert the dictionary to a hash.
|
84
|
+
#
|
85
|
+
def to_h
|
86
|
+
@cache
|
87
|
+
end
|
88
|
+
|
89
|
+
#
|
90
|
+
# Returns the values of the dictionary.
|
91
|
+
#
|
92
|
+
# @return [Array] The values of the dictionary.
|
93
|
+
#
|
94
|
+
def values
|
95
|
+
@cache.values
|
96
|
+
end
|
97
|
+
|
98
|
+
#
|
99
|
+
# Checks if the dictionary has an ID.
|
100
|
+
#
|
101
|
+
# @param [#to_s] id The ID to check.
|
102
|
+
#
|
103
|
+
# @return [Boolean] `true` if the dictionary has the ID, `false` otherwise.
|
104
|
+
#
|
105
|
+
def has?(id)
|
106
|
+
!self[id].nil?
|
107
|
+
end
|
108
|
+
|
109
|
+
#
|
110
|
+
# Send a message to the array of values.
|
111
|
+
#
|
112
|
+
def method_missing(name, ...)
|
113
|
+
if values.respond_to?(name)
|
114
|
+
values.send(name, ...)
|
115
|
+
else
|
116
|
+
super
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def respond_to_missing?(name, ...)
|
121
|
+
if values.respond_to?(name)
|
122
|
+
true
|
123
|
+
else
|
124
|
+
super
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
alias [] get
|
129
|
+
alias []= register
|
130
|
+
|
131
|
+
def inspect
|
132
|
+
"#<#{self.class} #{values.length} items>"
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|