discorb 0.13.0 → 0.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/build_main.yml +1 -0
  3. data/.github/workflows/build_version.yml +1 -0
  4. data/.github/workflows/crowdin.yml +32 -0
  5. data/.gitignore +3 -1
  6. data/.yardopts +2 -0
  7. data/Changelog.md +399 -388
  8. data/Gemfile +5 -1
  9. data/README.md +1 -1
  10. data/Rakefile +139 -9
  11. data/crowdin.yml +2 -0
  12. data/docs/Examples.md +2 -0
  13. data/docs/application_command.md +7 -5
  14. data/docs/cli/irb.md +2 -0
  15. data/docs/cli/new.md +2 -0
  16. data/docs/cli/run.md +3 -1
  17. data/docs/cli/setup.md +4 -2
  18. data/docs/cli.md +2 -0
  19. data/docs/events.md +6 -4
  20. data/docs/extension.md +2 -2
  21. data/docs/faq.md +4 -2
  22. data/docs/license.md +2 -0
  23. data/docs/tutorial.md +4 -3
  24. data/docs/voice_events.md +2 -0
  25. data/lib/discorb/app_command.rb +8 -7
  26. data/lib/discorb/application.rb +1 -1
  27. data/lib/discorb/channel.rb +100 -76
  28. data/lib/discorb/client.rb +13 -15
  29. data/lib/discorb/common.rb +3 -1
  30. data/lib/discorb/emoji.rb +5 -7
  31. data/lib/discorb/emoji_table.rb +3891 -3891
  32. data/lib/discorb/event.rb +8 -7
  33. data/lib/discorb/exe/show.rb +2 -0
  34. data/lib/discorb/extension.rb +1 -1
  35. data/lib/discorb/flag.rb +1 -1
  36. data/lib/discorb/gateway.rb +9 -13
  37. data/lib/discorb/guild.rb +63 -89
  38. data/lib/discorb/guild_template.rb +12 -9
  39. data/lib/discorb/http.rb +82 -44
  40. data/lib/discorb/integration.rb +3 -0
  41. data/lib/discorb/interaction/response.rb +27 -25
  42. data/lib/discorb/interaction/root.rb +8 -0
  43. data/lib/discorb/invite.rb +3 -2
  44. data/lib/discorb/member.rb +41 -12
  45. data/lib/discorb/message.rb +28 -17
  46. data/lib/discorb/modules.rb +19 -26
  47. data/lib/discorb/role.rb +15 -11
  48. data/lib/discorb/sticker.rb +8 -12
  49. data/lib/discorb/user.rb +7 -7
  50. data/lib/discorb/voice_state.rb +8 -5
  51. data/lib/discorb/webhook.rb +38 -47
  52. data/lib/discorb.rb +1 -1
  53. data/po/yard.pot +7772 -5154
  54. data/sig/discorb.rbs +3316 -3819
  55. data/template-replace/scripts/locale_ja.rb +62 -0
  56. metadata +5 -3
@@ -7,8 +7,7 @@ module Discorb
7
7
  module Messageable
8
8
  #
9
9
  # Post a message to the channel.
10
- # @macro async
11
- # @macro http
10
+ # @async
12
11
  #
13
12
  # @param [String] content The message content.
14
13
  # @param [Boolean] tts Whether the message is tts.
@@ -38,14 +37,8 @@ module Discorb
38
37
  allowed_mentions ? allowed_mentions.to_hash(@client.allowed_mentions) : @client.allowed_mentions.to_hash
39
38
  payload[:message_reference] = reference.to_reference if reference
40
39
  payload[:components] = Component.to_payload(components) if components
41
- files = [file] if file
42
- if files
43
- seperator, payload = HTTP.multipart(payload, files)
44
- headers = { "content-type" => "multipart/form-data; boundary=#{seperator}" }
45
- else
46
- headers = {}
47
- end
48
- _resp, data = @client.http.post("/channels/#{channel_id.wait}/messages", payload, headers: headers).wait
40
+ files = [file]
41
+ _resp, data = @client.http.multipart_post("/channels/#{channel_id.wait}/messages", payload, files).wait
49
42
  Message.new(@client, data.merge({ guild_id: @guild_id.to_s }))
50
43
  end
51
44
  end
@@ -54,8 +47,7 @@ module Discorb
54
47
 
55
48
  #
56
49
  # Edit a message.
57
- # @macro async
58
- # @macro http
50
+ # @async
59
51
  #
60
52
  # @param [#to_s] message_id The message id.
61
53
  # @param [String] content The message content.
@@ -65,6 +57,8 @@ module Discorb
65
57
  # @param [Array<Discorb::Component>, Array<Array<Discorb::Component>>] components The components to send.
66
58
  # @param [Boolean] supress Whether to supress embeds.
67
59
  #
60
+ # @return [Async::Task<void>] The task.
61
+ #
68
62
  def edit_message(message_id, content = nil, embed: nil, embeds: nil, allowed_mentions: nil,
69
63
  components: nil, supress: nil)
70
64
  Async do
@@ -86,12 +80,13 @@ module Discorb
86
80
 
87
81
  #
88
82
  # Delete a message.
89
- # @macro async
90
- # @macro http
83
+ # @async
91
84
  #
92
85
  # @param [#to_s] message_id The message id.
93
86
  # @param [String] reason The reason for deleting the message.
94
87
  #
88
+ # @return [Async::Task<void>] The task.
89
+ #
95
90
  def delete_message!(message_id, reason: nil)
96
91
  Async do
97
92
  @client.http.delete("/channels/#{channel_id.wait}/messages/#{message_id}", audit_log_reason: reason).wait
@@ -102,8 +97,7 @@ module Discorb
102
97
 
103
98
  #
104
99
  # Fetch a message from ID.
105
- # @macro async
106
- # @macro http
100
+ # @async
107
101
  #
108
102
  # @param [Discorb::Snowflake] id The ID of the message.
109
103
  #
@@ -119,8 +113,7 @@ module Discorb
119
113
 
120
114
  #
121
115
  # Fetch a message history.
122
- # @macro async
123
- # @macro http
116
+ # @async
124
117
  #
125
118
  # @param [Integer] limit The number of messages to fetch.
126
119
  # @param [Discorb::Snowflake] before The ID of the message to fetch before.
@@ -144,8 +137,7 @@ module Discorb
144
137
 
145
138
  #
146
139
  # Fetch the pinned messages in the channel.
147
- # @macro async
148
- # @macro http
140
+ # @async
149
141
  #
150
142
  # @return [Async::Task<Array<Discorb::Message>>] The pinned messages in the channel.
151
143
  #
@@ -158,12 +150,13 @@ module Discorb
158
150
 
159
151
  #
160
152
  # Pin a message in the channel.
161
- # @macro async
162
- # @macro http
153
+ # @async
163
154
  #
164
155
  # @param [Discorb::Message] message The message to pin.
165
156
  # @param [String] reason The reason of pinning the message.
166
157
  #
158
+ # @return [Async::Task<void>] The task.
159
+ #
167
160
  def pin_message(message, reason: nil)
168
161
  Async do
169
162
  @client.http.put("/channels/#{channel_id.wait}/pins/#{message.id}", {}, audit_log_reason: reason).wait
@@ -172,12 +165,13 @@ module Discorb
172
165
 
173
166
  #
174
167
  # Unpin a message in the channel.
175
- # @macro async
176
- # @macro http
168
+ # @async
177
169
  #
178
170
  # @param [Discorb::Message] message The message to unpin.
179
171
  # @param [String] reason The reason of unpinning the message.
180
172
  #
173
+ # @return [Async::Task<void>] The task.
174
+ #
181
175
  def unpin_message(message, reason: nil)
182
176
  Async do
183
177
  @client.http.delete("/channels/#{channel_id.wait}/pins/#{message.id}", audit_log_reason: reason).wait
@@ -186,8 +180,7 @@ module Discorb
186
180
 
187
181
  #
188
182
  # Trigger the typing indicator in the channel.
189
- # @macro async
190
- # @macro http
183
+ # @async
191
184
  #
192
185
  # If block is given, trigger typing indicator during executing block.
193
186
  # @example
data/lib/discorb/role.rb CHANGED
@@ -90,12 +90,13 @@ module Discorb
90
90
 
91
91
  #
92
92
  # Moves the role to a new position.
93
- # @macro async
94
- # @macro http
93
+ # @async
95
94
  #
96
95
  # @param [Integer] position The new position.
97
96
  # @param [String] reason The reason for moving the role.
98
97
  #
98
+ # @return [Async::Task<void>] The task.
99
+ #
99
100
  def move(position, reason: nil)
100
101
  Async do
101
102
  @client.http.patch("/guilds/#{@guild.id}/roles", { id: @id, position: position }, audit_log_reason: reason).wait
@@ -104,8 +105,7 @@ module Discorb
104
105
 
105
106
  #
106
107
  # Edits the role.
107
- # @macro async
108
- # @macro http
108
+ # @async
109
109
  # @macro edit
110
110
  #
111
111
  # @param [String] name The new name of the role.
@@ -116,15 +116,17 @@ module Discorb
116
116
  # @param [Discorb::Image, Discorb::UnicodeEmoji] icon The new icon or emoji of the role.
117
117
  # @param [String] reason The reason for editing the role.
118
118
  #
119
- def edit(name: :unset, position: :unset, color: :unset, hoist: :unset, mentionable: :unset, icon: :unset, reason: nil)
119
+ # @return [Async::Task<void>] The task.
120
+ #
121
+ def edit(name: Discorb::Unset, position: Discorb::Unset, color: Discorb::Unset, hoist: Discorb::Unset, mentionable: Discorb::Unset, icon: Discorb::Unset, reason: nil)
120
122
  Async do
121
123
  payload = {}
122
- payload[:name] = name if name != :unset
123
- payload[:position] = position if position != :unset
124
- payload[:color] = color.to_i if color != :unset
125
- payload[:hoist] = hoist if hoist != :unset
126
- payload[:mentionable] = mentionable if mentionable != :unset
127
- if icon != :unset
124
+ payload[:name] = name if name != Discorb::Unset
125
+ payload[:position] = position if position != Discorb::Unset
126
+ payload[:color] = color.to_i if color != Discorb::Unset
127
+ payload[:hoist] = hoist if hoist != Discorb::Unset
128
+ payload[:mentionable] = mentionable if mentionable != Discorb::Unset
129
+ if icon != Discorb::Unset
128
130
  if icon.is_a?(Discorb::Image)
129
131
  payload[:icon] = icon.to_s
130
132
  else
@@ -142,6 +144,8 @@ module Discorb
142
144
  #
143
145
  # @param [String] reason The reason for deleting the role.
144
146
  #
147
+ # @return [Async::Task<void>] The task.
148
+ #
145
149
  def delete!(reason: nil)
146
150
  Async do
147
151
  @client.http.delete("/guilds/#{@guild.id}/roles/#{@id}", audit_log_reason: reason).wait
@@ -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,12 +75,14 @@ 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
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
85
86
  @client.http.patch("/guilds/#{@guild_id}/stickers/#{@id}", payload, audit_log_reason: reason).wait
86
87
  end
87
88
  end
@@ -90,8 +91,7 @@ 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
  #
@@ -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
  #
@@ -150,18 +149,19 @@ 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
@@ -166,19 +166,20 @@ 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
181
+ payload[:topic] = topic if topic != Discorb::Unset
182
+ payload[:privacy_level] = self.class.privacy_level.key(privacy_level) if privacy_level != Discorb::Unset
182
183
  @client.http.edit("/stage-instances/#{@channel_id}", payload, audit_log_reason: reason).wait
183
184
  self
184
185
  end
@@ -191,6 +192,8 @@ module Discorb
191
192
  #
192
193
  # @param [String] reason The reason for deleting the stage instance.
193
194
  #
195
+ # @return [Async::Task<void>] The task.
196
+ #
194
197
  def delete!(reason: nil)
195
198
  Async do
196
199
  @client.http.delete("/stage-instances/#{@channel_id}", audit_log_reason: reason).wait
@@ -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_post("#{url}?wait=#{wait}", files, payload, headers: headers).wait
88
79
  data && Webhook::Message.new(self, data)
89
80
  end
90
81
  end
@@ -93,20 +84,21 @@ 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
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
110
102
  @http.patch(url.to_s, payload).wait
111
103
  end
112
104
  end
@@ -115,8 +107,9 @@ 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
@@ -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_patch("#{url}/messages/#{Utils.try(message, :id)}", payload, headers: headers).wait
168
155
  message.send(:_set_data, data)
169
156
  message
170
157
  end
@@ -175,6 +162,8 @@ 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
169
  @http.delete("#{url}/messages/#{Utils.try(message, :id)}").wait
@@ -308,12 +297,13 @@ module Discorb
308
297
 
309
298
  #
310
299
  # Edits the message.
311
- # @macro async
312
- # @macro http
300
+ # @async
313
301
  # @macro edit
314
302
  #
315
303
  # @param (see Webhook#edit_message)
316
304
  #
305
+ # @return [Async::Task<void>] The task.
306
+ #
317
307
  def edit(...)
318
308
  Async do
319
309
  @webhook.edit_message(self, ...).wait
@@ -322,8 +312,9 @@ module Discorb
322
312
 
323
313
  #
324
314
  # Deletes the message.
325
- # @macro async
326
- # @macro http
315
+ # @async
316
+ #
317
+ # @return [Async::Task<void>] The task.
327
318
  #
328
319
  def delete!
329
320
  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.