rubycord 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/rubycord/allowed_mentions.rb +34 -0
- data/lib/rubycord/api/application.rb +200 -0
- data/lib/rubycord/api/channel.rb +597 -0
- data/lib/rubycord/api/interaction.rb +52 -0
- data/lib/rubycord/api/invite.rb +42 -0
- data/lib/rubycord/api/server.rb +557 -0
- data/lib/rubycord/api/user.rb +153 -0
- data/lib/rubycord/api/webhook.rb +138 -0
- data/lib/rubycord/api.rb +356 -0
- data/lib/rubycord/await.rb +49 -0
- data/lib/rubycord/bot.rb +1757 -0
- data/lib/rubycord/cache.rb +259 -0
- data/lib/rubycord/colour_rgb.rb +41 -0
- data/lib/rubycord/commands/command_bot.rb +519 -0
- data/lib/rubycord/commands/container.rb +110 -0
- data/lib/rubycord/commands/events.rb +9 -0
- data/lib/rubycord/commands/parser.rb +325 -0
- data/lib/rubycord/commands/rate_limiter.rb +142 -0
- data/lib/rubycord/container.rb +753 -0
- data/lib/rubycord/data/activity.rb +269 -0
- data/lib/rubycord/data/application.rb +48 -0
- data/lib/rubycord/data/attachment.rb +109 -0
- data/lib/rubycord/data/audit_logs.rb +343 -0
- data/lib/rubycord/data/channel.rb +996 -0
- data/lib/rubycord/data/component.rb +227 -0
- data/lib/rubycord/data/embed.rb +249 -0
- data/lib/rubycord/data/emoji.rb +80 -0
- data/lib/rubycord/data/integration.rb +120 -0
- data/lib/rubycord/data/interaction.rb +798 -0
- data/lib/rubycord/data/invite.rb +135 -0
- data/lib/rubycord/data/member.rb +370 -0
- data/lib/rubycord/data/message.rb +412 -0
- data/lib/rubycord/data/overwrite.rb +106 -0
- data/lib/rubycord/data/profile.rb +89 -0
- data/lib/rubycord/data/reaction.rb +31 -0
- data/lib/rubycord/data/recipient.rb +32 -0
- data/lib/rubycord/data/role.rb +246 -0
- data/lib/rubycord/data/server.rb +1002 -0
- data/lib/rubycord/data/user.rb +261 -0
- data/lib/rubycord/data/voice_region.rb +43 -0
- data/lib/rubycord/data/voice_state.rb +39 -0
- data/lib/rubycord/data/webhook.rb +232 -0
- data/lib/rubycord/data.rb +40 -0
- data/lib/rubycord/errors.rb +737 -0
- data/lib/rubycord/events/await.rb +46 -0
- data/lib/rubycord/events/bans.rb +58 -0
- data/lib/rubycord/events/channels.rb +186 -0
- data/lib/rubycord/events/generic.rb +126 -0
- data/lib/rubycord/events/guilds.rb +191 -0
- data/lib/rubycord/events/interactions.rb +480 -0
- data/lib/rubycord/events/invites.rb +123 -0
- data/lib/rubycord/events/lifetime.rb +29 -0
- data/lib/rubycord/events/members.rb +91 -0
- data/lib/rubycord/events/message.rb +337 -0
- data/lib/rubycord/events/presence.rb +127 -0
- data/lib/rubycord/events/raw.rb +45 -0
- data/lib/rubycord/events/reactions.rb +156 -0
- data/lib/rubycord/events/roles.rb +86 -0
- data/lib/rubycord/events/threads.rb +94 -0
- data/lib/rubycord/events/typing.rb +70 -0
- data/lib/rubycord/events/voice_server_update.rb +45 -0
- data/lib/rubycord/events/voice_state_update.rb +103 -0
- data/lib/rubycord/events/webhooks.rb +62 -0
- data/lib/rubycord/gateway.rb +867 -0
- data/lib/rubycord/id_object.rb +37 -0
- data/lib/rubycord/light/data.rb +60 -0
- data/lib/rubycord/light/integrations.rb +71 -0
- data/lib/rubycord/light/light_bot.rb +56 -0
- data/lib/rubycord/light.rb +6 -0
- data/lib/rubycord/logger.rb +118 -0
- data/lib/rubycord/paginator.rb +55 -0
- data/lib/rubycord/permissions.rb +251 -0
- data/lib/rubycord/version.rb +5 -0
- data/lib/rubycord/voice/encoder.rb +113 -0
- data/lib/rubycord/voice/network.rb +366 -0
- data/lib/rubycord/voice/sodium.rb +96 -0
- data/lib/rubycord/voice/voice_bot.rb +408 -0
- data/lib/rubycord/webhooks/builder.rb +100 -0
- data/lib/rubycord/webhooks/client.rb +132 -0
- data/lib/rubycord/webhooks/embeds.rb +248 -0
- data/lib/rubycord/webhooks/modal.rb +78 -0
- data/lib/rubycord/webhooks/version.rb +7 -0
- data/lib/rubycord/webhooks/view.rb +192 -0
- data/lib/rubycord/webhooks.rb +12 -0
- data/lib/rubycord/websocket.rb +70 -0
- data/lib/rubycord.rb +140 -0
- metadata +231 -0
@@ -0,0 +1,156 @@
|
|
1
|
+
require "rubycord/events/generic"
|
2
|
+
require "rubycord/data"
|
3
|
+
|
4
|
+
module Rubycord::Events
|
5
|
+
# Generic superclass for events about adding and removing reactions
|
6
|
+
class ReactionEvent < Event
|
7
|
+
include Respondable
|
8
|
+
|
9
|
+
# @return [Emoji] the emoji that was reacted with.
|
10
|
+
attr_reader :emoji
|
11
|
+
|
12
|
+
# @!visibility private
|
13
|
+
attr_reader :message_id
|
14
|
+
|
15
|
+
def initialize(data, bot)
|
16
|
+
@bot = bot
|
17
|
+
|
18
|
+
@emoji = Rubycord::Emoji.new(data["emoji"], bot, nil)
|
19
|
+
@user_id = data["user_id"].to_i
|
20
|
+
@message_id = data["message_id"].to_i
|
21
|
+
@channel_id = data["channel_id"].to_i
|
22
|
+
end
|
23
|
+
|
24
|
+
# @return [User, Member] the user that reacted to this message, or member if a server exists.
|
25
|
+
def user
|
26
|
+
# Cache the user so we don't do requests all the time
|
27
|
+
@user ||= if server
|
28
|
+
@server.member(@user_id)
|
29
|
+
else
|
30
|
+
@bot.user(@user_id)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# @return [Message] the message that was reacted to.
|
35
|
+
def message
|
36
|
+
@message ||= channel.load_message(@message_id)
|
37
|
+
end
|
38
|
+
|
39
|
+
# @return [Channel] the channel that was reacted in.
|
40
|
+
def channel
|
41
|
+
@channel ||= @bot.channel(@channel_id)
|
42
|
+
end
|
43
|
+
|
44
|
+
# @return [Server, nil] the server that was reacted in. If reacted in a PM channel, it will be nil.
|
45
|
+
def server
|
46
|
+
@server ||= channel.server
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Generic superclass for event handlers pertaining to adding and removing reactions
|
51
|
+
class ReactionEventHandler < EventHandler
|
52
|
+
def matches?(event)
|
53
|
+
# Check for the proper event type
|
54
|
+
return false unless event.is_a? ReactionEvent
|
55
|
+
|
56
|
+
[
|
57
|
+
matches_all(@attributes[:emoji], event.emoji) do |a, e|
|
58
|
+
case a
|
59
|
+
when Integer
|
60
|
+
e.id == a
|
61
|
+
when String
|
62
|
+
e.name == a || e.name == a.delete(":") || e.id == a.resolve_id
|
63
|
+
else
|
64
|
+
e == a
|
65
|
+
end
|
66
|
+
end,
|
67
|
+
matches_all(@attributes[:message], event.message_id) do |a, e|
|
68
|
+
a == e
|
69
|
+
end,
|
70
|
+
matches_all(@attributes[:in], event.channel) do |a, e|
|
71
|
+
case a
|
72
|
+
when String
|
73
|
+
# Make sure to remove the "#" from channel names in case it was specified
|
74
|
+
a.delete("#") == e.name
|
75
|
+
when Integer
|
76
|
+
a == e.id
|
77
|
+
else
|
78
|
+
a == e
|
79
|
+
end
|
80
|
+
end,
|
81
|
+
matches_all(@attributes[:from], event.user) do |a, e|
|
82
|
+
case a
|
83
|
+
when String
|
84
|
+
a == e.name
|
85
|
+
when :bot
|
86
|
+
e.current_bot?
|
87
|
+
else
|
88
|
+
a == e
|
89
|
+
end
|
90
|
+
end
|
91
|
+
].reduce(true, &:&)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
# Event raised when somebody reacts to a message
|
96
|
+
class ReactionAddEvent < ReactionEvent; end
|
97
|
+
|
98
|
+
# Event handler for {ReactionAddEvent}
|
99
|
+
class ReactionAddEventHandler < ReactionEventHandler; end
|
100
|
+
|
101
|
+
# Event raised when somebody removes a reaction to a message
|
102
|
+
class ReactionRemoveEvent < ReactionEvent; end
|
103
|
+
|
104
|
+
# Event handler for {ReactionRemoveEvent}
|
105
|
+
class ReactionRemoveEventHandler < ReactionEventHandler; end
|
106
|
+
|
107
|
+
# Event raised when somebody removes all reactions from a message
|
108
|
+
class ReactionRemoveAllEvent < Event
|
109
|
+
include Respondable
|
110
|
+
|
111
|
+
# @!visibility private
|
112
|
+
attr_reader :message_id
|
113
|
+
|
114
|
+
def initialize(data, bot)
|
115
|
+
@bot = bot
|
116
|
+
|
117
|
+
@message_id = data["message_id"].to_i
|
118
|
+
@channel_id = data["channel_id"].to_i
|
119
|
+
end
|
120
|
+
|
121
|
+
# @return [Channel] the channel where the removal occurred.
|
122
|
+
def channel
|
123
|
+
@channel ||= @bot.channel(@channel_id)
|
124
|
+
end
|
125
|
+
|
126
|
+
# @return [Message] the message all reactions were removed from.
|
127
|
+
def message
|
128
|
+
@message ||= channel.load_message(@message_id)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
# Event handler for {ReactionRemoveAllEvent}
|
133
|
+
class ReactionRemoveAllEventHandler < EventHandler
|
134
|
+
def matches?(event)
|
135
|
+
# Check for the proper event type
|
136
|
+
return false unless event.is_a? ReactionRemoveAllEvent
|
137
|
+
|
138
|
+
[
|
139
|
+
matches_all(@attributes[:message], event.message_id) do |a, e|
|
140
|
+
a == e
|
141
|
+
end,
|
142
|
+
matches_all(@attributes[:in], event.channel) do |a, e|
|
143
|
+
case a
|
144
|
+
when String
|
145
|
+
# Make sure to remove the "#" from channel names in case it was specified
|
146
|
+
a.delete("#") == e.name
|
147
|
+
when Integer
|
148
|
+
a == e.id
|
149
|
+
else
|
150
|
+
a == e
|
151
|
+
end
|
152
|
+
end
|
153
|
+
].reduce(true, &:&)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require "rubycord/events/generic"
|
2
|
+
require "rubycord/data"
|
3
|
+
|
4
|
+
module Rubycord::Events
|
5
|
+
# Raised when a role is created on a server
|
6
|
+
class ServerRoleCreateEvent < Event
|
7
|
+
# @return [Role] the role that got created
|
8
|
+
attr_reader :role
|
9
|
+
|
10
|
+
# @return [Server] the server on which a role got created
|
11
|
+
attr_reader :server
|
12
|
+
|
13
|
+
# @!attribute [r] name
|
14
|
+
# @return [String] this role's name
|
15
|
+
# @see Role#name
|
16
|
+
delegate :name, to: :role
|
17
|
+
|
18
|
+
def initialize(data, bot)
|
19
|
+
@bot = bot
|
20
|
+
|
21
|
+
@server = bot.server(data["guild_id"].to_i)
|
22
|
+
return unless @server
|
23
|
+
|
24
|
+
role_id = data["role"]["id"].to_i
|
25
|
+
@role = @server.roles.find { |r| r.id == role_id }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Event handler for ServerRoleCreateEvent
|
30
|
+
class ServerRoleCreateEventHandler < EventHandler
|
31
|
+
def matches?(event)
|
32
|
+
# Check for the proper event type
|
33
|
+
return false unless event.is_a? ServerRoleCreateEvent
|
34
|
+
|
35
|
+
[
|
36
|
+
matches_all(@attributes[:name], event.name) do |a, e|
|
37
|
+
a == if a.is_a? String
|
38
|
+
e.to_s
|
39
|
+
else
|
40
|
+
e
|
41
|
+
end
|
42
|
+
end
|
43
|
+
].reduce(true, &:&)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Raised when a role is deleted from a server
|
48
|
+
class ServerRoleDeleteEvent < Event
|
49
|
+
# @return [Integer] the ID of the role that got deleted.
|
50
|
+
attr_reader :id
|
51
|
+
|
52
|
+
# @return [Server] the server on which a role got deleted.
|
53
|
+
attr_reader :server
|
54
|
+
|
55
|
+
def initialize(data, bot)
|
56
|
+
@bot = bot
|
57
|
+
|
58
|
+
# The role should already be deleted from the server's list
|
59
|
+
# by the time we create this event, so we'll create a temporary
|
60
|
+
# role object for event consumers to use.
|
61
|
+
@id = data["role_id"].to_i
|
62
|
+
server_id = data["guild_id"].to_i
|
63
|
+
@server = bot.server(server_id)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# EventHandler for ServerRoleDeleteEvent
|
68
|
+
class ServerRoleDeleteEventHandler < EventHandler
|
69
|
+
def matches?(event)
|
70
|
+
# Check for the proper event type
|
71
|
+
return false unless event.is_a? ServerRoleDeleteEvent
|
72
|
+
|
73
|
+
[
|
74
|
+
matches_all(@attributes[:id], event.id) do |a, e|
|
75
|
+
a.resolve_id == e.resolve_id
|
76
|
+
end
|
77
|
+
].reduce(true, &:&)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# Event raised when a role updates on a server
|
82
|
+
class ServerRoleUpdateEvent < ServerRoleCreateEvent; end
|
83
|
+
|
84
|
+
# Event handler for ServerRoleUpdateEvent
|
85
|
+
class ServerRoleUpdateEventHandler < ServerRoleCreateEventHandler; end
|
86
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
module Rubycord::Events
|
2
|
+
# Raised when a thread is created
|
3
|
+
class ThreadCreateEvent < Event
|
4
|
+
# @return [Channel] the thread in question.
|
5
|
+
attr_reader :thread
|
6
|
+
|
7
|
+
delegate :name, :server, :owner, :parent_channel, :thread_metadata, to: :thread
|
8
|
+
|
9
|
+
def initialize(data, bot)
|
10
|
+
@bot = bot
|
11
|
+
@thread = data.is_a?(Rubycord::Channel) ? data : bot.channel(data["id"].to_i)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# Event handler for ChannelCreateEvent
|
16
|
+
class ThreadCreateEventHandler < EventHandler
|
17
|
+
def matches?(event)
|
18
|
+
# Check for the proper event type
|
19
|
+
return false unless event.is_a? ThreadCreateEvent
|
20
|
+
|
21
|
+
[
|
22
|
+
matches_all(@attributes[:name], event.name) do |a, e|
|
23
|
+
a == if a.is_a? String
|
24
|
+
e.to_s
|
25
|
+
else
|
26
|
+
e
|
27
|
+
end
|
28
|
+
end,
|
29
|
+
matches_all(@attributes[:server], event.server) do |a, e|
|
30
|
+
a.resolve_id == e.resolve_id
|
31
|
+
end,
|
32
|
+
matches_all(@attributes[:invitable], event.thread.invitable) do |a, e|
|
33
|
+
a == e
|
34
|
+
end,
|
35
|
+
matches_all(@attributes[:owner], event.thread.owner) do |a, e|
|
36
|
+
a.resolve_id == e.resolve_id
|
37
|
+
end,
|
38
|
+
matches_all(@attributes[:channel], event.thread.parent) do |a, e|
|
39
|
+
a.resolve_id == e.resolve_id
|
40
|
+
end
|
41
|
+
].reduce(true, &:&)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# Raised when a thread is updated (e.g. name changes)
|
46
|
+
class ThreadUpdateEvent < ThreadCreateEvent; end
|
47
|
+
|
48
|
+
# Event handler for ThreadUpdateEvent
|
49
|
+
class ThreadUpdateEventHandler < ThreadCreateEventHandler
|
50
|
+
def matches?(event)
|
51
|
+
# Check for the proper event type
|
52
|
+
return false unless event.is_a? ThreadUpdateEvent
|
53
|
+
|
54
|
+
super
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# Raised when members are added or removed from a thread.
|
59
|
+
class ThreadMembersUpdateEvent < Event
|
60
|
+
# @return [Channel]
|
61
|
+
attr_reader :thread
|
62
|
+
|
63
|
+
# @return [Array<Member, User>]
|
64
|
+
attr_reader :added_members
|
65
|
+
|
66
|
+
# @return [Array<Integer>]
|
67
|
+
attr_reader :removed_member_ids
|
68
|
+
|
69
|
+
# @return [Integer]
|
70
|
+
attr_reader :member_count
|
71
|
+
|
72
|
+
delegate :name, :server, :owner, :parent_channel, :thread_metadata, to: :thread
|
73
|
+
|
74
|
+
def initialize(data, bot)
|
75
|
+
@bot = bot
|
76
|
+
@thread = data.is_a?(Rubycord::Channel) ? data : bot.channel(data["id"].to_i)
|
77
|
+
@added_members = data["added_members"]&.map do |member|
|
78
|
+
data["guild_id"] ? bot.member(data["guild_id"], member["user_id"]) : bot.user(member["user_id"])
|
79
|
+
end || []
|
80
|
+
@removed_member_ids = data["removed_member_ids"]&.map(&:resolve_id) || []
|
81
|
+
@member_count = data["member_count"]
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# Event handler for ThreadMembersUpdateEvent
|
86
|
+
class ThreadMembersUpdateEventHandler < ThreadCreateEventHandler
|
87
|
+
def matches?(event)
|
88
|
+
# Check for the proper event type
|
89
|
+
return false unless event.is_a? ThreadMembersUpdateEvent
|
90
|
+
|
91
|
+
super
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require "rubycord/events/generic"
|
2
|
+
|
3
|
+
module Rubycord::Events
|
4
|
+
# Event raised when a user starts typing
|
5
|
+
class TypingEvent < Event
|
6
|
+
include Respondable
|
7
|
+
|
8
|
+
# @return [Channel] the channel on which a user started typing.
|
9
|
+
attr_reader :channel
|
10
|
+
|
11
|
+
# @return [User, Member, Recipient] the user that started typing.
|
12
|
+
attr_reader :user
|
13
|
+
alias_method :member, :user
|
14
|
+
|
15
|
+
# @return [Time] when the typing happened.
|
16
|
+
attr_reader :timestamp
|
17
|
+
|
18
|
+
def initialize(data, bot)
|
19
|
+
@bot = bot
|
20
|
+
|
21
|
+
@user_id = data["user_id"].to_i
|
22
|
+
|
23
|
+
@channel_id = data["channel_id"].to_i
|
24
|
+
@channel = bot.channel(@channel_id)
|
25
|
+
|
26
|
+
@user = if channel.pm?
|
27
|
+
channel.recipient
|
28
|
+
elsif channel.group?
|
29
|
+
bot.user(@user_id)
|
30
|
+
else
|
31
|
+
bot.member(@channel.server.id, @user_id)
|
32
|
+
end
|
33
|
+
|
34
|
+
@timestamp = Time.at(data["timestamp"].to_i)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Event handler for TypingEvent
|
39
|
+
class TypingEventHandler < EventHandler
|
40
|
+
def matches?(event)
|
41
|
+
# Check for the proper event type
|
42
|
+
return false unless event.is_a? TypingEvent
|
43
|
+
|
44
|
+
[
|
45
|
+
matches_all(@attributes[:in], event.channel) do |a, e|
|
46
|
+
case a
|
47
|
+
when String
|
48
|
+
a.delete("#") == e.name
|
49
|
+
when Integer
|
50
|
+
a == e.id
|
51
|
+
else
|
52
|
+
a == e
|
53
|
+
end
|
54
|
+
end,
|
55
|
+
matches_all(@attributes[:from], event.user) do |a, e|
|
56
|
+
a == case a
|
57
|
+
when String
|
58
|
+
e.name
|
59
|
+
when Integer
|
60
|
+
e.id
|
61
|
+
else
|
62
|
+
e
|
63
|
+
end
|
64
|
+
end,
|
65
|
+
matches_all(@attributes[:after], event.timestamp) { |a, e| a > e },
|
66
|
+
matches_all(@attributes[:before], event.timestamp) { |a, e| a < e }
|
67
|
+
].reduce(true, &:&)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "rubycord/events/generic"
|
2
|
+
require "rubycord/data"
|
3
|
+
|
4
|
+
module Rubycord::Events
|
5
|
+
# Event raised when a server's voice server is updating.
|
6
|
+
# Sent when initially connecting to voice and when a voice instance fails
|
7
|
+
# over to a new server.
|
8
|
+
# This event is exposed for use with library agnostic interfaces like telecom and
|
9
|
+
# lavalink.
|
10
|
+
class VoiceServerUpdateEvent < Event
|
11
|
+
# @return [String] The voice connection token
|
12
|
+
attr_reader :token
|
13
|
+
|
14
|
+
# @return [Server] The server this update is for.
|
15
|
+
attr_reader :server
|
16
|
+
|
17
|
+
# @return [String] The voice server host.
|
18
|
+
attr_reader :endpoint
|
19
|
+
|
20
|
+
def initialize(data, bot)
|
21
|
+
@bot = bot
|
22
|
+
|
23
|
+
@token = data["token"]
|
24
|
+
@endpoint = data["endpoint"]
|
25
|
+
@server = bot.server(data["guild_id"])
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Event handler for VoiceServerUpdateEvent
|
30
|
+
class VoiceServerUpdateEventHandler < EventHandler
|
31
|
+
def matches?(event)
|
32
|
+
return false unless event.is_a? VoiceServerUpdateEvent
|
33
|
+
|
34
|
+
[
|
35
|
+
matches_all(@attributes[:from], event.server) do |a, e|
|
36
|
+
a == if a.is_a? String
|
37
|
+
e.name
|
38
|
+
else
|
39
|
+
e
|
40
|
+
end
|
41
|
+
end
|
42
|
+
]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require "rubycord/events/generic"
|
2
|
+
require "rubycord/data"
|
3
|
+
|
4
|
+
module Rubycord::Events
|
5
|
+
# Event raised when a user's voice state updates
|
6
|
+
class VoiceStateUpdateEvent < Event
|
7
|
+
attr_reader :user, :token, :suppress, :session_id, :self_mute, :self_deaf, :mute, :deaf, :server, :channel
|
8
|
+
|
9
|
+
# @return [Channel, nil] the old channel this user was on, or nil if the user is newly joining voice.
|
10
|
+
attr_reader :old_channel
|
11
|
+
|
12
|
+
def initialize(data, old_channel_id, bot)
|
13
|
+
@bot = bot
|
14
|
+
|
15
|
+
@token = data["token"]
|
16
|
+
@suppress = data["suppress"]
|
17
|
+
@session_id = data["session_id"]
|
18
|
+
@self_mute = data["self_mute"]
|
19
|
+
@self_deaf = data["self_deaf"]
|
20
|
+
@mute = data["mute"]
|
21
|
+
@deaf = data["deaf"]
|
22
|
+
@server = bot.server(data["guild_id"].to_i)
|
23
|
+
return unless @server
|
24
|
+
|
25
|
+
@channel = bot.channel(data["channel_id"].to_i) if data["channel_id"]
|
26
|
+
@old_channel = bot.channel(old_channel_id) if old_channel_id
|
27
|
+
@user = bot.user(data["user_id"].to_i)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Event handler for VoiceStateUpdateEvent
|
32
|
+
class VoiceStateUpdateEventHandler < EventHandler
|
33
|
+
def matches?(event)
|
34
|
+
# Check for the proper event type
|
35
|
+
return false unless event.is_a? VoiceStateUpdateEvent
|
36
|
+
|
37
|
+
[
|
38
|
+
matches_all(@attributes[:from], event.user) do |a, e|
|
39
|
+
a == case a
|
40
|
+
when String
|
41
|
+
e.name
|
42
|
+
when Integer
|
43
|
+
e.id
|
44
|
+
else
|
45
|
+
e
|
46
|
+
end
|
47
|
+
end,
|
48
|
+
matches_all(@attributes[:mute], event.mute) do |a, e|
|
49
|
+
a == if a.is_a? String
|
50
|
+
e.to_s
|
51
|
+
else
|
52
|
+
e
|
53
|
+
end
|
54
|
+
end,
|
55
|
+
matches_all(@attributes[:deaf], event.deaf) do |a, e|
|
56
|
+
a == if a.is_a? String
|
57
|
+
e.to_s
|
58
|
+
else
|
59
|
+
e
|
60
|
+
end
|
61
|
+
end,
|
62
|
+
matches_all(@attributes[:self_mute], event.self_mute) do |a, e|
|
63
|
+
a == if a.is_a? String
|
64
|
+
e.to_s
|
65
|
+
else
|
66
|
+
e
|
67
|
+
end
|
68
|
+
end,
|
69
|
+
matches_all(@attributes[:self_deaf], event.self_deaf) do |a, e|
|
70
|
+
a == if a.is_a? String
|
71
|
+
e.to_s
|
72
|
+
else
|
73
|
+
e
|
74
|
+
end
|
75
|
+
end,
|
76
|
+
matches_all(@attributes[:channel], event.channel) do |a, e|
|
77
|
+
next unless e # Don't bother if the channel is nil
|
78
|
+
|
79
|
+
a == case a
|
80
|
+
when String
|
81
|
+
e.name
|
82
|
+
when Integer
|
83
|
+
e.id
|
84
|
+
else
|
85
|
+
e
|
86
|
+
end
|
87
|
+
end,
|
88
|
+
matches_all(@attributes[:old_channel], event.old_channel) do |a, e|
|
89
|
+
next unless e # Don't bother if the channel is nil
|
90
|
+
|
91
|
+
a == case a
|
92
|
+
when String
|
93
|
+
e.name
|
94
|
+
when Integer
|
95
|
+
e.id
|
96
|
+
else
|
97
|
+
e
|
98
|
+
end
|
99
|
+
end
|
100
|
+
].reduce(true, &:&)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require "rubycord/events/generic"
|
2
|
+
require "rubycord/data"
|
3
|
+
|
4
|
+
module Rubycord::Events
|
5
|
+
# Event raised when a webhook is updated
|
6
|
+
class WebhookUpdateEvent < Event
|
7
|
+
# @return [Server] the server where the webhook updated
|
8
|
+
attr_reader :server
|
9
|
+
|
10
|
+
# @return [Channel] the channel the webhook is associated to
|
11
|
+
attr_reader :channel
|
12
|
+
|
13
|
+
def initialize(data, bot)
|
14
|
+
@bot = bot
|
15
|
+
|
16
|
+
@server = bot.server(data["guild_id"].to_i)
|
17
|
+
@channel = bot.channel(data["channel_id"].to_i)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# Event handler for {WebhookUpdateEvent}
|
22
|
+
class WebhookUpdateEventHandler < EventHandler
|
23
|
+
def matches?(event)
|
24
|
+
# Check for the proper event type
|
25
|
+
return false unless event.is_a? WebhookUpdateEvent
|
26
|
+
|
27
|
+
[
|
28
|
+
matches_all(@attributes[:server], event.server) do |a, e|
|
29
|
+
a == case a
|
30
|
+
when String
|
31
|
+
e.name
|
32
|
+
when Integer
|
33
|
+
e.id
|
34
|
+
else
|
35
|
+
e
|
36
|
+
end
|
37
|
+
end,
|
38
|
+
matches_all(@attributes[:channel], event.channel) do |a, e|
|
39
|
+
case a
|
40
|
+
when String
|
41
|
+
# Make sure to remove the "#" from channel names in case it was specified
|
42
|
+
a.delete("#") == e.name
|
43
|
+
when Integer
|
44
|
+
a == e.id
|
45
|
+
else
|
46
|
+
a == e
|
47
|
+
end
|
48
|
+
end,
|
49
|
+
matches_all(@attributes[:webhook], event) do |a, e|
|
50
|
+
a == case a
|
51
|
+
when String
|
52
|
+
e.name
|
53
|
+
when Integer
|
54
|
+
e.id
|
55
|
+
else
|
56
|
+
e
|
57
|
+
end
|
58
|
+
end
|
59
|
+
].reduce(true, &:&)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|