discorb 0.18.0 → 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (149) 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 +25 -0
  5. data/Gemfile +4 -4
  6. data/README.md +2 -1
  7. data/Rakefile +482 -459
  8. data/Steepfile +8 -6
  9. data/docs/application_command.md +1 -0
  10. data/docs/events.md +2 -2
  11. data/docs/voice_events.md +6 -6
  12. data/lib/discorb/allowed_mentions.rb +68 -72
  13. data/lib/discorb/app_command/command.rb +466 -394
  14. data/lib/discorb/app_command/common.rb +65 -25
  15. data/lib/discorb/app_command/handler.rb +304 -265
  16. data/lib/discorb/app_command.rb +5 -5
  17. data/lib/discorb/application.rb +198 -197
  18. data/lib/discorb/asset.rb +101 -101
  19. data/lib/discorb/attachment.rb +134 -119
  20. data/lib/discorb/audit_logs.rb +412 -385
  21. data/lib/discorb/automod.rb +279 -269
  22. data/lib/discorb/channel/base.rb +107 -108
  23. data/lib/discorb/channel/category.rb +32 -32
  24. data/lib/discorb/channel/container.rb +44 -44
  25. data/lib/discorb/channel/dm.rb +26 -28
  26. data/lib/discorb/channel/guild.rb +311 -246
  27. data/lib/discorb/channel/stage.rb +156 -140
  28. data/lib/discorb/channel/text.rb +430 -336
  29. data/lib/discorb/channel/thread.rb +374 -325
  30. data/lib/discorb/channel/voice.rb +85 -79
  31. data/lib/discorb/channel.rb +5 -5
  32. data/lib/discorb/client.rb +635 -623
  33. data/lib/discorb/color.rb +178 -182
  34. data/lib/discorb/common.rb +168 -164
  35. data/lib/discorb/components/button.rb +107 -106
  36. data/lib/discorb/components/select_menu.rb +157 -145
  37. data/lib/discorb/components/text_input.rb +103 -106
  38. data/lib/discorb/components.rb +68 -66
  39. data/lib/discorb/dictionary.rb +135 -135
  40. data/lib/discorb/embed.rb +404 -398
  41. data/lib/discorb/emoji.rb +309 -302
  42. data/lib/discorb/emoji_table.rb +16099 -8857
  43. data/lib/discorb/error.rb +131 -131
  44. data/lib/discorb/event.rb +360 -314
  45. data/lib/discorb/event_handler.rb +39 -39
  46. data/lib/discorb/exe/about.rb +17 -17
  47. data/lib/discorb/exe/irb.rb +72 -67
  48. data/lib/discorb/exe/new.rb +323 -315
  49. data/lib/discorb/exe/run.rb +69 -68
  50. data/lib/discorb/exe/setup.rb +57 -55
  51. data/lib/discorb/exe/show.rb +12 -12
  52. data/lib/discorb/extend.rb +25 -45
  53. data/lib/discorb/extension.rb +89 -83
  54. data/lib/discorb/flag.rb +126 -128
  55. data/lib/discorb/gateway.rb +984 -794
  56. data/lib/discorb/gateway_events.rb +670 -638
  57. data/lib/discorb/gateway_requests.rb +45 -48
  58. data/lib/discorb/guild.rb +2115 -1626
  59. data/lib/discorb/guild_template.rb +280 -241
  60. data/lib/discorb/http.rb +247 -232
  61. data/lib/discorb/image.rb +42 -42
  62. data/lib/discorb/integration.rb +169 -161
  63. data/lib/discorb/intents.rb +161 -163
  64. data/lib/discorb/interaction/autocomplete.rb +76 -62
  65. data/lib/discorb/interaction/command.rb +279 -224
  66. data/lib/discorb/interaction/components.rb +114 -104
  67. data/lib/discorb/interaction/modal.rb +36 -32
  68. data/lib/discorb/interaction/response.rb +379 -330
  69. data/lib/discorb/interaction/root.rb +271 -118
  70. data/lib/discorb/interaction.rb +5 -5
  71. data/lib/discorb/invite.rb +154 -153
  72. data/lib/discorb/member.rb +344 -311
  73. data/lib/discorb/message.rb +615 -544
  74. data/lib/discorb/message_meta.rb +197 -186
  75. data/lib/discorb/modules.rb +371 -290
  76. data/lib/discorb/permission.rb +305 -289
  77. data/lib/discorb/presence.rb +352 -346
  78. data/lib/discorb/rate_limit.rb +81 -76
  79. data/lib/discorb/reaction.rb +55 -54
  80. data/lib/discorb/role.rb +272 -240
  81. data/lib/discorb/shard.rb +76 -74
  82. data/lib/discorb/sticker.rb +193 -171
  83. data/lib/discorb/user.rb +205 -188
  84. data/lib/discorb/utils/colored_puts.rb +16 -16
  85. data/lib/discorb/utils.rb +12 -16
  86. data/lib/discorb/voice_state.rb +305 -281
  87. data/lib/discorb/webhook.rb +537 -507
  88. data/lib/discorb.rb +62 -56
  89. data/sig/discorb/activity.rbs +1 -0
  90. data/sig/discorb/allowed_mentions.rbs +1 -0
  91. data/sig/discorb/app_command/base.rbs +7 -1
  92. data/sig/discorb/application.rbs +6 -0
  93. data/sig/discorb/asset.rbs +2 -0
  94. data/sig/discorb/attachment.rbs +8 -0
  95. data/sig/discorb/audit_log.rbs +7 -0
  96. data/sig/discorb/automod.rbs +32 -6
  97. data/sig/discorb/avatar.rbs +1 -0
  98. data/sig/discorb/channel/base.rbs +8 -1
  99. data/sig/discorb/channel/category.rbs +1 -0
  100. data/sig/discorb/channel/container.rbs +4 -0
  101. data/sig/discorb/channel/stage.rbs +4 -0
  102. data/sig/discorb/channel/text.rbs +2 -2
  103. data/sig/discorb/channel/thread.rbs +11 -0
  104. data/sig/discorb/channel/voice.rbs +2 -0
  105. data/sig/discorb/client.rbs +21 -20
  106. data/sig/discorb/color.rbs +6 -0
  107. data/sig/discorb/component/base.rbs +1 -0
  108. data/sig/discorb/component/button.rbs +2 -0
  109. data/sig/discorb/component/select_menu.rbs +4 -0
  110. data/sig/discorb/component/text_input.rbs +1 -0
  111. data/sig/discorb/custom_emoji.rbs +5 -1
  112. data/sig/discorb/dictionary.rbs +2 -0
  113. data/sig/discorb/discord_model.rbs +2 -0
  114. data/sig/discorb/embed.rbs +7 -0
  115. data/sig/discorb/emoji.rbs +1 -0
  116. data/sig/discorb/event_handler.rbs +2 -1
  117. data/sig/discorb/extension.rbs +13 -12
  118. data/sig/discorb/flag.rbs +2 -0
  119. data/sig/discorb/gateway.rbs +5 -0
  120. data/sig/discorb/guild.rbs +8 -4
  121. data/sig/discorb/guild_template.rbs +1 -1
  122. data/sig/discorb/http.rbs +4 -1
  123. data/sig/discorb/image.rbs +2 -0
  124. data/sig/discorb/integration.rbs +1 -1
  125. data/sig/discorb/intents.rbs +4 -3
  126. data/sig/discorb/interaction/base.rbs +36 -0
  127. data/sig/discorb/interaction/message_component.rbs +1 -2
  128. data/sig/discorb/interaction/modal.rbs +1 -2
  129. data/sig/discorb/interaction/responder.rbs +49 -49
  130. data/sig/discorb/invite.rbs +1 -1
  131. data/sig/discorb/member.rbs +2 -0
  132. data/sig/discorb/message.rbs +8 -1
  133. data/sig/discorb/messageable.rbs +1 -4
  134. data/sig/discorb/partial_emoji.rbs +3 -0
  135. data/sig/discorb/permissions.rbs +7 -0
  136. data/sig/discorb/presence.rbs +2 -0
  137. data/sig/discorb/reaction.rbs +5 -1
  138. data/sig/discorb/role.rbs +7 -1
  139. data/sig/discorb/scheduled_event.rbs +2 -1
  140. data/sig/discorb/shard.rbs +2 -1
  141. data/sig/discorb/snowflake.rbs +2 -0
  142. data/sig/discorb/stage_instance.rbs +9 -3
  143. data/sig/discorb/sticker.rbs +1 -1
  144. data/sig/discorb/unicode_emoji.rbs +4 -0
  145. data/sig/discorb/user.rbs +24 -20
  146. data/sig/discorb/webhook.rbs +17 -6
  147. data/sig/discorb/welcome_screen.rbs +1 -0
  148. data/sig/override.rbs +2 -0
  149. metadata +3 -3
@@ -1,246 +1,311 @@
1
- # frozen_string_literal: true
2
-
3
- module Discorb
4
- #
5
- # Represents a channel in guild.
6
- # @abstract
7
- #
8
- class GuildChannel < Channel
9
- # @return [Integer] The position of the channel as integer.
10
- attr_reader :position
11
- # @return [Hash{Discorb::Role, Discorb::Member => PermissionOverwrite}] The permission overwrites of the channel.
12
- attr_reader :permission_overwrites
13
-
14
- # @!attribute [r] mention
15
- # @return [String] The mention of the channel.
16
- #
17
- # @!attribute [r] parent
18
- # @macro client_cache
19
- # @return [Discorb::CategoryChannel] The parent of channel.
20
- # @return [nil] If the channel is not a child of category.
21
- #
22
- # @!attribute [r] guild
23
- # @return [Discorb::Guild] The guild of channel.
24
- # @macro client_cache
25
-
26
- include Comparable
27
- @channel_type = nil
28
-
29
- #
30
- # Compares position of two channels.
31
- #
32
- # @param [Discorb::GuildChannel] other The channel to compare.
33
- #
34
- # @return [-1, 0, 1] -1 if the channel is at lower than the other, 1 if the channel is at highter than the other.
35
- #
36
- def <=>(other)
37
- return nil unless other.respond_to?(:position)
38
-
39
- @position <=> other.position
40
- end
41
-
42
- #
43
- # Checks if the channel is same as another.
44
- #
45
- # @param [Discorb::GuildChannel] other The channel to check.
46
- #
47
- # @return [Boolean] `true` if the channel is same as another.
48
- #
49
- def ==(other)
50
- return false unless other.respond_to?(:id)
51
-
52
- @id == other.id
53
- end
54
-
55
- #
56
- # Stringifies the channel.
57
- #
58
- # @return [String] The name of the channel with `#`.
59
- #
60
- def to_s
61
- "##{@name}"
62
- end
63
-
64
- def mention
65
- "<##{@id}>"
66
- end
67
-
68
- def parent
69
- return nil unless @parent_id
70
-
71
- @client.channels[@parent_id]
72
- end
73
-
74
- alias category parent
75
-
76
- def guild
77
- @client.guilds[@guild_id]
78
- end
79
-
80
- def inspect
81
- "#<#{self.class} \"##{@name}\" id=#{@id}>"
82
- end
83
-
84
- #
85
- # Deletes the channel.
86
- # @async
87
- #
88
- # @param [String] reason The reason of deleting the channel.
89
- #
90
- # @return [Async::Task<self>] The deleted channel.
91
- #
92
- def delete!(reason: nil)
93
- Async do
94
- @client.http.request(Route.new(base_url.wait.to_s, "//webhooks/:webhook_id/:token", :delete), {},
95
- audit_log_reason: reason).wait
96
- @deleted = true
97
- self
98
- end
99
- end
100
-
101
- alias close! delete!
102
- alias destroy! delete!
103
-
104
- #
105
- # Moves the channel to another position.
106
- # @async
107
- #
108
- # @param [Integer] position The position to move the channel.
109
- # @param [Boolean] lock_permissions Whether to lock the permissions of the channel.
110
- # @param [Discorb::CategoryChannel] parent The parent of channel.
111
- # @param [String] reason The reason of moving the channel.
112
- #
113
- # @return [Async::Task<self>] The moved channel.
114
- #
115
- def move(position, lock_permissions: false, parent: Discorb::Unset, reason: nil)
116
- Async do
117
- # @type var payload: Hash[Symbol, untyped]
118
- payload = {
119
- position: position,
120
- }
121
- payload[:lock_permissions] = lock_permissions
122
- payload[:parent_id] = parent&.id if parent != Discorb::Unset
123
- @client.http.request(Route.new("/guilds/#{@guild_id}/channels", "//guilds/:guild_id/channels", :patch),
124
- payload, audit_log_reason: reason).wait
125
- end
126
- end
127
-
128
- #
129
- # Set the channel's permission overwrite.
130
- # @async
131
- #
132
- # @param [Discorb::Role, Discorb::Member] target The target of the overwrite.
133
- # @param [String] reason The reason of setting the overwrite.
134
- # @param [{Symbol => Boolean}] perms The permission overwrites to replace.
135
- #
136
- # @return [Async::Task<void>] The task.
137
- #
138
- def set_permissions(target, reason: nil, **perms)
139
- Async do
140
- allow_value = @permission_overwrites[target]&.allow_value.to_i
141
- deny_value = @permission_overwrites[target]&.deny_value.to_i
142
- perms.each do |perm, value|
143
- allow_value[Discorb::Permission.bits[perm]] = 1 if value == true
144
- deny_value[Discorb::Permission.bits[perm]] = 1 if value == false
145
- end
146
- payload = {
147
- allow: allow_value,
148
- deny: deny_value,
149
- type: target.is_a?(Member) ? 1 : 0,
150
- }
151
- @client.http.request(
152
- Route.new("/channels/#{@id}/permissions/#{target.id}", "//channels/:channel_id/permissions/:target_id",
153
- :put), payload, audit_log_reason: reason,
154
- ).wait
155
- end
156
- end
157
-
158
- alias modify_permissions set_permissions
159
- alias modify_permisssion set_permissions
160
- alias edit_permissions set_permissions
161
- alias edit_permission set_permissions
162
-
163
- #
164
- # Delete the channel's permission overwrite.
165
- # @async
166
- #
167
- # @param [Discorb::Role, Discorb::Member] target The target of the overwrite.
168
- # @param [String] reason The reason of deleting the overwrite.
169
- #
170
- # @return [Async::Task<void>] The task.
171
- #
172
- def delete_permissions(target, reason: nil)
173
- Async do
174
- @client.http.request(
175
- Route.new("/channels/#{@id}/permissions/#{target.id}", "//channels/:channel_id/permissions/:target_id",
176
- :delete), {}, audit_log_reason: reason,
177
- ).wait
178
- end
179
- end
180
-
181
- alias delete_permission delete_permissions
182
- alias destroy_permissions delete_permissions
183
- alias destroy_permission delete_permissions
184
-
185
- #
186
- # Fetch the channel's invites.
187
- # @async
188
- #
189
- # @return [Async::Task<Array<Discorb::Invite>>] The invites in the channel.
190
- #
191
- def fetch_invites
192
- Async do
193
- _resp, data = @client.http.request(Route.new("/channels/#{@id}/invites", "//channels/:channel_id/invites",
194
- :get)).wait
195
- data.map { |invite| Invite.new(@client, invite, false) }
196
- end
197
- end
198
-
199
- #
200
- # Create an invite in the channel.
201
- # @async
202
- #
203
- # @param [Integer] max_age The max age of the invite.
204
- # @param [Integer] max_uses The max uses of the invite.
205
- # @param [Boolean] temporary Whether the invite is temporary.
206
- # @param [Boolean] unique Whether the invite is unique.
207
- # @note if it's `false` it may return existing invite.
208
- # @param [String] reason The reason of creating the invite.
209
- #
210
- # @return [Async::Task<Invite>] The created invite.
211
- #
212
- def create_invite(max_age: nil, max_uses: nil, temporary: false, unique: false, reason: nil)
213
- Async do
214
- _resp, data = @client.http.request(
215
- Route.new("/channels/#{@id}/invites", "//channels/:channel_id/invites", :post), {
216
- max_age: max_age,
217
- max_uses: max_uses,
218
- temporary: temporary,
219
- unique: unique,
220
- }, audit_log_reason: reason,
221
- ).wait
222
- Invite.new(@client, data, false)
223
- end
224
- end
225
-
226
- private
227
-
228
- def _set_data(data)
229
- @guild_id = data[:guild_id]
230
- @position = data[:position]
231
- @permission_overwrites = if data[:permission_overwrites]
232
- data[:permission_overwrites].to_h do |ow|
233
- [
234
- (ow[:type] == 1 ? guild.roles : guild.members)[ow[:id]],
235
- PermissionOverwrite.new(ow[:allow].to_i, ow[:deny].to_i),
236
- ]
237
- end
238
- else
239
- {}
240
- end
241
- @parent_id = data[:parent_id]
242
-
243
- super
244
- end
245
- end
246
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Discorb
4
+ #
5
+ # Represents a channel in guild.
6
+ # @abstract
7
+ #
8
+ class GuildChannel < Channel
9
+ # @return [Integer] The position of the channel as integer.
10
+ attr_reader :position
11
+ # @return [Hash{Discorb::Role, Discorb::Member => PermissionOverwrite}] The permission overwrites of the channel.
12
+ attr_reader :permission_overwrites
13
+
14
+ # @!attribute [r] mention
15
+ # @return [String] The mention of the channel.
16
+ #
17
+ # @!attribute [r] parent
18
+ # @macro client_cache
19
+ # @return [Discorb::CategoryChannel] The parent of channel.
20
+ # @return [nil] If the channel is not a child of category.
21
+ #
22
+ # @!attribute [r] guild
23
+ # @return [Discorb::Guild] The guild of channel.
24
+ # @macro client_cache
25
+
26
+ include Comparable
27
+ @channel_type = nil
28
+
29
+ #
30
+ # Compares position of two channels.
31
+ #
32
+ # @param [Discorb::GuildChannel] other The channel to compare.
33
+ #
34
+ # @return [-1, 0, 1] -1 if the channel is at lower than the other, 1 if the channel is at highter than the other.
35
+ #
36
+ def <=>(other)
37
+ return nil unless other.respond_to?(:position)
38
+
39
+ @position <=> other.position
40
+ end
41
+
42
+ #
43
+ # Checks if the channel is same as another.
44
+ #
45
+ # @param [Discorb::GuildChannel] other The channel to check.
46
+ #
47
+ # @return [Boolean] `true` if the channel is same as another.
48
+ #
49
+ def ==(other)
50
+ return false unless other.respond_to?(:id)
51
+
52
+ @id == other.id
53
+ end
54
+
55
+ #
56
+ # Stringifies the channel.
57
+ #
58
+ # @return [String] The name of the channel with `#`.
59
+ #
60
+ def to_s
61
+ "##{@name}"
62
+ end
63
+
64
+ def mention
65
+ "<##{@id}>"
66
+ end
67
+
68
+ def parent
69
+ return nil unless @parent_id
70
+
71
+ @client.channels[@parent_id]
72
+ end
73
+
74
+ alias category parent
75
+
76
+ def guild
77
+ @client.guilds[@guild_id]
78
+ end
79
+
80
+ def inspect
81
+ "#<#{self.class} \"##{@name}\" id=#{@id}>"
82
+ end
83
+
84
+ #
85
+ # Deletes the channel.
86
+ # @async
87
+ #
88
+ # @param [String] reason The reason of deleting the channel.
89
+ #
90
+ # @return [Async::Task<self>] The deleted channel.
91
+ #
92
+ def delete(reason: nil)
93
+ Async do
94
+ @client
95
+ .http
96
+ .request(
97
+ Route.new(
98
+ base_url.wait.to_s,
99
+ "//webhooks/:webhook_id/:token",
100
+ :delete
101
+ ),
102
+ {},
103
+ audit_log_reason: reason
104
+ )
105
+ .wait
106
+ @deleted = true
107
+ self
108
+ end
109
+ end
110
+
111
+ alias close delete
112
+ alias destroy delete
113
+
114
+ #
115
+ # Moves the channel to another position.
116
+ # @async
117
+ #
118
+ # @param [Integer] position The position to move the channel.
119
+ # @param [Boolean] lock_permissions Whether to lock the permissions of the channel.
120
+ # @param [Discorb::CategoryChannel] parent The parent of channel.
121
+ # @param [String] reason The reason of moving the channel.
122
+ #
123
+ # @return [Async::Task<self>] The moved channel.
124
+ #
125
+ def move(
126
+ position,
127
+ lock_permissions: false,
128
+ parent: Discorb::Unset,
129
+ reason: nil
130
+ )
131
+ Async do
132
+ # @type var payload: Hash[Symbol, untyped]
133
+ payload = { position: position }
134
+ payload[:lock_permissions] = lock_permissions
135
+ payload[:parent_id] = parent&.id if parent != Discorb::Unset
136
+ @client
137
+ .http
138
+ .request(
139
+ Route.new(
140
+ "/guilds/#{@guild_id}/channels",
141
+ "//guilds/:guild_id/channels",
142
+ :patch
143
+ ),
144
+ payload,
145
+ audit_log_reason: reason
146
+ )
147
+ .wait
148
+ end
149
+ end
150
+
151
+ #
152
+ # Set the channel's permission overwrite.
153
+ # @async
154
+ #
155
+ # @param [Discorb::Role, Discorb::Member] target The target of the overwrite.
156
+ # @param [String] reason The reason of setting the overwrite.
157
+ # @param [{Symbol => Boolean}] perms The permission overwrites to replace.
158
+ #
159
+ # @return [Async::Task<void>] The task.
160
+ #
161
+ def set_permissions(target, reason: nil, **perms)
162
+ Async do
163
+ allow_value = @permission_overwrites[target]&.allow_value.to_i
164
+ deny_value = @permission_overwrites[target]&.deny_value.to_i
165
+ perms.each do |perm, value|
166
+ allow_value[Discorb::Permission.bits[perm]] = 1 if value == true
167
+ deny_value[Discorb::Permission.bits[perm]] = 1 if value == false
168
+ end
169
+ payload = {
170
+ allow: allow_value,
171
+ deny: deny_value,
172
+ type: target.is_a?(Member) ? 1 : 0
173
+ }
174
+ @client
175
+ .http
176
+ .request(
177
+ Route.new(
178
+ "/channels/#{@id}/permissions/#{target.id}",
179
+ "//channels/:channel_id/permissions/:target_id",
180
+ :put
181
+ ),
182
+ payload,
183
+ audit_log_reason: reason
184
+ )
185
+ .wait
186
+ end
187
+ end
188
+
189
+ alias modify_permissions set_permissions
190
+ alias modify_permisssion set_permissions
191
+ alias edit_permissions set_permissions
192
+ alias edit_permission set_permissions
193
+
194
+ #
195
+ # Delete the channel's permission overwrite.
196
+ # @async
197
+ #
198
+ # @param [Discorb::Role, Discorb::Member] target The target of the overwrite.
199
+ # @param [String] reason The reason of deleting the overwrite.
200
+ #
201
+ # @return [Async::Task<void>] The task.
202
+ #
203
+ def delete_permissions(target, reason: nil)
204
+ Async do
205
+ @client
206
+ .http
207
+ .request(
208
+ Route.new(
209
+ "/channels/#{@id}/permissions/#{target.id}",
210
+ "//channels/:channel_id/permissions/:target_id",
211
+ :delete
212
+ ),
213
+ {},
214
+ audit_log_reason: reason
215
+ )
216
+ .wait
217
+ end
218
+ end
219
+
220
+ alias delete_permission delete_permissions
221
+ alias destroy_permissions delete_permissions
222
+ alias destroy_permission delete_permissions
223
+
224
+ #
225
+ # Fetch the channel's invites.
226
+ # @async
227
+ #
228
+ # @return [Async::Task<Array<Discorb::Invite>>] The invites in the channel.
229
+ #
230
+ def fetch_invites
231
+ Async do
232
+ _resp, data =
233
+ @client
234
+ .http
235
+ .request(
236
+ Route.new(
237
+ "/channels/#{@id}/invites",
238
+ "//channels/:channel_id/invites",
239
+ :get
240
+ )
241
+ )
242
+ .wait
243
+ data.map { |invite| Invite.new(@client, invite, false) }
244
+ end
245
+ end
246
+
247
+ #
248
+ # Create an invite in the channel.
249
+ # @async
250
+ #
251
+ # @param [Integer] max_age The max age of the invite.
252
+ # @param [Integer] max_uses The max uses of the invite.
253
+ # @param [Boolean] temporary Whether the invite is temporary.
254
+ # @param [Boolean] unique Whether the invite is unique.
255
+ # @note if it's `false` it may return existing invite.
256
+ # @param [String] reason The reason of creating the invite.
257
+ #
258
+ # @return [Async::Task<Invite>] The created invite.
259
+ #
260
+ def create_invite(
261
+ max_age: nil,
262
+ max_uses: nil,
263
+ temporary: false,
264
+ unique: false,
265
+ reason: nil
266
+ )
267
+ Async do
268
+ _resp, data =
269
+ @client
270
+ .http
271
+ .request(
272
+ Route.new(
273
+ "/channels/#{@id}/invites",
274
+ "//channels/:channel_id/invites",
275
+ :post
276
+ ),
277
+ {
278
+ max_age: max_age,
279
+ max_uses: max_uses,
280
+ temporary: temporary,
281
+ unique: unique
282
+ },
283
+ audit_log_reason: reason
284
+ )
285
+ .wait
286
+ Invite.new(@client, data, false)
287
+ end
288
+ end
289
+
290
+ private
291
+
292
+ def _set_data(data)
293
+ @guild_id = data[:guild_id]
294
+ @position = data[:position]
295
+ @permission_overwrites =
296
+ if data[:permission_overwrites]
297
+ data[:permission_overwrites].to_h do |ow|
298
+ [
299
+ (ow[:type] == 1 ? guild.roles : guild.members)[ow[:id]],
300
+ PermissionOverwrite.new(ow[:allow].to_i, ow[:deny].to_i)
301
+ ]
302
+ end
303
+ else
304
+ {}
305
+ end
306
+ @parent_id = data[:parent_id]
307
+
308
+ super
309
+ end
310
+ end
311
+ end