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
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 = @client.http.request(Route.new("/users/@me/channels", "//users/@me/channels", :post),
99
- { recipient_id: @id }).wait
100
- @dm_channel_id = dm_channel[:id]
101
- @dm_channel_id
102
- end
103
- end
104
-
105
- #
106
- # Represents the user's flags.
107
- # ## Flag fields
108
- # |`1 << 0`|`:discord_employee`|
109
- # |`1 << 1`|`:partnered_server_owner`|
110
- # |`1 << 2`|`:hypesquad_events`|
111
- # |`1 << 3`|`:bug_hunter_level_1`|
112
- # |`1 << 6`|`:house_bravery`|
113
- # |`1 << 7`|`:house_brilliance`|
114
- # |`1 << 8`|`:house_balance`|
115
- # |`1 << 9`|`:early_supporter`|
116
- # |`1 << 10`|`:team_user`|
117
- # |`1 << 14`|`:bug_hunter_level_2`|
118
- # |`1 << 16`|`:verified_bot`|
119
- # |`1 << 17`|`:early_verified_bot_developer`|
120
- # |`1 << 18`|`:discord_certified_moderator`|
121
- #
122
- class Flag < Discorb::Flag
123
- @bits = {
124
- discord_employee: 0,
125
- partnered_server_owner: 1,
126
- hypesquad_events: 2,
127
- bug_hunter_level_1: 3,
128
- house_bravery: 6,
129
- house_brilliance: 7,
130
- house_balance: 8,
131
- early_supporter: 9,
132
- team_user: 10,
133
- bug_hunter_level_2: 14,
134
- verified_bot: 16,
135
- early_verified_bot_developer: 17,
136
- discord_certified_moderator: 18,
137
- bot_http_interactions: 19,
138
- }.freeze
139
- end
140
-
141
- private
142
-
143
- def _set_data(data)
144
- @username = data[:username]
145
- @verified = data[:verified]
146
- @id = Snowflake.new(data[:id])
147
- @flag = User::Flag.new(data[:public_flags] | (data[:flags] || 0))
148
- @discriminator = data[:discriminator]
149
- @avatar = data[:avatar] ? Asset.new(self, data[:avatar]) : DefaultAvatar.new(data[:discriminator])
150
- @bot = data[:bot] || false
151
- @raw_data = data
152
- @client.users[@id] = self unless data[:no_cache]
153
- @created_at = @id.timestamp
154
- @data.update(data)
155
- end
156
- end
157
-
158
- #
159
- # Represents a client user.
160
- #
161
- class ClientUser < User
162
- #
163
- # Edit the client user.
164
- # @async
165
- # @macro edit
166
- #
167
- # @param [String] name The new username.
168
- # @param [Discorb::Image] avatar The new avatar.
169
- #
170
- # @return [Async::Task<void>] The task.
171
- #
172
- def edit(name: Discorb::Unset, avatar: Discorb::Unset)
173
- Async do
174
- payload = {}
175
- payload[:username] = name unless name == Discorb::Unset
176
- if avatar == Discorb::Unset
177
- # Nothing
178
- elsif avatar.nil?
179
- payload[:avatar] = nil
180
- else
181
- payload[:avatar] = avatar.to_s
182
- end
183
- @client.http.request(Route.new("/users/@me", "//users/@me", :patch), payload).wait
184
- self
185
- end
186
- end
187
- end
188
- end
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
- if object.respond_to?(message)
8
- object.send(message, ...)
9
- else
10
- object
11
- end
12
- end
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