discorb 0.19.0 → 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/build_version.yml +2 -2
  3. data/.rubocop.yml +12 -75
  4. data/Changelog.md +10 -0
  5. data/Rakefile +482 -454
  6. data/lib/discorb/allowed_mentions.rb +68 -72
  7. data/lib/discorb/app_command/command.rb +466 -398
  8. data/lib/discorb/app_command/common.rb +65 -25
  9. data/lib/discorb/app_command/handler.rb +304 -266
  10. data/lib/discorb/app_command.rb +5 -5
  11. data/lib/discorb/application.rb +198 -197
  12. data/lib/discorb/asset.rb +101 -101
  13. data/lib/discorb/attachment.rb +134 -119
  14. data/lib/discorb/audit_logs.rb +412 -385
  15. data/lib/discorb/automod.rb +279 -269
  16. data/lib/discorb/channel/base.rb +107 -108
  17. data/lib/discorb/channel/category.rb +32 -32
  18. data/lib/discorb/channel/container.rb +44 -44
  19. data/lib/discorb/channel/dm.rb +26 -28
  20. data/lib/discorb/channel/guild.rb +311 -246
  21. data/lib/discorb/channel/stage.rb +156 -140
  22. data/lib/discorb/channel/text.rb +430 -336
  23. data/lib/discorb/channel/thread.rb +374 -325
  24. data/lib/discorb/channel/voice.rb +85 -79
  25. data/lib/discorb/channel.rb +5 -5
  26. data/lib/discorb/client.rb +635 -621
  27. data/lib/discorb/color.rb +178 -182
  28. data/lib/discorb/common.rb +168 -164
  29. data/lib/discorb/components/button.rb +107 -106
  30. data/lib/discorb/components/select_menu.rb +157 -145
  31. data/lib/discorb/components/text_input.rb +103 -106
  32. data/lib/discorb/components.rb +68 -66
  33. data/lib/discorb/dictionary.rb +135 -135
  34. data/lib/discorb/embed.rb +404 -398
  35. data/lib/discorb/emoji.rb +309 -302
  36. data/lib/discorb/emoji_table.rb +16099 -8857
  37. data/lib/discorb/error.rb +131 -131
  38. data/lib/discorb/event.rb +360 -314
  39. data/lib/discorb/event_handler.rb +39 -39
  40. data/lib/discorb/exe/about.rb +17 -17
  41. data/lib/discorb/exe/irb.rb +72 -67
  42. data/lib/discorb/exe/new.rb +323 -315
  43. data/lib/discorb/exe/run.rb +69 -68
  44. data/lib/discorb/exe/setup.rb +57 -55
  45. data/lib/discorb/exe/show.rb +12 -12
  46. data/lib/discorb/extend.rb +25 -45
  47. data/lib/discorb/extension.rb +89 -83
  48. data/lib/discorb/flag.rb +126 -128
  49. data/lib/discorb/gateway.rb +984 -804
  50. data/lib/discorb/gateway_events.rb +670 -638
  51. data/lib/discorb/gateway_requests.rb +45 -48
  52. data/lib/discorb/guild.rb +2115 -1626
  53. data/lib/discorb/guild_template.rb +280 -241
  54. data/lib/discorb/http.rb +247 -232
  55. data/lib/discorb/image.rb +42 -42
  56. data/lib/discorb/integration.rb +169 -161
  57. data/lib/discorb/intents.rb +161 -163
  58. data/lib/discorb/interaction/autocomplete.rb +76 -62
  59. data/lib/discorb/interaction/command.rb +279 -224
  60. data/lib/discorb/interaction/components.rb +114 -104
  61. data/lib/discorb/interaction/modal.rb +36 -32
  62. data/lib/discorb/interaction/response.rb +379 -336
  63. data/lib/discorb/interaction/root.rb +271 -257
  64. data/lib/discorb/interaction.rb +5 -5
  65. data/lib/discorb/invite.rb +154 -153
  66. data/lib/discorb/member.rb +344 -311
  67. data/lib/discorb/message.rb +615 -544
  68. data/lib/discorb/message_meta.rb +197 -186
  69. data/lib/discorb/modules.rb +371 -290
  70. data/lib/discorb/permission.rb +305 -291
  71. data/lib/discorb/presence.rb +352 -346
  72. data/lib/discorb/rate_limit.rb +81 -76
  73. data/lib/discorb/reaction.rb +55 -54
  74. data/lib/discorb/role.rb +272 -240
  75. data/lib/discorb/shard.rb +76 -74
  76. data/lib/discorb/sticker.rb +193 -171
  77. data/lib/discorb/user.rb +205 -188
  78. data/lib/discorb/utils/colored_puts.rb +16 -16
  79. data/lib/discorb/utils.rb +12 -16
  80. data/lib/discorb/voice_state.rb +305 -281
  81. data/lib/discorb/webhook.rb +537 -507
  82. data/lib/discorb.rb +62 -56
  83. data/sig/discorb/application.rbs +2 -0
  84. data/sig/discorb/automod.rbs +10 -1
  85. data/sig/discorb/guild.rbs +2 -0
  86. data/sig/discorb/message.rbs +2 -0
  87. data/sig/discorb/user.rbs +22 -20
  88. metadata +2 -2
@@ -1,186 +1,197 @@
1
- # frozen_string_literal: true
2
-
3
- module Discorb
4
- #
5
- # Represents a message in Discord.
6
- #
7
- class Message < DiscordModel
8
- #
9
- # Represents message flag.
10
- # ## Flag fields
11
- # |Field|Value|
12
- # |-|-|
13
- # |`1 << 0`|`:crossposted`|
14
- # |`1 << 1`|`:crosspost`|
15
- # |`1 << 2`|`:supress_embeds`|
16
- # |`1 << 3`|`:source_message_deleted`|
17
- # |`1 << 4`|`:urgent`|
18
- # |`1 << 5`|`:has_thread`|
19
- # |`1 << 6`|`:ephemeral`|
20
- # |`1 << 7`|`:loading`|
21
- #
22
- class Flag < Discorb::Flag
23
- @bits = {
24
- crossposted: 0,
25
- crosspost: 1,
26
- supress_embeds: 2,
27
- source_message_deleted: 3,
28
- urgent: 4,
29
- has_thread: 5,
30
- ephemeral: 6,
31
- loading: 7,
32
- }.freeze
33
- end
34
-
35
- #
36
- # Represents reference of message.
37
- #
38
- class Reference
39
- # @return [Discorb::Snowflake] The guild ID.
40
- attr_accessor :guild_id
41
- # @return [Discorb::Snowflake] The channel ID.
42
- attr_accessor :channel_id
43
- # @return [Discorb::Snowflake] The message ID.
44
- attr_accessor :message_id
45
- # @return [Boolean] Whether fail the request if the message is not found.
46
- attr_accessor :fail_if_not_exists
47
-
48
- alias fail_if_not_exists? fail_if_not_exists
49
-
50
- #
51
- # Initialize a new reference.
52
- #
53
- # @param [Discorb::Snowflake] guild_id The guild ID.
54
- # @param [Discorb::Snowflake] channel_id The channel ID.
55
- # @param [Discorb::Snowflake] message_id The message ID.
56
- # @param [Boolean] fail_if_not_exists Whether fail the request if the message is not found.
57
- #
58
- def initialize(guild_id, channel_id, message_id, fail_if_not_exists: true)
59
- @guild_id = guild_id
60
- @channel_id = channel_id
61
- @message_id = message_id
62
- @fail_if_not_exists = fail_if_not_exists
63
- end
64
-
65
- #
66
- # Convert the reference to a hash.
67
- #
68
- # @return [Hash] The hash.
69
- #
70
- def to_hash
71
- {
72
- message_id: @message_id,
73
- channel_id: @channel_id,
74
- guild_id: @guild_id,
75
- fail_if_not_exists: @fail_if_not_exists,
76
- }
77
- end
78
-
79
- #
80
- # Initialize a new reference from a hash.
81
- #
82
- # @param [Hash] data The hash.
83
- #
84
- # @return [Discorb::Message::Reference] The reference.
85
- # @see https://discord.com/developers/docs/resources/channel#message-reference-object
86
- #
87
- def self.from_hash(data)
88
- new(data[:guild_id], data[:channel_id], data[:message_id], fail_if_not_exists: data[:fail_if_not_exists])
89
- end
90
-
91
- def inspect
92
- "#<#{self.class.name} #{@channel_id}/#{@message_id}>"
93
- end
94
- end
95
-
96
- #
97
- # Represents a sticker.
98
- #
99
- class Sticker
100
- # @return [Discorb::Snowflake] The sticker ID.
101
- attr_reader :id
102
- # @return [String] The sticker name.
103
- attr_reader :name
104
- # @return [Symbol] The sticker format.
105
- attr_reader :format
106
-
107
- def initialize(data)
108
- @id = Snowflake.new(data[:id])
109
- @name = data[:name]
110
- @format = Discorb::Sticker::STICKER_FORMAT[data[:format]]
111
- end
112
-
113
- def inspect
114
- "#<#{self.class.name} #{@id}: #{@name} format=#{@format}>"
115
- end
116
- end
117
-
118
- #
119
- # Represents a interaction of message.
120
- #
121
- class Interaction < DiscordModel
122
- # @return [Discorb::Snowflake] The interaction ID.
123
- attr_reader :id
124
- # @return [String] The name of command.
125
- # @return [nil] If the message is not a command.
126
- attr_reader :name
127
- # @return [Class] The type of interaction.
128
- attr_reader :type
129
- # @return [Discorb::User] The user.
130
- attr_reader :user
131
-
132
- #
133
- # Initialize a new interaction.
134
- # @private
135
- #
136
- # @param [Discorb::Client] client The client.
137
- # @param [Hash] data The interaction data.
138
- #
139
- def initialize(client, data)
140
- @id = Snowflake.new(data[:id])
141
- @name = data[:name]
142
- @type = (Discorb::Interaction.descendants.find { |c| c.interaction_type == data[:type] } or
143
- raise "Unknown interaction type: #{data[:type]}")
144
- @user = client.users[data[:user][:id]] || User.new(client, data[:user])
145
- end
146
-
147
- def inspect
148
- "<#{self.class.name} #{@id}: #{@name} type=#{@type} #{@user}>"
149
- end
150
- end
151
-
152
- #
153
- # Represents a activity of message.
154
- #
155
- class Activity < DiscordModel
156
- # @return [String] The name of activity.
157
- attr_reader :name
158
- # @return [Symbol] The type of activity.
159
- attr_reader :type
160
-
161
- # @private
162
- # @return [{Integer => Symbol}] The mapping of activity type.
163
- TYPES = {
164
- 1 => :join,
165
- 2 => :spectate,
166
- 3 => :listen,
167
- 5 => :join_request,
168
- }.freeze
169
-
170
- #
171
- # Initialize a new activity.
172
- # @private
173
- #
174
- # @param [Hash] data The activity data.
175
- #
176
- def initialize(data)
177
- @name = data[:name]
178
- @type = TYPES[data[:type]]
179
- end
180
-
181
- def inspect
182
- "<#{self.class.name} #{@name} type=#{@type}>"
183
- end
184
- end
185
- end
186
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Discorb
4
+ #
5
+ # Represents a message in Discord.
6
+ #
7
+ class Message < DiscordModel
8
+ #
9
+ # Represents message flag.
10
+ # ## Flag fields
11
+ # |Field|Value|
12
+ # |-|-|
13
+ # |`1 << 0`|`:crossposted`|
14
+ # |`1 << 1`|`:crosspost`|
15
+ # |`1 << 2`|`:supress_embeds`|
16
+ # |`1 << 3`|`:source_message_deleted`|
17
+ # |`1 << 4`|`:urgent`|
18
+ # |`1 << 5`|`:has_thread`|
19
+ # |`1 << 6`|`:ephemeral`|
20
+ # |`1 << 7`|`:loading`|
21
+ # |`1 << 8`|`:failed_to_mention_some_roles_in_thread`|
22
+ #
23
+ class Flag < Discorb::Flag
24
+ @bits = {
25
+ crossposted: 0,
26
+ crosspost: 1,
27
+ supress_embeds: 2,
28
+ source_message_deleted: 3,
29
+ urgent: 4,
30
+ has_thread: 5,
31
+ ephemeral: 6,
32
+ loading: 7,
33
+ failed_to_mention_some_roles_in_thread: 8
34
+ }.freeze
35
+ end
36
+
37
+ #
38
+ # Represents reference of message.
39
+ #
40
+ class Reference
41
+ # @return [Discorb::Snowflake] The guild ID.
42
+ attr_accessor :guild_id
43
+ # @return [Discorb::Snowflake] The channel ID.
44
+ attr_accessor :channel_id
45
+ # @return [Discorb::Snowflake] The message ID.
46
+ attr_accessor :message_id
47
+ # @return [Boolean] Whether fail the request if the message is not found.
48
+ attr_accessor :fail_if_not_exists
49
+
50
+ alias fail_if_not_exists? fail_if_not_exists
51
+
52
+ #
53
+ # Initialize a new reference.
54
+ #
55
+ # @param [Discorb::Snowflake] guild_id The guild ID.
56
+ # @param [Discorb::Snowflake] channel_id The channel ID.
57
+ # @param [Discorb::Snowflake] message_id The message ID.
58
+ # @param [Boolean] fail_if_not_exists Whether fail the request if the message is not found.
59
+ #
60
+ def initialize(guild_id, channel_id, message_id, fail_if_not_exists: true)
61
+ @guild_id = guild_id
62
+ @channel_id = channel_id
63
+ @message_id = message_id
64
+ @fail_if_not_exists = fail_if_not_exists
65
+ end
66
+
67
+ #
68
+ # Convert the reference to a hash.
69
+ #
70
+ # @return [Hash] The hash.
71
+ #
72
+ def to_hash
73
+ {
74
+ message_id: @message_id,
75
+ channel_id: @channel_id,
76
+ guild_id: @guild_id,
77
+ fail_if_not_exists: @fail_if_not_exists
78
+ }
79
+ end
80
+
81
+ #
82
+ # Initialize a new reference from a hash.
83
+ #
84
+ # @param [Hash] data The hash.
85
+ #
86
+ # @return [Discorb::Message::Reference] The reference.
87
+ # @see https://discord.com/developers/docs/resources/channel#message-reference-object
88
+ #
89
+ def self.from_hash(data)
90
+ new(
91
+ data[:guild_id],
92
+ data[:channel_id],
93
+ data[:message_id],
94
+ fail_if_not_exists: data[:fail_if_not_exists]
95
+ )
96
+ end
97
+
98
+ def inspect
99
+ "#<#{self.class.name} #{@channel_id}/#{@message_id}>"
100
+ end
101
+ end
102
+
103
+ #
104
+ # Represents a sticker.
105
+ #
106
+ class Sticker
107
+ # @return [Discorb::Snowflake] The sticker ID.
108
+ attr_reader :id
109
+ # @return [String] The sticker name.
110
+ attr_reader :name
111
+ # @return [Symbol] The sticker format.
112
+ attr_reader :format
113
+
114
+ def initialize(data)
115
+ @id = Snowflake.new(data[:id])
116
+ @name = data[:name]
117
+ @format = Discorb::Sticker::STICKER_FORMAT[data[:format]]
118
+ end
119
+
120
+ def inspect
121
+ "#<#{self.class.name} #{@id}: #{@name} format=#{@format}>"
122
+ end
123
+ end
124
+
125
+ #
126
+ # Represents a interaction of message.
127
+ #
128
+ class Interaction < DiscordModel
129
+ # @return [Discorb::Snowflake] The interaction ID.
130
+ attr_reader :id
131
+ # @return [String] The name of command.
132
+ # @return [nil] If the message is not a command.
133
+ attr_reader :name
134
+ # @return [Class] The type of interaction.
135
+ attr_reader :type
136
+ # @return [Discorb::User] The user.
137
+ attr_reader :user
138
+
139
+ #
140
+ # Initialize a new interaction.
141
+ # @private
142
+ #
143
+ # @param [Discorb::Client] client The client.
144
+ # @param [Hash] data The interaction data.
145
+ #
146
+ def initialize(client, data)
147
+ @id = Snowflake.new(data[:id])
148
+ @name = data[:name]
149
+ @type =
150
+ (
151
+ Discorb::Interaction.descendants.find do |c|
152
+ c.interaction_type == data[:type]
153
+ end or raise "Unknown interaction type: #{data[:type]}"
154
+ )
155
+ @user = client.users[data[:user][:id]] || User.new(client, data[:user])
156
+ end
157
+
158
+ def inspect
159
+ "<#{self.class.name} #{@id}: #{@name} type=#{@type} #{@user}>"
160
+ end
161
+ end
162
+
163
+ #
164
+ # Represents a activity of message.
165
+ #
166
+ class Activity < DiscordModel
167
+ # @return [String] The name of activity.
168
+ attr_reader :name
169
+ # @return [Symbol] The type of activity.
170
+ attr_reader :type
171
+
172
+ # @private
173
+ # @return [{Integer => Symbol}] The mapping of activity type.
174
+ TYPES = {
175
+ 1 => :join,
176
+ 2 => :spectate,
177
+ 3 => :listen,
178
+ 5 => :join_request
179
+ }.freeze
180
+
181
+ #
182
+ # Initialize a new activity.
183
+ # @private
184
+ #
185
+ # @param [Hash] data The activity data.
186
+ #
187
+ def initialize(data)
188
+ @name = data[:name]
189
+ @type = TYPES[data[:type]]
190
+ end
191
+
192
+ def inspect
193
+ "<#{self.class.name} #{@name} type=#{@type}>"
194
+ end
195
+ end
196
+ end
197
+ end