discorb 0.13.0 → 0.13.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/build_main.yml +1 -0
  3. data/.github/workflows/build_version.yml +4 -3
  4. data/.github/workflows/crowdin.yml +32 -0
  5. data/.gitignore +3 -1
  6. data/.yardopts +2 -0
  7. data/CODE_OF_CONDUCT.md +128 -0
  8. data/Changelog.md +420 -388
  9. data/Gemfile +5 -1
  10. data/README.md +2 -2
  11. data/Rakefile +131 -1
  12. data/crowdin.yml +2 -0
  13. data/discorb.gemspec +12 -1
  14. data/docs/Examples.md +2 -0
  15. data/docs/application_command.md +7 -5
  16. data/docs/cli/irb.md +2 -0
  17. data/docs/cli/new.md +2 -0
  18. data/docs/cli/run.md +3 -1
  19. data/docs/cli/setup.md +4 -2
  20. data/docs/cli.md +2 -0
  21. data/docs/events.md +6 -4
  22. data/docs/extension.md +2 -2
  23. data/docs/faq.md +4 -2
  24. data/docs/license.md +2 -0
  25. data/docs/tutorial.md +4 -3
  26. data/docs/voice_events.md +2 -0
  27. data/lib/discorb/app_command.rb +32 -9
  28. data/lib/discorb/application.rb +1 -1
  29. data/lib/discorb/asset.rb +1 -1
  30. data/lib/discorb/channel.rb +170 -125
  31. data/lib/discorb/client.rb +20 -22
  32. data/lib/discorb/common.rb +32 -1
  33. data/lib/discorb/dictionary.rb +10 -2
  34. data/lib/discorb/emoji.rb +7 -9
  35. data/lib/discorb/emoji_table.rb +3891 -3891
  36. data/lib/discorb/event.rb +12 -11
  37. data/lib/discorb/exe/show.rb +2 -0
  38. data/lib/discorb/extension.rb +1 -1
  39. data/lib/discorb/flag.rb +1 -1
  40. data/lib/discorb/gateway.rb +63 -17
  41. data/lib/discorb/guild.rb +110 -156
  42. data/lib/discorb/guild_template.rb +15 -12
  43. data/lib/discorb/http.rb +41 -136
  44. data/lib/discorb/integration.rb +34 -2
  45. data/lib/discorb/interaction/autocomplete.rb +1 -1
  46. data/lib/discorb/interaction/response.rb +34 -32
  47. data/lib/discorb/interaction/root.rb +8 -0
  48. data/lib/discorb/invite.rb +4 -3
  49. data/lib/discorb/log.rb +3 -2
  50. data/lib/discorb/member.rb +44 -15
  51. data/lib/discorb/message.rb +33 -22
  52. data/lib/discorb/modules.rb +28 -35
  53. data/lib/discorb/presence.rb +2 -2
  54. data/lib/discorb/rate_limit.rb +14 -18
  55. data/lib/discorb/role.rb +18 -14
  56. data/lib/discorb/sticker.rb +10 -14
  57. data/lib/discorb/user.rb +10 -10
  58. data/lib/discorb/voice_state.rb +12 -7
  59. data/lib/discorb/webhook.rb +44 -50
  60. data/lib/discorb.rb +1 -1
  61. data/po/yard.pot +7772 -5154
  62. data/sig/discorb.rbs +3316 -3819
  63. data/template-replace/scripts/locale_ja.rb +62 -0
  64. metadata +18 -5
@@ -67,8 +67,7 @@ module Discorb
67
67
 
68
68
  #
69
69
  # Edits the sticker.
70
- # @macro async
71
- # @macro http
70
+ # @async
72
71
  # @macro edit
73
72
  #
74
73
  # @param [String] name The new name of the sticker.
@@ -76,13 +75,15 @@ module Discorb
76
75
  # @param [Discorb::Emoji] tag The new tags of the sticker.
77
76
  # @param [String] reason The reason for the edit.
78
77
  #
79
- def edit(name: :unset, description: :unset, tag: :unset, reason: :unset)
78
+ # @return [Async::Task<void>] The task.
79
+ #
80
+ def edit(name: Discorb::Unset, description: Discorb::Unset, tag: Discorb::Unset, reason: Discorb::Unset)
80
81
  Async do
81
82
  payload = {}
82
- payload[:name] = name unless name == :unset
83
- payload[:description] = description unless description == :unset
84
- payload[:tags] = tag.name unless tag == :unset
85
- @client.http.patch("/guilds/#{@guild_id}/stickers/#{@id}", payload, audit_log_reason: reason).wait
83
+ payload[:name] = name unless name == Discorb::Unset
84
+ payload[:description] = description unless description == Discorb::Unset
85
+ payload[:tags] = tag.name unless tag == Discorb::Unset
86
+ @client.http.request(Route.new("/guilds/#{@guild_id}/stickers/#{@id}", "//guilds/:guild_id/stickers/:sticker_id", :patch), payload, audit_log_reason: reason).wait
86
87
  end
87
88
  end
88
89
 
@@ -90,14 +91,13 @@ module Discorb
90
91
 
91
92
  #
92
93
  # Deletes the sticker.
93
- # @macro async
94
- # @macro http
94
+ # @async
95
95
  #
96
96
  # @param [String] reason The reason for the deletion.
97
97
  #
98
98
  def delete!(reason: nil)
99
99
  Async do
100
- @client.http.delete("/guilds/#{@guild_id}/stickers/#{@id}", audit_log_reason: reason).wait
100
+ @client.http.request(Route.new("/guilds/#{@guild_id}/stickers/#{@id}", "//guilds/:guild_id/stickers/:sticker_id", :delete), audit_log_reason: reason).wait
101
101
  end
102
102
  end
103
103
 
@@ -112,14 +112,10 @@ module Discorb
112
112
  attr_reader :id
113
113
  # @return [String] The name of the sticker pack.
114
114
  attr_reader :name
115
- # @return [Discorb::Snowflake] The ID of the SKU.
116
- attr_reader :sku_id
117
115
  # @return [Discorb::Snowflake] The cover sticker of the pack.
118
116
  attr_reader :cover_sticker_id
119
117
  # @return [String] The description of the pack.
120
118
  attr_reader :description
121
- # @return [Discorb::Store::SKU] The banner asset ID of the pack.
122
- attr_reader :banner_asset_id
123
119
  # @return [Array<Discorb::Sticker>] The stickers in the pack.
124
120
  attr_reader :stickers
125
121
  # @return [Discorb::Asset] The banner of the pack.
data/lib/discorb/user.rb CHANGED
@@ -58,8 +58,7 @@ module Discorb
58
58
 
59
59
  #
60
60
  # Whether the user is a owner of the client.
61
- # @macro async
62
- # @macro http
61
+ # @async
63
62
  #
64
63
  # @param [Boolean] strict Whether don't allow if the user is a member of the team.
65
64
  #
@@ -85,7 +84,7 @@ module Discorb
85
84
  Async do
86
85
  next @dm_channel_id if @dm_channel_id
87
86
 
88
- _resp, dm_channel = @client.http.post("/users/@me/channels", { recipient_id: @id }).wait
87
+ _resp, dm_channel = @client.http.request(Route.new("/users/@me/channels", "//users/@me/channels", :post), { recipient_id: @id }).wait
89
88
  @dm_channel_id = dm_channel[:id]
90
89
  @dm_channel_id
91
90
  end
@@ -138,7 +137,7 @@ module Discorb
138
137
  @avatar = data[:avatar] ? Asset.new(self, data[:avatar]) : DefaultAvatar.new(data[:discriminator])
139
138
  @bot = data[:bot]
140
139
  @raw_data = data
141
- @client.users[@id] = self if !data[:no_cache] && data.is_a?(User)
140
+ @client.users[@id] = self if !data[:no_cache]
142
141
  @created_at = @id.timestamp
143
142
  @data.update(data)
144
143
  end
@@ -150,25 +149,26 @@ module Discorb
150
149
  class ClientUser < User
151
150
  #
152
151
  # Edit the client user.
153
- # @macro async
154
- # @macro http
152
+ # @async
155
153
  # @macro edit
156
154
  #
157
155
  # @param [String] name The new username.
158
156
  # @param [Discorb::Image] avatar The new avatar.
159
157
  #
160
- def edit(name: :unset, avatar: :unset)
158
+ # @return [Async::Task<void>] The task.
159
+ #
160
+ def edit(name: Discorb::Unset, avatar: Discorb::Unset)
161
161
  Async do
162
162
  payload = {}
163
- payload[:username] = name unless name == :unset
164
- if avatar == :unset
163
+ payload[:username] = name unless name == Discorb::Unset
164
+ if avatar == Discorb::Unset
165
165
  # Nothing
166
166
  elsif avatar.nil?
167
167
  payload[:avatar] = nil
168
168
  else
169
169
  payload[:avatar] = avatar.to_s
170
170
  end
171
- @client.http.patch("/users/@me", payload).wait
171
+ @client.http.request(Route.new("/users/@me", "//users/@me", :patch), payload).wait
172
172
  self
173
173
  end
174
174
  end
@@ -166,20 +166,23 @@ module Discorb
166
166
 
167
167
  #
168
168
  # Edits the stage instance.
169
- # @macro async
170
- # @macro http
169
+ # @async
171
170
  # @macro edit
172
171
  #
173
172
  # @param [String] topic The new topic of the stage instance.
174
173
  # @param [:public, :guild_only] privacy_level The new privacy level of the stage instance.
175
174
  # @param [String] reason The reason for editing the stage instance.
176
175
  #
177
- def edit(topic: :unset, privacy_level: :unset, reason: nil)
176
+ # @return [Async::Task<void>] The task.
177
+ #
178
+ def edit(topic: Discorb::Unset, privacy_level: Discorb::Unset, reason: nil)
178
179
  Async do
179
180
  payload = {}
180
- payload[:topic] = topic if topic != :unset
181
- payload[:privacy_level] = self.class.privacy_level.key(privacy_level) if privacy_level != :unset
182
- @client.http.edit("/stage-instances/#{@channel_id}", payload, audit_log_reason: reason).wait
181
+ payload[:topic] = topic if topic != Discorb::Unset
182
+ payload[:privacy_level] = self.class.privacy_level.key(privacy_level) if privacy_level != Discorb::Unset
183
+ @client.http.request(
184
+ Route.new("/stage-instances/#{@channel_id}", "//stage-instances/:channel_id", :patch), payload, audit_log_reason: reason,
185
+ ).wait
183
186
  self
184
187
  end
185
188
  end
@@ -191,9 +194,11 @@ module Discorb
191
194
  #
192
195
  # @param [String] reason The reason for deleting the stage instance.
193
196
  #
197
+ # @return [Async::Task<void>] The task.
198
+ #
194
199
  def delete!(reason: nil)
195
200
  Async do
196
- @client.http.delete("/stage-instances/#{@channel_id}", audit_log_reason: reason).wait
201
+ @client.http.request(Route.new("/stage-instances/#{@channel_id}", "//stage-instances/:stage_instance_id", :delete), audit_log_reason: reason).wait
197
202
  self
198
203
  end
199
204
  end
@@ -43,8 +43,7 @@ module Discorb
43
43
 
44
44
  #
45
45
  # Posts a message to the webhook.
46
- # @macro async
47
- # @macro http
46
+ # @async
48
47
  #
49
48
  # @param [String] content The content of the message.
50
49
  # @param [Boolean] tts Whether the message should be sent as text-to-speech.
@@ -61,7 +60,7 @@ module Discorb
61
60
  # @return [Async::Task<nil>] If `wait` is false.
62
61
  #
63
62
  def post(content = nil, tts: false, embed: nil, embeds: nil, allowed_mentions: nil,
64
- file: nil, files: nil, username: nil, avatar_url: :unset, wait: true)
63
+ file: nil, files: nil, username: nil, avatar_url: Discorb::Unset, wait: true)
65
64
  Async do
66
65
  payload = {}
67
66
  payload[:content] = content if content
@@ -74,17 +73,9 @@ module Discorb
74
73
  payload[:embeds] = tmp_embed.map(&:to_hash) if tmp_embed
75
74
  payload[:allowed_mentions] = allowed_mentions&.to_hash
76
75
  payload[:username] = username if username
77
- payload[:avatar_url] = avatar_url if avatar_url != :unset
78
- files = [file] if file
79
- if files
80
- headers, payload = HTTP.multipart(payload, files)
81
- else
82
- headers = {
83
- "Content-Type" => "application/json",
84
- }
85
- end
86
- _resp, data = @http.post("#{url}?wait=#{wait}", payload, headers: headers).wait
87
-
76
+ payload[:avatar_url] = avatar_url if avatar_url != Discorb::Unset
77
+ files = [file]
78
+ _resp, data = @http.multipart_request(Route.new("#{url}?wait=#{wait}", "//webhooks/:webhook_id/:token", :post), files, payload, headers: headers).wait
88
79
  data && Webhook::Message.new(self, data)
89
80
  end
90
81
  end
@@ -93,21 +84,22 @@ module Discorb
93
84
 
94
85
  #
95
86
  # Edits the webhook.
96
- # @macro async
97
- # @macro http
87
+ # @async
98
88
  # @macro edit
99
89
  #
100
90
  # @param [String] name The new name of the webhook.
101
91
  # @param [Discorb::Image] avatar The new avatar of the webhook.
102
92
  # @param [Discorb::GuildChannel] channel The new channel of the webhook.
103
93
  #
104
- def edit(name: :unset, avatar: :unset, channel: :unset)
94
+ # @return [Async::Task<void>] The task.
95
+ #
96
+ def edit(name: Discorb::Unset, avatar: Discorb::Unset, channel: Discorb::Unset)
105
97
  Async do
106
98
  payload = {}
107
- payload[:name] = name if name != :unset
108
- payload[:avatar] = avatar if avatar != :unset
109
- payload[:channel_id] = Utils.try(channel, :id) if channel != :unset
110
- @http.patch(url.to_s, payload).wait
99
+ payload[:name] = name if name != Discorb::Unset
100
+ payload[:avatar] = avatar if avatar != Discorb::Unset
101
+ payload[:channel_id] = Utils.try(channel, :id) if channel != Discorb::Unset
102
+ @http.request(Route.new(url, "//webhooks/:webhook_id/:token", :patch), payload).wait
111
103
  end
112
104
  end
113
105
 
@@ -115,12 +107,13 @@ module Discorb
115
107
 
116
108
  #
117
109
  # Deletes the webhook.
118
- # @macro async
119
- # @macro http
110
+ # @async
111
+ #
112
+ # @return [Async::Task<void>] The task.
120
113
  #
121
114
  def delete!
122
115
  Async do
123
- @http.delete(url).wait
116
+ @http.request(Route.new(url, "//webhooks/:webhook_id/:token", :delete)).wait
124
117
  self
125
118
  end
126
119
  end
@@ -129,8 +122,7 @@ module Discorb
129
122
 
130
123
  #
131
124
  # Edits the webhook's message.
132
- # @macro async
133
- # @macro http
125
+ # @async
134
126
  # @macro edit
135
127
  #
136
128
  # @param [Discorb::Webhook::Message] message The message to edit.
@@ -142,29 +134,24 @@ module Discorb
142
134
  # @param [Array<Discorb::File>] files The files to send.
143
135
  # @param [Discorb::AllowedMentions] allowed_mentions The allowed mentions to send.
144
136
  #
137
+ # @return [Async::Task<void>] The task.
138
+ #
145
139
  def edit_message(
146
- message, content = :unset,
147
- embed: :unset, embeds: :unset,
148
- file: :unset, files: :unset,
149
- attachments: :unset,
150
- allowed_mentions: :unset
140
+ message, content = Discorb::Unset,
141
+ embed: Discorb::Unset, embeds: Discorb::Unset,
142
+ file: Discorb::Unset, files: Discorb::Unset,
143
+ attachments: Discorb::Unset,
144
+ allowed_mentions: Discorb::Unset
151
145
  )
152
146
  Async do
153
147
  payload = {}
154
- payload[:content] = content if content != :unset
155
- payload[:embeds] = embed ? [embed.to_hash] : [] if embed != :unset
156
- payload[:embeds] = embeds.map(&:to_hash) if embeds != :unset
157
- payload[:attachments] = attachments.map(&:to_hash) if attachments != :unset
158
- payload[:allowed_mentions] = allowed_mentions if allowed_mentions != :unset
159
- files = [file] if file != :unset
160
- if files == :unset
161
- headers = {
162
- "Content-Type" => "application/json",
163
- }
164
- else
165
- headers, payload = HTTP.multipart(payload, files)
166
- end
167
- _resp, data = @http.patch("#{url}/messages/#{Utils.try(message, :id)}", payload, headers: headers).wait
148
+ payload[:content] = content if content != Discorb::Unset
149
+ payload[:embeds] = embed ? [embed.to_hash] : [] if embed != Discorb::Unset
150
+ payload[:embeds] = embeds.map(&:to_hash) if embeds != Discorb::Unset
151
+ payload[:attachments] = attachments.map(&:to_hash) if attachments != Discorb::Unset
152
+ payload[:allowed_mentions] = allowed_mentions if allowed_mentions != Discorb::Unset
153
+ files = [file] if file != Discorb::Unset
154
+ _resp, data = @http.multipart_request(Route.new("#{url}/messages/#{Utils.try(message, :id)}", "//webhooks/:webhook_id/:token/messages/:message_id", :patch), payload, headers: headers).wait
168
155
  message.send(:_set_data, data)
169
156
  message
170
157
  end
@@ -175,9 +162,14 @@ module Discorb
175
162
  #
176
163
  # @param [Discorb::Webhook::Message] message The message to delete.
177
164
  #
165
+ # @return [Async::Task<void>] The task.
166
+ #
178
167
  def delete_message!(message)
179
168
  Async do
180
- @http.delete("#{url}/messages/#{Utils.try(message, :id)}").wait
169
+ @http.request(Route.new(
170
+ "#{url}/messages/#{Utils.try(message, :id)}",
171
+ "//webhooks/:webhook_id/:token/messages/:message_id", :delete
172
+ )).wait
181
173
  message
182
174
  end
183
175
  end
@@ -308,12 +300,13 @@ module Discorb
308
300
 
309
301
  #
310
302
  # Edits the message.
311
- # @macro async
312
- # @macro http
303
+ # @async
313
304
  # @macro edit
314
305
  #
315
306
  # @param (see Webhook#edit_message)
316
307
  #
308
+ # @return [Async::Task<void>] The task.
309
+ #
317
310
  def edit(...)
318
311
  Async do
319
312
  @webhook.edit_message(self, ...).wait
@@ -322,8 +315,9 @@ module Discorb
322
315
 
323
316
  #
324
317
  # Deletes the message.
325
- # @macro async
326
- # @macro http
318
+ # @async
319
+ #
320
+ # @return [Async::Task<void>] The task.
327
321
  #
328
322
  def delete!
329
323
  Async do
data/lib/discorb.rb CHANGED
@@ -16,7 +16,7 @@ module Discorb
16
16
  # @note You must enable `GUILD_MEMBERS` intent to use this method.
17
17
  #
18
18
  # @!macro edit
19
- # @note The arguments of this method are defaultly set to `:unset`. Specify value to set the value, if not don't specify or specify `:unset`.
19
+ # @note The arguments of this method are defaultly set to `Discorb::Unset`. Specify value to set the value, if not don't specify or specify `Discorb::Unset`.
20
20
  #
21
21
  # @!macro http
22
22
  # @note This method calls HTTP request.