discorb 0.12.4 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +10 -0
- data/docs/application_command.md +10 -8
- data/docs/events.md +53 -1
- data/lib/discorb/application.rb +31 -1
- data/lib/discorb/audit_logs.rb +28 -16
- data/lib/discorb/channel.rb +12 -5
- data/lib/discorb/client.rb +4 -4
- data/lib/discorb/common.rb +26 -1
- data/lib/discorb/components.rb +12 -0
- data/lib/discorb/dictionary.rb +1 -1
- data/lib/discorb/embed.rb +4 -0
- data/lib/discorb/emoji.rb +4 -0
- data/lib/discorb/event.rb +265 -24
- data/lib/discorb/event_handler.rb +39 -0
- data/lib/discorb/extension.rb +4 -4
- data/lib/discorb/file.rb +4 -0
- data/lib/discorb/flag.rb +4 -0
- data/lib/discorb/gateway.rb +56 -1
- data/lib/discorb/gateway_requests.rb +4 -0
- data/lib/discorb/guild.rb +113 -0
- data/lib/discorb/image.rb +7 -5
- data/lib/discorb/intents.rb +8 -3
- data/lib/discorb/log.rb +4 -0
- data/lib/discorb/member.rb +1 -1
- data/lib/discorb/message.rb +4 -0
- data/lib/discorb/permission.rb +4 -0
- data/lib/discorb/rate_limit.rb +6 -2
- data/lib/discorb/sticker.rb +9 -0
- data/lib/discorb/user.rb +1 -0
- data/lib/discorb.rb +1 -1
- data/po/yard.pot +4 -4
- data/sig/discorb.rbs +7 -7
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54c0aa4482415e2d38abe5adf4765ec71681d7f0874a5208b868797c4ebc4626
|
4
|
+
data.tar.gz: 6d15fbcc255d6fddb22e4d8b73f6a7fee40b3690a2f79b4356adcec029d1e90c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d866205f326de7437f2f8464e0e69fa14c024cd2427507b428507249352902c84003d741265e1b40b86e545435362fd001d949ebe2d9828216bcb5440f93eee3
|
7
|
+
data.tar.gz: 1b2797ea34e32198aa660486771db933ea6893b9542e30a813ce14c2d4b49299ef24c4ecc7ea052dbd7260c5eabe728b120026f543aca49ecc0f2040450741bc
|
data/Changelog.md
CHANGED
@@ -2,6 +2,16 @@
|
|
2
2
|
|
3
3
|
# Changelog
|
4
4
|
|
5
|
+
## v0.13
|
6
|
+
|
7
|
+
### v0.13.0
|
8
|
+
|
9
|
+
- Change!: Event is now EventHandler.
|
10
|
+
- Add: Support for scheduled events.
|
11
|
+
- Fix: Fix bug in sticker initialization.
|
12
|
+
- Add: Support application flags
|
13
|
+
- Add: Add `#inspect` method to many classes.
|
14
|
+
|
5
15
|
## v0.12
|
6
16
|
|
7
17
|
### v0.12.4
|
data/docs/application_command.md
CHANGED
@@ -49,6 +49,8 @@ client.run(ENV["DISCORD_BOT_TOKEN"])
|
|
49
49
|
| `guild_ids` | The ID of the guild to register the command in. |
|
50
50
|
| `block` | A block that will be called when the command is invoked. |
|
51
51
|
|
52
|
+
Block will be called with a {Discorb::ApplicationCommand::Interaction} object and specified options.
|
53
|
+
|
52
54
|
In `options`, hash should be like this:
|
53
55
|
|
54
56
|
```ruby
|
@@ -121,16 +123,16 @@ group.slash("message_expand", "Whether bot should expand message.", {
|
|
121
123
|
type: :boolean,
|
122
124
|
description: "Whether bot should expand message."
|
123
125
|
}
|
124
|
-
}) do |interaction|
|
126
|
+
}) do |interaction, enabled|
|
125
127
|
# ...
|
126
128
|
end
|
127
129
|
|
128
|
-
group.slash("
|
130
|
+
group.slash("level", "Whether level system is enabled.", {
|
129
131
|
"enabled" => {
|
130
132
|
type: :boolean,
|
131
|
-
description: "Whether
|
133
|
+
description: "Whether level system is enabled."
|
132
134
|
}
|
133
|
-
}) do |interaction|
|
135
|
+
}) do |interaction, enabled|
|
134
136
|
# ...
|
135
137
|
end
|
136
138
|
|
@@ -146,15 +148,15 @@ client.slash_group("settings", "Set settings of bot.") do |group|
|
|
146
148
|
type: :boolean,
|
147
149
|
description: "Whether bot should expand message."
|
148
150
|
}
|
149
|
-
}) do |interaction|
|
151
|
+
}) do |interaction, enabled|
|
150
152
|
# ...
|
151
153
|
end
|
152
|
-
group.slash("bump_alert", "Whether
|
154
|
+
group.slash("bump_alert", "Whether level system is enabled.", {
|
153
155
|
"enabled" => {
|
154
156
|
type: :boolean,
|
155
|
-
description: "Whether
|
157
|
+
description: "Whether level system is enabled."
|
156
158
|
}
|
157
|
-
}) do |interaction|
|
159
|
+
}) do |interaction, enabled|
|
158
160
|
# ...
|
159
161
|
end
|
160
162
|
end
|
data/docs/events.md
CHANGED
@@ -503,7 +503,50 @@ Fires when a select menu is selected.
|
|
503
503
|
|
504
504
|
### Voice events
|
505
505
|
|
506
|
-
|
506
|
+
Because it's big, it's documented in {file:docs/voice_events.md}.
|
507
|
+
|
508
|
+
### Guild scheduled event events
|
509
|
+
|
510
|
+
#### `scheduled_event_create(event)`
|
511
|
+
|
512
|
+
Fires when a scheduled event is created.
|
513
|
+
|
514
|
+
| Parameter | Type | Description |
|
515
|
+
| ---------- | ----- | ----------- |
|
516
|
+
| `event` | {Discorb::ScheduledEvent}| The created scheduled event. |
|
517
|
+
|
518
|
+
#### `scheduled_event_cancel(event)`, `scheduled_event_delete(event)`
|
519
|
+
|
520
|
+
Fires when a scheduled event is canceled or deleted.
|
521
|
+
|
522
|
+
| Parameter | Type | Description |
|
523
|
+
| ---------- | ----- | ----------- |
|
524
|
+
| `event` | {Discorb::ScheduledEvent}| The deleted scheduled event. |
|
525
|
+
|
526
|
+
#### `scheduled_event_edit(before, after)`
|
527
|
+
|
528
|
+
Fires when a scheduled event is edited.
|
529
|
+
|
530
|
+
| Parameter | Type | Description |
|
531
|
+
| ---------- | ----- | ----------- |
|
532
|
+
| `before` | {Discorb::ScheduledEvent}| The scheduled event before the edit. |
|
533
|
+
| `after` | {Discorb::ScheduledEvent}| The scheduled event after the edit. |
|
534
|
+
|
535
|
+
#### `scheduled_event_start(event)`
|
536
|
+
|
537
|
+
Fires when a scheduled event is started.
|
538
|
+
|
539
|
+
| Parameter | Type | Description |
|
540
|
+
| ---------- | ----- | ----------- |
|
541
|
+
| `event` | {Discorb::ScheduledEvent}| The scheduled event that started. |
|
542
|
+
|
543
|
+
#### `scheduled_event_end(event)`
|
544
|
+
|
545
|
+
Fires when a scheduled event is ended.
|
546
|
+
|
547
|
+
| Parameter | Type | Description |
|
548
|
+
| ---------- | ----- | ----------- |
|
549
|
+
| `event` | {Discorb::ScheduledEvent}| The scheduled event that ended. |
|
507
550
|
|
508
551
|
### Low-level events
|
509
552
|
|
@@ -530,3 +573,12 @@ Fires when `THREAD_CREATE` is received.
|
|
530
573
|
| Parameter | Type | Description |
|
531
574
|
| ---------- | ----- | ----------- |
|
532
575
|
|`thread` | {Discorb::ThreadChannel}| The thread of the event. |
|
576
|
+
|
577
|
+
#### `scheduled_event_update(before, after)`
|
578
|
+
|
579
|
+
Fires when `SCHEDULED_EVENT_UPDATE` is received.
|
580
|
+
|
581
|
+
| Parameter | Type | Description |
|
582
|
+
| ---------- | ----- | ----------- |
|
583
|
+
| `before` | {Discorb::ScheduledEvent}| The scheduled event before the update. |
|
584
|
+
|`after` | {Discorb::ScheduledEvent}| The scheduled event after the update. |
|
data/lib/discorb/application.rb
CHANGED
@@ -27,7 +27,8 @@ module Discorb
|
|
27
27
|
# @return [Boolean] Whether the application's bot requires a code grant.
|
28
28
|
attr_reader :bot_require_code_grant
|
29
29
|
alias bot_require_code_grant? bot_require_code_grant
|
30
|
-
|
30
|
+
# @return [Discorb::Application::Flag] The application's flags.
|
31
|
+
attr_reader :flags
|
31
32
|
# @private
|
32
33
|
def initialize(client, data)
|
33
34
|
@client = client
|
@@ -42,6 +43,7 @@ module Discorb
|
|
42
43
|
@verify_key = data[:verify_key]
|
43
44
|
@owner = @client.users[data[:owner][:id]] || User.new(@client, data[:owner])
|
44
45
|
@team = data[:team] && Team.new(@client, data[:team])
|
46
|
+
@flags = Flag.new(data[:flags])
|
45
47
|
end
|
46
48
|
|
47
49
|
def inspect
|
@@ -52,6 +54,34 @@ module Discorb
|
|
52
54
|
|
53
55
|
alias require_code_grant? bot_require_code_grant?
|
54
56
|
|
57
|
+
#
|
58
|
+
# Represents a flag for an application.
|
59
|
+
# ## Flag fields
|
60
|
+
#
|
61
|
+
# | Field|Value|
|
62
|
+
# |---|---|
|
63
|
+
# | `1 << 12` | `:gateway_presence` |
|
64
|
+
# | `1 << 13` | `:gateway_presence_limited` |
|
65
|
+
# | `1 << 14` | `:gateway_guild_members` |
|
66
|
+
# | `1 << 15` | `:gateway_guild_members_limited` |
|
67
|
+
# | `1 << 16` | `:verification_pending_guild_limit` |
|
68
|
+
# | `1 << 17` | `:embedded` |
|
69
|
+
# | `1 << 18` | `:gateway_message_content` |
|
70
|
+
# | `1 << 19` | `:gateway_message_content_limited` |
|
71
|
+
#
|
72
|
+
class Flag < Discorb::Flag
|
73
|
+
@bits = {
|
74
|
+
gateway_presence: 12,
|
75
|
+
gateway_presence_limited: 13,
|
76
|
+
gateway_guild_members: 14,
|
77
|
+
gateway_guild_members_limited: 15,
|
78
|
+
verification_pending_guild_limit: 16,
|
79
|
+
embedded: 17,
|
80
|
+
gateway_message_content: 18,
|
81
|
+
gateway_message_content_limited: 19,
|
82
|
+
}
|
83
|
+
end
|
84
|
+
|
55
85
|
#
|
56
86
|
# Represents a team for an application.
|
57
87
|
#
|
data/lib/discorb/audit_logs.rb
CHANGED
@@ -90,6 +90,9 @@ module Discorb
|
|
90
90
|
# * `:sticker_create`
|
91
91
|
# * `:sticker_update`
|
92
92
|
# * `:sticker_delete`
|
93
|
+
# * `:guild_scheduled_event_create`
|
94
|
+
# * `:guild_scheduled_event_update`
|
95
|
+
# * `:guild_scheduled_event_delete`
|
93
96
|
# * `:thread_create`
|
94
97
|
# * `:thread_update`
|
95
98
|
# * `:thread_delete`
|
@@ -148,9 +151,12 @@ module Discorb
|
|
148
151
|
90 => :sticker_create,
|
149
152
|
91 => :sticker_update,
|
150
153
|
92 => :sticker_delete,
|
154
|
+
100 => :guild_scheduled_event_create,
|
155
|
+
101 => :guild_scheduled_event_update,
|
156
|
+
102 => :guild_scheduled_event_delete,
|
151
157
|
110 => :thread_create,
|
152
158
|
111 => :thread_update,
|
153
|
-
112 => :thread_delete
|
159
|
+
112 => :thread_delete,
|
154
160
|
}.freeze
|
155
161
|
|
156
162
|
# @private
|
@@ -160,7 +166,7 @@ module Discorb
|
|
160
166
|
role: ->(client, id, guild_id) { client.guilds[guild_id]&.roles&.[](id) },
|
161
167
|
member: ->(client, id, guild_id) { client.guilds[guild_id]&.members&.[](id) },
|
162
168
|
guild: ->(client, id, _guild_id) { client.guilds[id] },
|
163
|
-
message: ->(client, id, _guild_id) { client.messages[id] }
|
169
|
+
message: ->(client, id, _guild_id) { client.messages[id] },
|
164
170
|
}
|
165
171
|
|
166
172
|
# @private
|
@@ -171,15 +177,15 @@ module Discorb
|
|
171
177
|
@user_id = Snowflake.new(data[:user_id])
|
172
178
|
@target_id = Snowflake.new(data[:target_id])
|
173
179
|
@type = self.class.events[data[:action_type]]
|
174
|
-
@target = self.class.converts[@type.to_s.split(
|
180
|
+
@target = self.class.converts[@type.to_s.split("_")[0].to_sym]&.call(client, @target_id, @gui)
|
175
181
|
@target ||= Snowflake.new(data[:target_id])
|
176
182
|
@changes = data[:changes] && Changes.new(data[:changes])
|
177
183
|
@reason = data[:reason]
|
178
184
|
data[:options]&.each do |option, value|
|
179
185
|
define_singleton_method(option) { value }
|
180
|
-
if option.end_with?(
|
181
|
-
define_singleton_method(option.to_s.sub(
|
182
|
-
self.class.converts[option.to_s.split(
|
186
|
+
if option.end_with?("_id")
|
187
|
+
define_singleton_method(option.to_s.sub("_id", "")) do
|
188
|
+
self.class.converts[option.to_s.split("_")[0].to_sym]&.call(client, value, @guild_id)
|
183
189
|
end
|
184
190
|
end
|
185
191
|
end
|
@@ -203,7 +209,7 @@ module Discorb
|
|
203
209
|
end
|
204
210
|
|
205
211
|
def inspect
|
206
|
-
"#<#{self.class} #{@changes&.data&.length ||
|
212
|
+
"#<#{self.class} #{@changes&.data&.length || "No"} changes>"
|
207
213
|
end
|
208
214
|
|
209
215
|
class << self
|
@@ -268,15 +274,21 @@ module Discorb
|
|
268
274
|
def initialize(data)
|
269
275
|
@key = data[:key].to_sym
|
270
276
|
method = case @key.to_s
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
277
|
+
when /.*_id$/, "id"
|
278
|
+
->(v) { Snowflake.new(v) }
|
279
|
+
when "permissions"
|
280
|
+
->(v) { Discorb::Permission.new(v.to_i) }
|
281
|
+
when "status"
|
282
|
+
->(v) { Discorb::ScheduledEvent.status[v] }
|
283
|
+
when "entity_type"
|
284
|
+
->(v) { Discorb::ScheduledEvent.entity_type[v] }
|
285
|
+
when "privacy_level"
|
286
|
+
->(v) { Discorb::StageInstance.privacy_level[v] || Discorb::ScheduledEvent.privacy_level[v] }
|
287
|
+
else
|
288
|
+
->(v) { v }
|
289
|
+
end
|
290
|
+
@old_value = method.(data[:old_value])
|
291
|
+
@new_value = method.(data[:new_value])
|
280
292
|
end
|
281
293
|
|
282
294
|
#
|
data/lib/discorb/channel.rb
CHANGED
@@ -491,17 +491,24 @@ module Discorb
|
|
491
491
|
# @param [Discorb::Message] message The message to start the thread.
|
492
492
|
# @param [Integer] auto_archive_duration The duration of auto-archiving.
|
493
493
|
# @param [Boolean] public Whether the thread is public.
|
494
|
+
# @param [Integer] rate_limit_per_user The rate limit per user.
|
495
|
+
# @param [Integer] slowmode Alias of `rate_limit_per_user`.
|
494
496
|
# @param [String] reason The reason of starting the thread.
|
495
497
|
#
|
496
498
|
# @return [Async::Task<Discorb::ThreadChannel>] The started thread.
|
497
499
|
#
|
498
|
-
def start_thread(name, message: nil, auto_archive_duration: 1440, public: true, reason: nil)
|
500
|
+
def start_thread(name, message: nil, auto_archive_duration: 1440, public: true, rate_limit_per_user: nil, slowmode: nil, reason: nil)
|
499
501
|
Async do
|
500
502
|
_resp, data = if message.nil?
|
501
|
-
@client.http.post(
|
502
|
-
|
503
|
-
|
504
|
-
|
503
|
+
@client.http.post(
|
504
|
+
"/channels/#{@id}/threads", {
|
505
|
+
name: name,
|
506
|
+
auto_archive_duration: auto_archive_duration,
|
507
|
+
type: public ? 11 : 10,
|
508
|
+
rate_limit_per_user: rate_limit_per_user || slowmode,
|
509
|
+
},
|
510
|
+
audit_log_reason: reason,
|
511
|
+
).wait
|
505
512
|
else
|
506
513
|
@client.http.post("/channels/#{@id}/messages/#{Utils.try(message, :id)}/threads", {
|
507
514
|
name: name, auto_archive_duration: auto_archive_duration,
|
data/lib/discorb/client.rb
CHANGED
@@ -112,10 +112,10 @@ module Discorb
|
|
112
112
|
# @param [Hash] metadata The metadata of the event.
|
113
113
|
# @param [Proc] block The block to execute when the event is triggered.
|
114
114
|
#
|
115
|
-
# @return [Discorb::
|
115
|
+
# @return [Discorb::EventHandler] The event.
|
116
116
|
#
|
117
117
|
def on(event_name, id: nil, **metadata, &block)
|
118
|
-
ne =
|
118
|
+
ne = EventHandler.new(block, id, metadata)
|
119
119
|
@events[event_name] ||= []
|
120
120
|
@events[event_name].delete_if { |e| e.metadata[:override] }
|
121
121
|
@events[event_name] << ne
|
@@ -127,7 +127,7 @@ module Discorb
|
|
127
127
|
#
|
128
128
|
# @param (see #on)
|
129
129
|
#
|
130
|
-
# @return [Discorb::
|
130
|
+
# @return [Discorb::EventHandler] The event.
|
131
131
|
#
|
132
132
|
def once(event_name, id: nil, **metadata, &block)
|
133
133
|
metadata[:once] = true
|
@@ -184,7 +184,7 @@ module Discorb
|
|
184
184
|
events.each do |block|
|
185
185
|
Async do
|
186
186
|
Async(annotation: "Discorb event: #{event_name}") do |task|
|
187
|
-
if block.is_a?(Discorb::
|
187
|
+
if block.is_a?(Discorb::EventHandler)
|
188
188
|
@events[event_name].delete(block) if block.metadata[:once]
|
189
189
|
end
|
190
190
|
block.call(*args)
|
data/lib/discorb/common.rb
CHANGED
@@ -4,7 +4,7 @@ module Discorb
|
|
4
4
|
# @return [String] The API base URL.
|
5
5
|
API_BASE_URL = "https://discord.com/api/v9"
|
6
6
|
# @return [String] The version of discorb.
|
7
|
-
VERSION = "0.
|
7
|
+
VERSION = "0.13.0"
|
8
8
|
# @return [String] The user agent for the bot.
|
9
9
|
USER_AGENT = "DiscordBot (https://discorb-lib.github.io #{VERSION}) Ruby/#{RUBY_VERSION}"
|
10
10
|
|
@@ -110,6 +110,31 @@ module Discorb
|
|
110
110
|
@value & 0xFFF
|
111
111
|
end
|
112
112
|
|
113
|
+
def inspect
|
114
|
+
"#<#{self.class} #{to_s}>"
|
115
|
+
end
|
116
|
+
|
113
117
|
alias id to_s
|
114
118
|
end
|
119
|
+
|
120
|
+
Unset = Object.new
|
121
|
+
class << Unset
|
122
|
+
def method_missing(*)
|
123
|
+
self
|
124
|
+
end
|
125
|
+
|
126
|
+
def or(other)
|
127
|
+
other
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
module DefineOr
|
132
|
+
refine Object do
|
133
|
+
def or(other)
|
134
|
+
self
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
using DefineOr
|
115
140
|
end
|
data/lib/discorb/components.rb
CHANGED
@@ -6,6 +6,10 @@ module Discorb
|
|
6
6
|
# Represents a Discord component.
|
7
7
|
#
|
8
8
|
class Component
|
9
|
+
def inspect
|
10
|
+
"#<#{self.class}>"
|
11
|
+
end
|
12
|
+
|
9
13
|
class << self
|
10
14
|
#
|
11
15
|
# Create a new component from hash data.
|
@@ -142,6 +146,10 @@ module Discorb
|
|
142
146
|
end
|
143
147
|
end
|
144
148
|
|
149
|
+
def inspect
|
150
|
+
"#<#{self.class}: #{@custom_id || @url}>"
|
151
|
+
end
|
152
|
+
|
145
153
|
class << self
|
146
154
|
# @private
|
147
155
|
attr_reader :styles
|
@@ -218,6 +226,10 @@ module Discorb
|
|
218
226
|
}
|
219
227
|
end
|
220
228
|
|
229
|
+
def inspect
|
230
|
+
"#<#{self.class}: #{@custom_id}>"
|
231
|
+
end
|
232
|
+
|
221
233
|
#
|
222
234
|
# Represents an option of a select menu.
|
223
235
|
#
|
data/lib/discorb/dictionary.rb
CHANGED
data/lib/discorb/embed.rb
CHANGED