discordrb 3.3.0 → 3.5.0
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.
- checksums.yaml +4 -4
- data/.circleci/config.yml +152 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +24 -0
- data/.github/pull_request_template.md +37 -0
- data/.github/workflows/codeql.yml +65 -0
- data/.markdownlint.json +4 -0
- data/.rubocop.yml +39 -36
- data/CHANGELOG.md +874 -552
- data/Gemfile +2 -0
- data/LICENSE.txt +1 -1
- data/README.md +80 -86
- data/Rakefile +2 -0
- data/bin/console +1 -0
- data/discordrb-webhooks.gemspec +9 -6
- data/discordrb.gemspec +21 -18
- data/lib/discordrb/allowed_mentions.rb +36 -0
- data/lib/discordrb/api/application.rb +202 -0
- data/lib/discordrb/api/channel.rb +236 -47
- data/lib/discordrb/api/interaction.rb +54 -0
- data/lib/discordrb/api/invite.rb +5 -5
- data/lib/discordrb/api/server.rb +94 -66
- data/lib/discordrb/api/user.rb +17 -11
- data/lib/discordrb/api/webhook.rb +63 -6
- data/lib/discordrb/api.rb +55 -16
- data/lib/discordrb/await.rb +0 -1
- data/lib/discordrb/bot.rb +480 -93
- data/lib/discordrb/cache.rb +31 -24
- data/lib/discordrb/colour_rgb.rb +43 -0
- data/lib/discordrb/commands/command_bot.rb +35 -12
- data/lib/discordrb/commands/container.rb +21 -24
- data/lib/discordrb/commands/parser.rb +20 -20
- data/lib/discordrb/commands/rate_limiter.rb +4 -3
- data/lib/discordrb/container.rb +209 -20
- data/lib/discordrb/data/activity.rb +271 -0
- data/lib/discordrb/data/application.rb +50 -0
- data/lib/discordrb/data/attachment.rb +71 -0
- data/lib/discordrb/data/audit_logs.rb +345 -0
- data/lib/discordrb/data/channel.rb +993 -0
- data/lib/discordrb/data/component.rb +229 -0
- data/lib/discordrb/data/embed.rb +251 -0
- data/lib/discordrb/data/emoji.rb +82 -0
- data/lib/discordrb/data/integration.rb +122 -0
- data/lib/discordrb/data/interaction.rb +800 -0
- data/lib/discordrb/data/invite.rb +137 -0
- data/lib/discordrb/data/member.rb +372 -0
- data/lib/discordrb/data/message.rb +414 -0
- data/lib/discordrb/data/overwrite.rb +108 -0
- data/lib/discordrb/data/profile.rb +91 -0
- data/lib/discordrb/data/reaction.rb +33 -0
- data/lib/discordrb/data/recipient.rb +34 -0
- data/lib/discordrb/data/role.rb +248 -0
- data/lib/discordrb/data/server.rb +1004 -0
- data/lib/discordrb/data/user.rb +264 -0
- data/lib/discordrb/data/voice_region.rb +45 -0
- data/lib/discordrb/data/voice_state.rb +41 -0
- data/lib/discordrb/data/webhook.rb +238 -0
- data/lib/discordrb/data.rb +28 -4180
- data/lib/discordrb/errors.rb +46 -4
- data/lib/discordrb/events/bans.rb +7 -5
- data/lib/discordrb/events/channels.rb +3 -1
- data/lib/discordrb/events/guilds.rb +16 -9
- data/lib/discordrb/events/interactions.rb +482 -0
- data/lib/discordrb/events/invites.rb +125 -0
- data/lib/discordrb/events/members.rb +6 -2
- data/lib/discordrb/events/message.rb +72 -27
- data/lib/discordrb/events/presence.rb +35 -18
- data/lib/discordrb/events/raw.rb +1 -3
- data/lib/discordrb/events/reactions.rb +49 -4
- data/lib/discordrb/events/threads.rb +96 -0
- data/lib/discordrb/events/typing.rb +6 -4
- data/lib/discordrb/events/voice_server_update.rb +47 -0
- data/lib/discordrb/events/voice_state_update.rb +15 -10
- data/lib/discordrb/events/webhooks.rb +9 -6
- data/lib/discordrb/gateway.rb +99 -71
- data/lib/discordrb/id_object.rb +39 -0
- data/lib/discordrb/light/integrations.rb +1 -1
- data/lib/discordrb/light/light_bot.rb +1 -1
- data/lib/discordrb/logger.rb +4 -4
- data/lib/discordrb/paginator.rb +57 -0
- data/lib/discordrb/permissions.rb +159 -39
- data/lib/discordrb/version.rb +1 -1
- data/lib/discordrb/voice/encoder.rb +16 -7
- data/lib/discordrb/voice/network.rb +99 -47
- data/lib/discordrb/voice/sodium.rb +98 -0
- data/lib/discordrb/voice/voice_bot.rb +33 -25
- data/lib/discordrb/webhooks.rb +2 -0
- data/lib/discordrb.rb +107 -1
- metadata +126 -54
- data/.codeclimate.yml +0 -16
- data/.travis.yml +0 -33
- data/bin/travis_build_docs.sh +0 -17
- /data/{CONTRIBUTING.md → .github/CONTRIBUTING.md} +0 -0
data/lib/discordrb/container.rb
CHANGED
@@ -5,6 +5,7 @@ require 'discordrb/events/typing'
|
|
5
5
|
require 'discordrb/events/lifetime'
|
6
6
|
require 'discordrb/events/presence'
|
7
7
|
require 'discordrb/events/voice_state_update'
|
8
|
+
require 'discordrb/events/voice_server_update'
|
8
9
|
require 'discordrb/events/channels'
|
9
10
|
require 'discordrb/events/members'
|
10
11
|
require 'discordrb/events/roles'
|
@@ -12,6 +13,7 @@ require 'discordrb/events/guilds'
|
|
12
13
|
require 'discordrb/events/await'
|
13
14
|
require 'discordrb/events/bans'
|
14
15
|
require 'discordrb/events/reactions'
|
16
|
+
require 'discordrb/events/interactions'
|
15
17
|
|
16
18
|
require 'discordrb/await'
|
17
19
|
|
@@ -89,7 +91,7 @@ module Discordrb
|
|
89
91
|
|
90
92
|
# This **event** is raised when a message is edited in a channel.
|
91
93
|
# @param attributes [Hash] The event's attributes.
|
92
|
-
# @option attributes [
|
94
|
+
# @option attributes [String, Integer] :id Matches the ID of the message that was edited.
|
93
95
|
# @option attributes [String, Integer, Channel] :in Matches the channel the message was edited in.
|
94
96
|
# @yield The block is executed when the event is raised.
|
95
97
|
# @yieldparam event [MessageEditEvent] The event that was raised.
|
@@ -100,7 +102,7 @@ module Discordrb
|
|
100
102
|
|
101
103
|
# This **event** is raised when a message is deleted in a channel.
|
102
104
|
# @param attributes [Hash] The event's attributes.
|
103
|
-
# @option attributes [
|
105
|
+
# @option attributes [String, Integer] :id Matches the ID of the message that was deleted.
|
104
106
|
# @option attributes [String, Integer, Channel] :in Matches the channel the message was deleted in.
|
105
107
|
# @yield The block is executed when the event is raised.
|
106
108
|
# @yieldparam event [MessageDeleteEvent] The event that was raised.
|
@@ -109,9 +111,26 @@ module Discordrb
|
|
109
111
|
register_event(MessageDeleteEvent, attributes, block)
|
110
112
|
end
|
111
113
|
|
114
|
+
# This **event** is raised whenever a message is updated. Message updates can be triggered from
|
115
|
+
# a user editing their own message, or from Discord automatically attaching embeds to the
|
116
|
+
# user's message for URLs contained in the message's content. If you only want to listen
|
117
|
+
# for users editing their own messages, use the {message_edit} handler instead.
|
118
|
+
# @param attributes [Hash] The event's attributes.
|
119
|
+
# @option attributes [String, Integer] :id Matches the ID of the message that was updated.
|
120
|
+
# @option attributes [String, Integer, Channel] :in Matches the channel the message was updated in.
|
121
|
+
# @yield The block is executed when the event is raised.
|
122
|
+
# @yieldparam event [MessageUpdateEvent] The event that was raised.
|
123
|
+
# @return [MessageUpdateEventHandler] the event handler that was registered.
|
124
|
+
def message_update(attributes = {}, &block)
|
125
|
+
register_event(MessageUpdateEvent, attributes, block)
|
126
|
+
end
|
127
|
+
|
112
128
|
# This **event** is raised when somebody reacts to a message.
|
113
129
|
# @param attributes [Hash] The event's attributes.
|
114
|
-
# @option attributes [
|
130
|
+
# @option attributes [String, Integer] :emoji Matches the ID of the emoji that was reacted with, or its name.
|
131
|
+
# @option attributes [String, Integer, User] :from Matches the user who added the reaction.
|
132
|
+
# @option attributes [String, Integer, Message] :message Matches the message to which the reaction was added.
|
133
|
+
# @option attributes [String, Integer, Channel] :in Matches the channel the reaction was added in.
|
115
134
|
# @yield The block is executed when the event is raised.
|
116
135
|
# @yieldparam event [ReactionAddEvent] The event that was raised.
|
117
136
|
# @return [ReactionAddEventHandler] The event handler that was registered.
|
@@ -121,8 +140,11 @@ module Discordrb
|
|
121
140
|
|
122
141
|
# This **event** is raised when somebody removes a reaction from a message.
|
123
142
|
# @param attributes [Hash] The event's attributes.
|
124
|
-
# @option attributes [
|
143
|
+
# @option attributes [String, Integer] :emoji Matches the ID of the emoji that was removed from the reactions, or
|
125
144
|
# its name.
|
145
|
+
# @option attributes [String, Integer, User] :from Matches the user who removed the reaction.
|
146
|
+
# @option attributes [String, Integer, Message] :message Matches the message to which the reaction was removed.
|
147
|
+
# @option attributes [String, Integer, Channel] :in Matches the channel the reaction was removed in.
|
126
148
|
# @yield The block is executed when the event is raised.
|
127
149
|
# @yieldparam event [ReactionRemoveEvent] The event that was raised.
|
128
150
|
# @return [ReactionRemoveEventHandler] The event handler that was registered.
|
@@ -132,6 +154,9 @@ module Discordrb
|
|
132
154
|
|
133
155
|
# This **event** is raised when somebody removes all reactions from a message.
|
134
156
|
# @param attributes [Hash] The event's attributes.
|
157
|
+
# @option attributes [Hash] The event's attributes.
|
158
|
+
# @option attributes [String, Integer, Message] :message Matches the message to which the reactions were removed.
|
159
|
+
# @option attributes [String, Integer, Channel] :in Matches the channel the reactions were removed in.
|
135
160
|
# @yield The block is executed when the event is raised.
|
136
161
|
# @yieldparam event [ReactionRemoveAllEvent] The event that was raised.
|
137
162
|
# @return [ReactionRemoveAllEventHandler] The event handler that was registered.
|
@@ -143,6 +168,8 @@ module Discordrb
|
|
143
168
|
# @param attributes [Hash] The event's attributes.
|
144
169
|
# @option attributes [String, Integer, User] :from Matches the user whose status changed.
|
145
170
|
# @option attributes [:offline, :idle, :online] :status Matches the status the user has now.
|
171
|
+
# @option attributes [Hash<Symbol, Symbol>] :client_status Matches the current online status (`:online`, `:idle` or `:dnd`) of the user
|
172
|
+
# on various device types (`:desktop`, `:mobile`, or `:web`). The value will be `nil` when the user is offline or invisible
|
146
173
|
# @yield The block is executed when the event is raised.
|
147
174
|
# @yieldparam event [PresenceEvent] The event that was raised.
|
148
175
|
# @return [PresenceEventHandler] the event handler that was registered.
|
@@ -216,8 +243,8 @@ module Discordrb
|
|
216
243
|
# This **event** is raised when a recipient is added to a group channel.
|
217
244
|
# @param attributes [Hash] The event's attributes.
|
218
245
|
# @option attributes [String] :name Matches the name of the group channel that the recipient is added to.
|
219
|
-
# @option attributes [
|
220
|
-
# @option attributes [
|
246
|
+
# @option attributes [String, Integer] :owner_id Matches the ID of the group channel's owner.
|
247
|
+
# @option attributes [String, Integer] :id Matches the ID of the recipient added to the group channel.
|
221
248
|
# @yield The block is executed when the event is raised.
|
222
249
|
# @yieldparam event [ChannelRecipientAddEvent] The event that was raised.
|
223
250
|
# @return [ChannelRecipientAddHandler] the event handler that was registered.
|
@@ -228,8 +255,8 @@ module Discordrb
|
|
228
255
|
# This **event** is raised when a recipient is removed from a group channel.
|
229
256
|
# @param attributes [Hash] The event's attributes.
|
230
257
|
# @option attributes [String] :name Matches the name of the group channel that the recipient is added to.
|
231
|
-
# @option attributes [
|
232
|
-
# @option attributes [
|
258
|
+
# @option attributes [String, Integer] :owner_id Matches the ID of the group channel's owner.
|
259
|
+
# @option attributes [String, Integer] :id Matches the ID of the recipient removed from the group channel.
|
233
260
|
# @yield The block is executed when the event is raised.
|
234
261
|
# @yieldparam event [ChannelRecipientRemoveEvent] The event that was raised.
|
235
262
|
# @return [ChannelRecipientRemoveHandler] the event handler that was registered.
|
@@ -254,6 +281,16 @@ module Discordrb
|
|
254
281
|
register_event(VoiceStateUpdateEvent, attributes, block)
|
255
282
|
end
|
256
283
|
|
284
|
+
# This **event** is raised when first connecting to a server's voice channel.
|
285
|
+
# @param attributes [Hash] The event's attributes.
|
286
|
+
# @option attributes [String, Integer, User] :from Matches the server that the update is for.
|
287
|
+
# @yield The block is executed when the event is raised.
|
288
|
+
# @yieldparam event [VoiceServerUpdateEvent] The event that was raised.
|
289
|
+
# @return [VoiceServerUpdateEventHandler] The event handler that was registered.
|
290
|
+
def voice_server_update(attributes = {}, &block)
|
291
|
+
register_event(VoiceServerUpdateEvent, attributes, block)
|
292
|
+
end
|
293
|
+
|
257
294
|
# This **event** is raised when a new user joins a server.
|
258
295
|
# @param attributes [Hash] The event's attributes.
|
259
296
|
# @option attributes [String] :username Matches the username of the joined user.
|
@@ -352,7 +389,7 @@ module Discordrb
|
|
352
389
|
# This **event** is raised when an emoji is created.
|
353
390
|
# @param attributes [Hash] The event's attributes.
|
354
391
|
# @option attributes [String, Integer, Server] :server Matches the server.
|
355
|
-
# @option attributes [String, Integer] :id Matches the
|
392
|
+
# @option attributes [String, Integer] :id Matches the ID of the emoji.
|
356
393
|
# @option attributes [String] :name Matches the name of the emoji.
|
357
394
|
# @yield The block is executed when the event is raised.
|
358
395
|
# @yieldparam event [ServerEmojiCreateEvent] The event that was raised.
|
@@ -364,7 +401,7 @@ module Discordrb
|
|
364
401
|
# This **event** is raised when an emoji is deleted.
|
365
402
|
# @param attributes [Hash] The event's attributes.
|
366
403
|
# @option attributes [String, Integer, Server] :server Matches the server.
|
367
|
-
# @option attributes [String, Integer] :id Matches the
|
404
|
+
# @option attributes [String, Integer] :id Matches the ID of the emoji.
|
368
405
|
# @option attributes [String] :name Matches the name of the emoji.
|
369
406
|
# @yield The block is executed when the event is raised.
|
370
407
|
# @yieldparam event [ServerEmojiDeleteEvent] The event that was raised.
|
@@ -376,7 +413,7 @@ module Discordrb
|
|
376
413
|
# This **event** is raised when an emoji is updated.
|
377
414
|
# @param attributes [Hash] The event's attributes.
|
378
415
|
# @option attributes [String, Integer, Server] :server Matches the server.
|
379
|
-
# @option attributes [String, Integer] :id Matches the
|
416
|
+
# @option attributes [String, Integer] :id Matches the ID of the emoji.
|
380
417
|
# @option attributes [String] :name Matches the name of the emoji.
|
381
418
|
# @option attributes [String] :old_name Matches the name of the emoji before the update.
|
382
419
|
# @yield The block is executed when the event is raised.
|
@@ -398,7 +435,7 @@ module Discordrb
|
|
398
435
|
|
399
436
|
# This **event** is raised when a role is deleted.
|
400
437
|
# @param attributes [Hash] The event's attributes.
|
401
|
-
# @option attributes [
|
438
|
+
# @option attributes [String, Integer] :id Matches the role ID.
|
402
439
|
# @yield The block is executed when the event is raised.
|
403
440
|
# @yieldparam event [ServerRoleDeleteEvent] The event that was raised.
|
404
441
|
# @return [ServerRoleDeleteEventHandler] the event handler that was registered.
|
@@ -418,9 +455,9 @@ module Discordrb
|
|
418
455
|
|
419
456
|
# This **event** is raised when a webhook is updated.
|
420
457
|
# @param attributes [Hash] The event's attributes.
|
421
|
-
# @option attributes [String, Integer, Server] :server Matches the server by name,
|
422
|
-
# @option attributes [String, Integer, Channel] :channel Matches the channel by name,
|
423
|
-
# @option attribute [String, Integer, Webhook] :webhook Matches the webhook by name,
|
458
|
+
# @option attributes [String, Integer, Server] :server Matches the server by name, ID or instance.
|
459
|
+
# @option attributes [String, Integer, Channel] :channel Matches the channel by name, ID or instance.
|
460
|
+
# @option attribute [String, Integer, Webhook] :webhook Matches the webhook by name, ID or instance.
|
424
461
|
# @yield The block is executed when the event is raised.
|
425
462
|
# @yieldparam event [WebhookUpdateEvent] The event that was raised.
|
426
463
|
# @return [WebhookUpdateEventHandler] the event handler that was registered.
|
@@ -462,6 +499,142 @@ module Discordrb
|
|
462
499
|
alias_method :direct_message, :pm
|
463
500
|
alias_method :dm, :pm
|
464
501
|
|
502
|
+
# This **event** is raised when an invite is created.
|
503
|
+
# @param attributes [Hash] The event's attributes.
|
504
|
+
# @option attributes [String, Integer, User] :inviter Matches the user that created the invite.
|
505
|
+
# @option attributes [String, Integer, Channel] :channel Matches the channel the invite was created for.
|
506
|
+
# @option attributes [String, Integer, Server] :server Matches the server the invite was created for.
|
507
|
+
# @option attributes [true, false] :temporary Matches whether the invite is temporary or not.
|
508
|
+
# @yield The block is executed when the event is raised.
|
509
|
+
# @yieldparam event [InviteCreateEvent] The event that was raised.
|
510
|
+
# @return [InviteCreateEventHandler] The event handler that was registered.
|
511
|
+
def invite_create(attributes = {}, &block)
|
512
|
+
register_event(InviteCreateEvent, attributes, block)
|
513
|
+
end
|
514
|
+
|
515
|
+
# This **event** is raised when an invite is deleted.
|
516
|
+
# @param attributes [Hash] The event's attributes.
|
517
|
+
# @option attributes [String, Integer, Channel] :channel Matches the channel the deleted invite was for.
|
518
|
+
# @option attributes [String, Integer, Server] :server Matches the server the deleted invite was for.
|
519
|
+
# @yield The block is executed when the event is raised
|
520
|
+
# @yieldparam event [InviteDeleteEvent] The event that was raised.
|
521
|
+
# @return [InviteDeleteEventHandler] The event handler that was registered.
|
522
|
+
def invite_delete(attributes = {}, &block)
|
523
|
+
register_event(InviteDeleteEvent, attributes, block)
|
524
|
+
end
|
525
|
+
|
526
|
+
# This **event** is raised whenever an interaction event is received.
|
527
|
+
# @param attributes [Hash] The event's attributes.
|
528
|
+
# @option attributes [Integer, Symbol, String] :type The interaction type, can be the integer value or the name
|
529
|
+
# of the key in {Discordrb::Interaction::TYPES}.
|
530
|
+
# @option attributes [String, Integer, Server, nil] :server The server where this event was created. `nil` for DM channels.
|
531
|
+
# @option attributes [String, Integer, Channel] :channel The channel where this event was created.
|
532
|
+
# @option attributes [String, Integer, User] :user The user that triggered this event.
|
533
|
+
# @yield The block is executed when the event is raised.
|
534
|
+
# @yieldparam event [InteractionCreateEvent] The event that was raised.
|
535
|
+
# @return [InteractionCreateEventHandler] The event handler that was registered.
|
536
|
+
def interaction_create(attributes = {}, &block)
|
537
|
+
register_event(InteractionCreateEvent, attributes, block)
|
538
|
+
end
|
539
|
+
|
540
|
+
# This **event** is raised whenever an application command (slash command) is executed.
|
541
|
+
# @param name [Symbol] The name of the application command this handler is for.
|
542
|
+
# @param attributes [Hash] The event's attributes.
|
543
|
+
# @yield The block is executed when the event is raised.
|
544
|
+
# @yieldparam event [ApplicationCommandEvent] The event that was raised.
|
545
|
+
# @return [ApplicationCommandEventHandler] The event handler that was registered.
|
546
|
+
def application_command(name, attributes = {}, &block)
|
547
|
+
@application_commands ||= {}
|
548
|
+
|
549
|
+
unless block
|
550
|
+
@application_commands[name] ||= ApplicationCommandEventHandler.new(attributes, nil)
|
551
|
+
return @application_commands[name]
|
552
|
+
end
|
553
|
+
|
554
|
+
@application_commands[name] = ApplicationCommandEventHandler.new(attributes, block)
|
555
|
+
end
|
556
|
+
|
557
|
+
# This **event** is raised whenever an button interaction is created.
|
558
|
+
# @param attributes [Hash] The event's attributes.
|
559
|
+
# @option attributes [String, Regexp] :custom_id A custom_id to match against.
|
560
|
+
# @option attributes [String, Integer, Message] :message The message to filter for.
|
561
|
+
# @yield The block is executed when the event is raised.
|
562
|
+
# @yieldparam event [ButtonEvent] The event that was raised.
|
563
|
+
# @return [ButtonEventHandler] The event handler that was registered.
|
564
|
+
def button(attributes = {}, &block)
|
565
|
+
register_event(ButtonEvent, attributes, block)
|
566
|
+
end
|
567
|
+
|
568
|
+
# This **event** is raised whenever an select string interaction is created.
|
569
|
+
# @param attributes [Hash] The event's attributes.
|
570
|
+
# @option attributes [String, Regexp] :custom_id A custom_id to match against.
|
571
|
+
# @option attributes [String, Integer, Message] :message The message to filter for.
|
572
|
+
# @yield The block is executed when the event is raised.
|
573
|
+
# @yieldparam event [StringSelectEvent] The event that was raised.
|
574
|
+
# @return [StringSelectEventHandler] The event handler that was registered.
|
575
|
+
def string_select(attributes = {}, &block)
|
576
|
+
register_event(StringSelectEvent, attributes, block)
|
577
|
+
end
|
578
|
+
|
579
|
+
alias_method :select_menu, :string_select
|
580
|
+
|
581
|
+
# This **event** is raised whenever a modal is submitted.
|
582
|
+
# @param attributes [Hash] The event's attributes.
|
583
|
+
# @option attributes [String, Regexp] :custom_id A custom_id to match against.
|
584
|
+
# @option attributes [String, Integer, Message] :message The message to filter for.
|
585
|
+
# @option attributes [String, Integer, Server, nil] :server The server where this event was created. `nil` for DM channels.
|
586
|
+
# @option attributes [String, Integer, Channel] :channel The channel where this event was created.
|
587
|
+
# @option attributes [String, Integer, User] :user The user that triggered this event. # @yield The block is executed when the event is raised.
|
588
|
+
# @yieldparam event [ModalSubmitEvent] The event that was raised.
|
589
|
+
# @return [ModalSubmitEventHandler] The event handler that was registered.
|
590
|
+
def modal_submit(attributes = {}, &block)
|
591
|
+
register_event(ModalSubmitEvent, attributes, block)
|
592
|
+
end
|
593
|
+
|
594
|
+
# This **event** is raised whenever an select user interaction is created.
|
595
|
+
# @param attributes [Hash] The event's attributes.
|
596
|
+
# @option attributes [String, Regexp] :custom_id A custom_id to match against.
|
597
|
+
# @option attributes [String, Integer, Message] :message The message to filter for.
|
598
|
+
# @yield The block is executed when the event is raised.
|
599
|
+
# @yieldparam event [UserSelectEvent] The event that was raised.
|
600
|
+
# @return [UserSelectEventHandler] The event handler that was registered.
|
601
|
+
def user_select(attributes = {}, &block)
|
602
|
+
register_event(UserSelectEvent, attributes, block)
|
603
|
+
end
|
604
|
+
|
605
|
+
# This **event** is raised whenever an select role interaction is created.
|
606
|
+
# @param attributes [Hash] The event's attributes.
|
607
|
+
# @option attributes [String, Regexp] :custom_id A custom_id to match against.
|
608
|
+
# @option attributes [String, Integer, Message] :message The message to filter for.
|
609
|
+
# @yield The block is executed when the event is raised.
|
610
|
+
# @yieldparam event [RoleSelectEvent] The event that was raised.
|
611
|
+
# @return [RoleSelectEventHandler] The event handler that was registered.
|
612
|
+
def role_select(attributes = {}, &block)
|
613
|
+
register_event(RoleSelectEvent, attributes, block)
|
614
|
+
end
|
615
|
+
|
616
|
+
# This **event** is raised whenever an select mentionable interaction is created.
|
617
|
+
# @param attributes [Hash] The event's attributes.
|
618
|
+
# @option attributes [String, Regexp] :custom_id A custom_id to match against.
|
619
|
+
# @option attributes [String, Integer, Message] :message The message to filter for.
|
620
|
+
# @yield The block is executed when the event is raised.
|
621
|
+
# @yieldparam event [MentionableSelectEvent] The event that was raised.
|
622
|
+
# @return [MentionableSelectEventHandler] The event handler that was registered.
|
623
|
+
def mentionable_select(attributes = {}, &block)
|
624
|
+
register_event(MentionableSelectEvent, attributes, block)
|
625
|
+
end
|
626
|
+
|
627
|
+
# This **event** is raised whenever an select channel interaction is created.
|
628
|
+
# @param attributes [Hash] The event's attributes.
|
629
|
+
# @option attributes [String, Regexp] :custom_id A custom_id to match against.
|
630
|
+
# @option attributes [String, Integer, Message] :message The message to filter for.
|
631
|
+
# @yield The block is executed when the event is raised.
|
632
|
+
# @yieldparam event [ChannelSelectEvent] The event that was raised.
|
633
|
+
# @return [ChannelSelectEventHandler] The event handler that was registered.
|
634
|
+
def channel_select(attributes = {}, &block)
|
635
|
+
register_event(ChannelSelectEvent, attributes, block)
|
636
|
+
end
|
637
|
+
|
465
638
|
# This **event** is raised for every dispatch received over the gateway, whether supported by discordrb or not.
|
466
639
|
# @param attributes [Hash] The event's attributes.
|
467
640
|
# @option attributes [String, Symbol, Regexp] :type Matches the event type of the dispatch.
|
@@ -492,9 +665,16 @@ module Discordrb
|
|
492
665
|
@event_handlers[clazz].delete(handler)
|
493
666
|
end
|
494
667
|
|
668
|
+
# Remove an application command handler
|
669
|
+
# @param name [String, Symbol] The name of the command handler to remove.
|
670
|
+
def remove_application_command_handler(name)
|
671
|
+
@application_commands.delete(name)
|
672
|
+
end
|
673
|
+
|
495
674
|
# Removes all events from this event handler.
|
496
675
|
def clear!
|
497
|
-
@event_handlers
|
676
|
+
@event_handlers&.clear
|
677
|
+
@application_commands&.clear
|
498
678
|
end
|
499
679
|
|
500
680
|
# Adds an event handler to this container. Usually, it's more expressive to just use one of the shorthand adder
|
@@ -510,11 +690,19 @@ module Discordrb
|
|
510
690
|
# Adds all event handlers from another container into this one. Existing event handlers will be overwritten.
|
511
691
|
# @param container [Module] A module that `extend`s {EventContainer} from which the handlers will be added.
|
512
692
|
def include_events(container)
|
513
|
-
|
514
|
-
|
693
|
+
application_command_handlers = container.instance_variable_get(:@application_commands)
|
694
|
+
handlers = container.instance_variable_get :@event_handlers
|
695
|
+
return unless handlers || application_command_handlers
|
515
696
|
|
516
697
|
@event_handlers ||= {}
|
517
|
-
@event_handlers.merge!(handlers) { |_, old, new| old + new }
|
698
|
+
@event_handlers.merge!(handlers || {}) { |_, old, new| old + new }
|
699
|
+
|
700
|
+
@application_commands ||= {}
|
701
|
+
|
702
|
+
@application_commands.merge!(application_command_handlers || {}) do |_, old, new|
|
703
|
+
old.subcommands.merge!(new.subcommands)
|
704
|
+
old
|
705
|
+
end
|
518
706
|
end
|
519
707
|
|
520
708
|
alias_method :include!, :include_events
|
@@ -525,7 +713,7 @@ module Discordrb
|
|
525
713
|
# @param event_class [Class] The event type
|
526
714
|
# @return [Class] the handler type
|
527
715
|
def self.handler_class(event_class)
|
528
|
-
class_from_string(event_class
|
716
|
+
class_from_string("#{event_class}Handler")
|
529
717
|
end
|
530
718
|
|
531
719
|
# Returns the event class for a handler class type
|
@@ -552,6 +740,7 @@ module Discordrb
|
|
552
740
|
|
553
741
|
include Discordrb::Events
|
554
742
|
|
743
|
+
# @return [EventHandler]
|
555
744
|
def register_event(clazz, attributes, block)
|
556
745
|
handler = EventContainer.handler_class(clazz).new(attributes, block)
|
557
746
|
|
@@ -0,0 +1,271 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Discordrb
|
4
|
+
# Contains information about user activities such as the game they are playing,
|
5
|
+
# music they are listening to, or their live stream.
|
6
|
+
class Activity
|
7
|
+
# Values corresponding to the flags bitmask
|
8
|
+
FLAGS = {
|
9
|
+
instance: 1 << 0, # this activity is an instanced game session
|
10
|
+
join: 1 << 1, # this activity is joinable
|
11
|
+
spectate: 1 << 2, # this activity can be spectated
|
12
|
+
join_request: 1 << 3, # this activity allows asking to join
|
13
|
+
sync: 1 << 4, # this activity is a spotify track
|
14
|
+
play: 1 << 5 # this game can be played or opened from discord
|
15
|
+
}.freeze
|
16
|
+
|
17
|
+
# @return [String] the activity's name
|
18
|
+
attr_reader :name
|
19
|
+
|
20
|
+
# @return [Integer, nil] activity type. Can be {GAME}, {STREAMING}, {LISTENING}, {CUSTOM}, or {COMPETING}
|
21
|
+
attr_reader :type
|
22
|
+
|
23
|
+
# @return [String, nil] stream URL, when the activity type is {STREAMING}
|
24
|
+
attr_reader :url
|
25
|
+
|
26
|
+
# @return [String, nil] the application ID for the game
|
27
|
+
attr_reader :application_id
|
28
|
+
|
29
|
+
# @return [String, nil] details about what the player is currently doing
|
30
|
+
attr_reader :details
|
31
|
+
|
32
|
+
# @return [String, nil] the user's current party status
|
33
|
+
attr_reader :state
|
34
|
+
|
35
|
+
# @return [true, false] whether or not the activity is an instanced game session
|
36
|
+
attr_reader :instance
|
37
|
+
|
38
|
+
# @return [Integer] a bitmask of activity flags
|
39
|
+
# @see FLAGS
|
40
|
+
attr_reader :flags
|
41
|
+
|
42
|
+
# @return [Timestamps, nil] times for the start and/or end of the activity
|
43
|
+
attr_reader :timestamps
|
44
|
+
|
45
|
+
# @return [Secrets, nil] secrets for rich presence, joining, and spectating
|
46
|
+
attr_reader :secrets
|
47
|
+
|
48
|
+
# @return [Assets, nil] images for the presence and their texts
|
49
|
+
attr_reader :assets
|
50
|
+
|
51
|
+
# @return [Party, nil] information about the player's current party
|
52
|
+
attr_reader :party
|
53
|
+
|
54
|
+
# @return [Emoji, nil] emoji data for custom statuses
|
55
|
+
attr_reader :emoji
|
56
|
+
|
57
|
+
# @return [Time] the time when the activity was added to the user's session
|
58
|
+
attr_reader :created_at
|
59
|
+
|
60
|
+
# Type indicating the activity is for a game
|
61
|
+
GAME = 0
|
62
|
+
# Type indicating the activity is a stream
|
63
|
+
STREAMING = 1
|
64
|
+
# Type indicating the activity is for music
|
65
|
+
LISTENING = 2
|
66
|
+
# This type is currently unused in the client but can be reported by bots
|
67
|
+
WATCHING = 3
|
68
|
+
# Type indicating the activity is a custom status
|
69
|
+
CUSTOM = 4
|
70
|
+
# Type indicating the activity is for a competitive game
|
71
|
+
COMPETING = 5
|
72
|
+
|
73
|
+
# @!visibility private
|
74
|
+
def initialize(data, bot)
|
75
|
+
@name = data['name']
|
76
|
+
@type = data['type']
|
77
|
+
@url = data['url']
|
78
|
+
@application_id = data['application_id']
|
79
|
+
@details = data['details']
|
80
|
+
@state = data['state']
|
81
|
+
@instance = data['instance']
|
82
|
+
@flags = data['flags'] || 0
|
83
|
+
@created_at = Time.at(data['created_at'].to_i)
|
84
|
+
|
85
|
+
@timestamps = Timestamps.new(data['timestamps']) if data['timestamps']
|
86
|
+
@secrets = Secret.new(data['secrets']) if data['secrets']
|
87
|
+
@assets = Assets.new(data['assets'], @application_id) if data['assets']
|
88
|
+
@party = Party.new(data['party']) if data['party']
|
89
|
+
@emoji = Emoji.new(data['emoji'], bot, nil) if data['emoji']
|
90
|
+
end
|
91
|
+
|
92
|
+
# @return [true, false] Whether or not the `join` flag is set for this activity
|
93
|
+
def join?
|
94
|
+
flag_set? :join
|
95
|
+
end
|
96
|
+
|
97
|
+
# @return [true, false] Whether or not the `spectate` flag is set for this activity
|
98
|
+
def spectate?
|
99
|
+
flag_set? :spectate
|
100
|
+
end
|
101
|
+
|
102
|
+
# @return [true, false] Whether or not the `join_request` flag is set for this activity
|
103
|
+
def join_request?
|
104
|
+
flag_set? :join_request
|
105
|
+
end
|
106
|
+
|
107
|
+
# @return [true, false] Whether or not the `sync` flag is set for this activity
|
108
|
+
def sync?
|
109
|
+
flag_set? :sync
|
110
|
+
end
|
111
|
+
|
112
|
+
# @return [true, false] Whether or not the `play` flag is set for this activity
|
113
|
+
def play?
|
114
|
+
flag_set? :play
|
115
|
+
end
|
116
|
+
|
117
|
+
# @return [true, false] Whether or not the `instance` flag is set for this activity
|
118
|
+
def instance?
|
119
|
+
@instance || flag_set?(:instance)
|
120
|
+
end
|
121
|
+
|
122
|
+
# @!visibility private
|
123
|
+
def flag_set?(sym)
|
124
|
+
!(@flags & FLAGS[sym]).zero?
|
125
|
+
end
|
126
|
+
|
127
|
+
# Timestamps for the start and end of instanced activities
|
128
|
+
class Timestamps
|
129
|
+
# @return [Time, nil]
|
130
|
+
attr_reader :start
|
131
|
+
|
132
|
+
# @return [Time, nil]
|
133
|
+
attr_reader :end
|
134
|
+
|
135
|
+
# @!visibility private
|
136
|
+
def initialize(data)
|
137
|
+
@start = Time.at(data['start'] / 1000) if data['start']
|
138
|
+
@end = Time.at(data['end'] / 1000) if data['end']
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
# Contains secrets used for rich presence
|
143
|
+
class Secrets
|
144
|
+
# @return [String, nil] secret for joining a party
|
145
|
+
attr_reader :join
|
146
|
+
|
147
|
+
# @return [String, nil] secret for spectating
|
148
|
+
attr_reader :spectate
|
149
|
+
|
150
|
+
# @return [String, nil] secret for a specific instanced match
|
151
|
+
attr_reader :match
|
152
|
+
|
153
|
+
# @!visibility private
|
154
|
+
def initialize(data)
|
155
|
+
@join = data['join']
|
156
|
+
@spectate = data['spectate']
|
157
|
+
@match = data['match']
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
# Assets for rich presence images and hover text
|
162
|
+
class Assets
|
163
|
+
# @return [String, nil] the asset ID for the large image of this activity
|
164
|
+
attr_reader :large_image_id
|
165
|
+
|
166
|
+
# @return [String, nil] text displayed when hovering over the large iamge
|
167
|
+
attr_reader :large_text
|
168
|
+
|
169
|
+
# @return [String, nil] the asset ID for the small image of this activity
|
170
|
+
attr_reader :small_image_id
|
171
|
+
|
172
|
+
# @return [String, nil]
|
173
|
+
attr_reader :small_text
|
174
|
+
|
175
|
+
# @return [String, nil] the application ID for these assets.
|
176
|
+
attr_reader :application_id
|
177
|
+
|
178
|
+
# @!visibility private
|
179
|
+
def initialize(data, application_id)
|
180
|
+
@application_id = application_id
|
181
|
+
@large_image_id = data['large_image']
|
182
|
+
@large_text = data['large_text']
|
183
|
+
@small_image_id = data['small_image']
|
184
|
+
@small_text = data['small_text']
|
185
|
+
end
|
186
|
+
|
187
|
+
# Utility function to get an Asset's large image URL.
|
188
|
+
# @param format [String, nil] If `nil`, the URL will default to `webp`. You can otherwise specify one of `webp`, `jpg`, or `png`.
|
189
|
+
# @return [String] the URL to the large image asset.
|
190
|
+
def large_image_url(format = 'webp')
|
191
|
+
API.asset_url(@application_id, @large_image_id, format)
|
192
|
+
end
|
193
|
+
|
194
|
+
# Utility function to get an Asset's large image URL.
|
195
|
+
# @param format [String, nil] If `nil`, the URL will default to `webp`. You can otherwise specify one of `webp`, `jpg`, or `png`.
|
196
|
+
# @return [String] the URL to the small image asset.
|
197
|
+
def small_image_url(format = 'webp')
|
198
|
+
API.asset_url(@application_id, @small_image_id, format)
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
# Contains information about an activity's party
|
203
|
+
class Party
|
204
|
+
# @return [String, nil]
|
205
|
+
attr_reader :id
|
206
|
+
|
207
|
+
# @return [Integer, nil]
|
208
|
+
attr_reader :current_size
|
209
|
+
|
210
|
+
# @return [Integer, nil]
|
211
|
+
attr_reader :max_size
|
212
|
+
|
213
|
+
# @!visibility private
|
214
|
+
def initialize(data)
|
215
|
+
@id = data['id']
|
216
|
+
@current_size, @max_size = data['size']
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
# A collection of the user's activities.
|
222
|
+
class ActivitySet
|
223
|
+
include Enumerable
|
224
|
+
|
225
|
+
# @!visibility private
|
226
|
+
def initialize(activities = [])
|
227
|
+
@activities = activities
|
228
|
+
end
|
229
|
+
|
230
|
+
# @!visibility private
|
231
|
+
# Implement each for Enumerable
|
232
|
+
def each(&block)
|
233
|
+
@activities.each(&block)
|
234
|
+
end
|
235
|
+
|
236
|
+
# @return [Array<Activity>] all activities
|
237
|
+
def to_a
|
238
|
+
@activities
|
239
|
+
end
|
240
|
+
|
241
|
+
# @return [Array<Activity>] all activities of type {Activity::GAME}
|
242
|
+
def games
|
243
|
+
@activities.select { |act| act.type == Activity::GAME }
|
244
|
+
end
|
245
|
+
|
246
|
+
# @return [Array<Activity>] all activities of type {Activity::STREAMING}
|
247
|
+
def streaming
|
248
|
+
@activities.select { |act| act.type == Activity::STREAMING }
|
249
|
+
end
|
250
|
+
|
251
|
+
# @return [Array<Activity>] all activities of type {Activity::LISTENING}
|
252
|
+
def listening
|
253
|
+
@activities.select { |act| act.type == Activity::LISTENING }
|
254
|
+
end
|
255
|
+
|
256
|
+
# @return [Array<Activity>] all activities of type {Activity::WATCHING}
|
257
|
+
def watching
|
258
|
+
@activities.select { |act| act.type == Activity::WATCHING }
|
259
|
+
end
|
260
|
+
|
261
|
+
# @return [Array<Activity>] all activities of type {Activity::CUSTOM}
|
262
|
+
def custom_status
|
263
|
+
@activities.select { |act| act.type == Activity::CUSTOM }
|
264
|
+
end
|
265
|
+
|
266
|
+
# @return [Array<Activity>] all activities of type {Activity::COMPETING}
|
267
|
+
def competing
|
268
|
+
@activities.select { |act| act.type == Activity::COMPETING }
|
269
|
+
end
|
270
|
+
end
|
271
|
+
end
|