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,46 @@
|
|
1
|
+
require "rubycord/events/generic"
|
2
|
+
require "rubycord/await"
|
3
|
+
|
4
|
+
module Rubycord::Events
|
5
|
+
# @see Bot#await
|
6
|
+
class AwaitEvent < Event
|
7
|
+
# The await that was triggered.
|
8
|
+
# @return [Await] The await
|
9
|
+
attr_reader :await
|
10
|
+
|
11
|
+
# The event that triggered the await.
|
12
|
+
# @return [Event] The event
|
13
|
+
attr_reader :event
|
14
|
+
|
15
|
+
# @!attribute [r] key
|
16
|
+
# @return [Symbol] the await's key.
|
17
|
+
# @see Await#key
|
18
|
+
# @!attribute [r] type
|
19
|
+
# @return [Class] the await's event class.
|
20
|
+
# @see Await#type
|
21
|
+
# @!attribute [r] attributes
|
22
|
+
# @return [Hash] a hash of attributes defined on the await.
|
23
|
+
# @see Await#attributes
|
24
|
+
delegate :key, :type, :attributes, to: :await
|
25
|
+
|
26
|
+
# For internal use only
|
27
|
+
def initialize(await, event, bot)
|
28
|
+
@await = await
|
29
|
+
@event = event
|
30
|
+
@bot = bot
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Event handler for {AwaitEvent}
|
35
|
+
class AwaitEventHandler < EventHandler
|
36
|
+
def matches?(event)
|
37
|
+
# Check for the proper event type
|
38
|
+
return false unless event.is_a? AwaitEvent
|
39
|
+
|
40
|
+
[
|
41
|
+
matches_all(@attributes[:key], event.key) { |a, e| a == e },
|
42
|
+
matches_all(@attributes[:type], event.type) { |a, e| a == e }
|
43
|
+
].reduce(true, &:&)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require "rubycord/events/generic"
|
2
|
+
|
3
|
+
module Rubycord::Events
|
4
|
+
# Raised when a user is banned
|
5
|
+
class UserBanEvent < Event
|
6
|
+
# @return [User] the user that was banned
|
7
|
+
attr_reader :user
|
8
|
+
|
9
|
+
# @return [Server] the server from which the user was banned
|
10
|
+
attr_reader :server
|
11
|
+
|
12
|
+
# @!visibility private
|
13
|
+
def initialize(data, bot)
|
14
|
+
@user = bot.user(data["user"]["id"].to_i)
|
15
|
+
@server = bot.server(data["guild_id"].to_i)
|
16
|
+
@bot = bot
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Event handler for {UserBanEvent}
|
21
|
+
class UserBanEventHandler < EventHandler
|
22
|
+
def matches?(event)
|
23
|
+
# Check for the proper event type
|
24
|
+
return false unless event.is_a? UserBanEvent
|
25
|
+
|
26
|
+
[
|
27
|
+
matches_all(@attributes[:user], event.user) do |a, e|
|
28
|
+
case a
|
29
|
+
when String
|
30
|
+
a == e.name
|
31
|
+
when Integer
|
32
|
+
a == e.id
|
33
|
+
when :bot
|
34
|
+
e.current_bot?
|
35
|
+
else
|
36
|
+
a == e
|
37
|
+
end
|
38
|
+
end,
|
39
|
+
matches_all(@attributes[:server], event.server) do |a, e|
|
40
|
+
a == case a
|
41
|
+
when String
|
42
|
+
e.name
|
43
|
+
when Integer
|
44
|
+
e.id
|
45
|
+
else
|
46
|
+
e
|
47
|
+
end
|
48
|
+
end
|
49
|
+
].reduce(true, &:&)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# Raised when a user is unbanned from a server
|
54
|
+
class UserUnbanEvent < UserBanEvent; end
|
55
|
+
|
56
|
+
# Event handler for {UserUnbanEvent}
|
57
|
+
class UserUnbanEventHandler < UserBanEventHandler; end
|
58
|
+
end
|
@@ -0,0 +1,186 @@
|
|
1
|
+
require "rubycord/events/generic"
|
2
|
+
require "rubycord/data"
|
3
|
+
|
4
|
+
module Rubycord::Events
|
5
|
+
# Raised when a channel is created
|
6
|
+
class ChannelCreateEvent < Event
|
7
|
+
# @return [Channel] the channel in question.
|
8
|
+
attr_reader :channel
|
9
|
+
|
10
|
+
# @!attribute [r] type
|
11
|
+
# @return [Integer] the channel's type (0: text, 1: private, 2: voice, 3: group).
|
12
|
+
# @see Channel#type
|
13
|
+
# @!attribute [r] topic
|
14
|
+
# @return [String] the channel's topic.
|
15
|
+
# @see Channel#topic
|
16
|
+
# @!attribute [r] position
|
17
|
+
# @return [Integer] the position of the channel in the channels list.
|
18
|
+
# @see Channel#position
|
19
|
+
# @!attribute [r] name
|
20
|
+
# @return [String] the channel's name
|
21
|
+
# @see Channel#name
|
22
|
+
# @!attribute [r] id
|
23
|
+
# @return [Integer] the channel's unique ID.
|
24
|
+
# @see Channel#id
|
25
|
+
# @!attribute [r] server
|
26
|
+
# @return [Server] the server the channel belongs to.
|
27
|
+
# @see Channel#server
|
28
|
+
delegate :name, :server, :type, :owner_id, :recipients, :topic, :user_limit, :position, :permission_overwrites, to: :channel
|
29
|
+
|
30
|
+
def initialize(data, bot)
|
31
|
+
@bot = bot
|
32
|
+
@channel = data.is_a?(Rubycord::Channel) ? data : bot.channel(data["id"].to_i)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Event handler for ChannelCreateEvent
|
37
|
+
class ChannelCreateEventHandler < EventHandler
|
38
|
+
def matches?(event)
|
39
|
+
# Check for the proper event type
|
40
|
+
return false unless event.is_a? ChannelCreateEvent
|
41
|
+
|
42
|
+
[
|
43
|
+
matches_all(@attributes[:type], event.type) do |a, e|
|
44
|
+
a == if a.is_a? String
|
45
|
+
e.name
|
46
|
+
else
|
47
|
+
e
|
48
|
+
end
|
49
|
+
end,
|
50
|
+
matches_all(@attributes[:name], event.name) do |a, e|
|
51
|
+
a == if a.is_a? String
|
52
|
+
e.to_s
|
53
|
+
else
|
54
|
+
e
|
55
|
+
end
|
56
|
+
end
|
57
|
+
].reduce(true, &:&)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# Raised when a channel is deleted
|
62
|
+
class ChannelDeleteEvent < Event
|
63
|
+
# @return [Integer] the channel's type (0: text, 1: private, 2: voice, 3: group).
|
64
|
+
attr_reader :type
|
65
|
+
|
66
|
+
# @return [String] the channel's topic
|
67
|
+
attr_reader :topic
|
68
|
+
|
69
|
+
# @return [Integer] the position of the channel on the list
|
70
|
+
attr_reader :position
|
71
|
+
|
72
|
+
# @return [String] the channel's name
|
73
|
+
attr_reader :name
|
74
|
+
|
75
|
+
# @return [Integer] the channel's ID
|
76
|
+
attr_reader :id
|
77
|
+
|
78
|
+
# @return [Server] the channel's server
|
79
|
+
attr_reader :server
|
80
|
+
|
81
|
+
# @return [Integer, nil] the channel's owner ID if this is a group channel
|
82
|
+
attr_reader :owner_id
|
83
|
+
|
84
|
+
def initialize(data, bot)
|
85
|
+
@bot = bot
|
86
|
+
|
87
|
+
@type = data["type"]
|
88
|
+
@topic = data["topic"]
|
89
|
+
@position = data["position"]
|
90
|
+
@name = data["name"]
|
91
|
+
@is_private = data["is_private"]
|
92
|
+
@id = data["id"].to_i
|
93
|
+
@server = bot.server(data["guild_id"].to_i) if data["guild_id"]
|
94
|
+
@owner_id = bot.user(data["owner_id"]) if @type == 3
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# Event handler for ChannelDeleteEvent
|
99
|
+
class ChannelDeleteEventHandler < EventHandler
|
100
|
+
def matches?(event)
|
101
|
+
# Check for the proper event type
|
102
|
+
return false unless event.is_a? ChannelDeleteEvent
|
103
|
+
|
104
|
+
[
|
105
|
+
matches_all(@attributes[:type], event.type) do |a, e|
|
106
|
+
a == if a.is_a? String
|
107
|
+
e.name
|
108
|
+
else
|
109
|
+
e
|
110
|
+
end
|
111
|
+
end,
|
112
|
+
matches_all(@attributes[:name], event.name) do |a, e|
|
113
|
+
a == if a.is_a? String
|
114
|
+
e.to_s
|
115
|
+
else
|
116
|
+
e
|
117
|
+
end
|
118
|
+
end
|
119
|
+
].reduce(true, &:&)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
# Generic subclass for recipient events (add/remove)
|
124
|
+
class ChannelRecipientEvent < Event
|
125
|
+
# @return [Channel] the channel in question.
|
126
|
+
attr_reader :channel
|
127
|
+
|
128
|
+
delegate :name, :server, :type, :owner_id, :recipients, :topic, :user_limit, :position, :permission_overwrites, to: :channel
|
129
|
+
|
130
|
+
# @return [Recipient] the recipient that was added/removed from the group
|
131
|
+
attr_reader :recipient
|
132
|
+
|
133
|
+
delegate :id, to: :recipient
|
134
|
+
|
135
|
+
def initialize(data, bot)
|
136
|
+
@bot = bot
|
137
|
+
|
138
|
+
@channel = bot.channel(data["channel_id"].to_i)
|
139
|
+
recipient = data["user"]
|
140
|
+
recipient_user = bot.ensure_user(recipient)
|
141
|
+
@recipient = Rubycord::Recipient.new(recipient_user, @channel, bot)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
# Generic event handler for channel recipient events
|
146
|
+
class ChannelRecipientEventHandler < EventHandler
|
147
|
+
def matches?(event)
|
148
|
+
# Check for the proper event type
|
149
|
+
return false unless event.is_a? ChannelRecipientEvent
|
150
|
+
|
151
|
+
[
|
152
|
+
matches_all(@attributes[:owner_id], event.owner_id) do |a, e|
|
153
|
+
a.resolve_id == e.resolve_id
|
154
|
+
end,
|
155
|
+
matches_all(@attributes[:id], event.id) do |a, e|
|
156
|
+
a.resolve_id == e.resolve_id
|
157
|
+
end,
|
158
|
+
matches_all(@attributes[:name], event.name) do |a, e|
|
159
|
+
a == if a.is_a? String
|
160
|
+
e.to_s
|
161
|
+
else
|
162
|
+
e
|
163
|
+
end
|
164
|
+
end
|
165
|
+
]
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
# Raised when a user is added to a private channel
|
170
|
+
class ChannelRecipientAddEvent < ChannelRecipientEvent; end
|
171
|
+
|
172
|
+
# Event handler for ChannelRecipientAddEvent
|
173
|
+
class ChannelRecipientAddEventHandler < ChannelRecipientEventHandler; end
|
174
|
+
|
175
|
+
# Raised when a recipient that isn't the bot leaves or is kicked from a group channel
|
176
|
+
class ChannelRecipientRemoveEvent < ChannelRecipientEvent; end
|
177
|
+
|
178
|
+
# Event handler for ChannelRecipientRemoveEvent
|
179
|
+
class ChannelRecipientRemoveEventHandler < ChannelRecipientEventHandler; end
|
180
|
+
|
181
|
+
# Raised when a channel is updated (e.g. topic changes)
|
182
|
+
class ChannelUpdateEvent < ChannelCreateEvent; end
|
183
|
+
|
184
|
+
# Event handler for ChannelUpdateEvent
|
185
|
+
class ChannelUpdateEventHandler < ChannelCreateEventHandler; end
|
186
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
# Events used by rubycord
|
2
|
+
module Rubycord::Events
|
3
|
+
# A negated object, used to not match something in event parameters.
|
4
|
+
# @see Rubycord::Events.matches_all
|
5
|
+
class Negated
|
6
|
+
attr_reader :object
|
7
|
+
|
8
|
+
def initialize(object)
|
9
|
+
@object = object
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# Attempts to match possible formats of event attributes to a set comparison value, using a comparison block.
|
14
|
+
# It allows five kinds of attribute formats:
|
15
|
+
# 0. nil -> always returns true
|
16
|
+
# 1. A single attribute, not negated
|
17
|
+
# 2. A single attribute, negated
|
18
|
+
# 3. An array of attributes, not negated
|
19
|
+
# 4. An array of attributes, not negated
|
20
|
+
# Note that it doesn't allow an array of negated attributes. For info on negation stuff, see {::#not!}
|
21
|
+
# @param attributes [Object, Array<Object>, Negated<Object>, Negated<Array<Object>>, nil] One or more attributes to
|
22
|
+
# compare to the to_check value.
|
23
|
+
# @param to_check [Object] What to compare the attributes to.
|
24
|
+
# @yield [a, e] The block will be called when a comparison happens.
|
25
|
+
# @yieldparam [Object] a The attribute to compare to the value to check. Will always be a single not-negated object,
|
26
|
+
# all the negation and array handling is done by the method
|
27
|
+
# @yieldparam [Object] e The value to compare the attribute to. Will always be the value passed to the function as
|
28
|
+
# to_check.
|
29
|
+
# @yieldreturn [true, false] Whether or not the attribute a matches the given comparison value e.
|
30
|
+
# @return [true, false] whether the attributes match the comparison value in at least one way.
|
31
|
+
def self.matches_all(attributes, to_check, &)
|
32
|
+
# "Zeroth" case: attributes is nil
|
33
|
+
return true if attributes.nil?
|
34
|
+
|
35
|
+
# First case: there's a single negated attribute
|
36
|
+
if attributes.is_a? Negated
|
37
|
+
# The contained object might also be an array, so recursively call matches_all (and negate the result)
|
38
|
+
return !matches_all(attributes.object, to_check, &)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Second case: there's a single, not-negated attribute
|
42
|
+
return yield(attributes, to_check) unless attributes.is_a? Array
|
43
|
+
|
44
|
+
# Third case: it's an array of attributes
|
45
|
+
attributes.reduce(false) do |result, element|
|
46
|
+
result || yield(element, to_check)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Generic event class that can be extended
|
51
|
+
class Event
|
52
|
+
# @return [Bot] the bot used to initialize this event.
|
53
|
+
attr_reader :bot
|
54
|
+
|
55
|
+
class << self
|
56
|
+
protected
|
57
|
+
|
58
|
+
# Delegates a list of methods to a particular object. This is essentially a reimplementation of ActiveSupport's
|
59
|
+
# `#delegate`, but without the overhead provided by the rest. Used in subclasses of `Event` to delegate properties
|
60
|
+
# on events to properties on data objects.
|
61
|
+
# @param methods [Array<Symbol>] The methods to delegate.
|
62
|
+
# @param hash [Hash<Symbol => Symbol>] A hash with one `:to` key and the value the method to be delegated to.
|
63
|
+
def delegate(*methods, hash)
|
64
|
+
methods.each do |e|
|
65
|
+
define_method(e) do
|
66
|
+
object = __send__(hash[:to])
|
67
|
+
object.__send__(e)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# Generic event handler that can be extended
|
75
|
+
class EventHandler
|
76
|
+
def initialize(attributes, block)
|
77
|
+
@attributes = attributes
|
78
|
+
@block = block
|
79
|
+
end
|
80
|
+
|
81
|
+
# Whether or not this event handler matches the given event with its attributes.
|
82
|
+
# @raise [RuntimeError] if this method is called - overwrite it in your event handler!
|
83
|
+
def matches?(_)
|
84
|
+
raise "Attempted to call matches?() from a generic EventHandler"
|
85
|
+
end
|
86
|
+
|
87
|
+
# Checks whether this handler matches the given event, and then calls it.
|
88
|
+
# @param event [Object] The event object to match and call the handler with
|
89
|
+
def match(event)
|
90
|
+
call(event) if matches? event
|
91
|
+
end
|
92
|
+
|
93
|
+
# Calls this handler
|
94
|
+
# @param event [Object] The event object to call this handler with
|
95
|
+
def call(event)
|
96
|
+
@block.call(event)
|
97
|
+
end
|
98
|
+
|
99
|
+
# to be overwritten by extending event handlers
|
100
|
+
def after_call(event)
|
101
|
+
end
|
102
|
+
|
103
|
+
# @see Rubycord::Events::matches_all
|
104
|
+
def matches_all(attributes, to_check, &)
|
105
|
+
Rubycord::Events.matches_all(attributes, to_check, &)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
# Event handler that matches all events. Only useful for making an event that has no attributes, such as {ReadyEvent}.
|
110
|
+
class TrueEventHandler < EventHandler
|
111
|
+
# Always returns true.
|
112
|
+
# @return [true]
|
113
|
+
def matches?(_)
|
114
|
+
true
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
# Utility function that creates a negated object for {Rubycord::Events.matches_all}
|
120
|
+
# @param [Object] object The object to negate
|
121
|
+
# @see Rubycord::Events::Negated
|
122
|
+
# @see Rubycord::Events.matches_all
|
123
|
+
# @return [Negated<Object>] the object, negated, as an attribute to pass to matches_all
|
124
|
+
def not!(object)
|
125
|
+
Rubycord::Events::Negated.new(object)
|
126
|
+
end
|
@@ -0,0 +1,191 @@
|
|
1
|
+
require "rubycord/events/generic"
|
2
|
+
require "rubycord/data"
|
3
|
+
|
4
|
+
module Rubycord::Events
|
5
|
+
# Generic subclass for server events (create/update/delete)
|
6
|
+
class ServerEvent < Event
|
7
|
+
# @return [Server] the server in question.
|
8
|
+
attr_reader :server
|
9
|
+
|
10
|
+
def initialize(data, bot)
|
11
|
+
@bot = bot
|
12
|
+
|
13
|
+
init_server(data, bot)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Initializes this event with server data. Should be overwritten in case the server doesn't exist at the time
|
17
|
+
# of event creation (e. g. {ServerDeleteEvent})
|
18
|
+
def init_server(data, bot)
|
19
|
+
@server = bot.server(data["id"].to_i)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Generic event handler for member events
|
24
|
+
class ServerEventHandler < EventHandler
|
25
|
+
def matches?(event)
|
26
|
+
# Check for the proper event type
|
27
|
+
return false unless event.is_a? ServerEvent
|
28
|
+
|
29
|
+
[
|
30
|
+
matches_all(@attributes[:server], event.server) do |a, e|
|
31
|
+
a == case a
|
32
|
+
when String
|
33
|
+
e.name
|
34
|
+
when Integer
|
35
|
+
e.id
|
36
|
+
else
|
37
|
+
e
|
38
|
+
end
|
39
|
+
end
|
40
|
+
].reduce(true, &:&)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Server is created
|
45
|
+
# @see Rubycord::EventContainer#server_create
|
46
|
+
class ServerCreateEvent < ServerEvent; end
|
47
|
+
|
48
|
+
# Event handler for {ServerCreateEvent}
|
49
|
+
class ServerCreateEventHandler < ServerEventHandler; end
|
50
|
+
|
51
|
+
# Server is updated (e.g. name changed)
|
52
|
+
# @see Rubycord::EventContainer#server_update
|
53
|
+
class ServerUpdateEvent < ServerEvent; end
|
54
|
+
|
55
|
+
# Event handler for {ServerUpdateEvent}
|
56
|
+
class ServerUpdateEventHandler < ServerEventHandler; end
|
57
|
+
|
58
|
+
# Server is deleted, the server was left because the bot was kicked, or the
|
59
|
+
# bot made itself leave the server.
|
60
|
+
# @see Rubycord::EventContainer#server_delete
|
61
|
+
class ServerDeleteEvent < ServerEvent
|
62
|
+
# @return [Integer] The ID of the server that was left.
|
63
|
+
attr_reader :server
|
64
|
+
|
65
|
+
# Override init_server to account for the deleted server
|
66
|
+
def init_server(data, _bot)
|
67
|
+
@server = data["id"].to_i
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# Event handler for {ServerDeleteEvent}
|
72
|
+
class ServerDeleteEventHandler < ServerEventHandler; end
|
73
|
+
|
74
|
+
# Emoji is created/deleted/updated
|
75
|
+
class ServerEmojiChangeEvent < ServerEvent
|
76
|
+
# @return [Server] the server in question.
|
77
|
+
attr_reader :server
|
78
|
+
|
79
|
+
# @return [Array<Emoji>] array of emojis.
|
80
|
+
attr_reader :emoji
|
81
|
+
|
82
|
+
def initialize(server, data, bot)
|
83
|
+
@bot = bot
|
84
|
+
@server = server
|
85
|
+
process_emoji(data)
|
86
|
+
end
|
87
|
+
|
88
|
+
# @!visibility private
|
89
|
+
def process_emoji(data)
|
90
|
+
@emoji = data["emojis"].map do |e|
|
91
|
+
@server.emoji[e["id"]]
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# Generic event helper for when an emoji is either created or deleted
|
97
|
+
class ServerEmojiCDEvent < ServerEvent
|
98
|
+
# @return [Server] the server in question.
|
99
|
+
attr_reader :server
|
100
|
+
|
101
|
+
# @return [Emoji] the emoji data.
|
102
|
+
attr_reader :emoji
|
103
|
+
|
104
|
+
def initialize(server, emoji, bot)
|
105
|
+
@bot = bot
|
106
|
+
@emoji = emoji
|
107
|
+
@server = server
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
# Emoji is created
|
112
|
+
class ServerEmojiCreateEvent < ServerEmojiCDEvent; end
|
113
|
+
|
114
|
+
# Emoji is deleted
|
115
|
+
class ServerEmojiDeleteEvent < ServerEmojiCDEvent; end
|
116
|
+
|
117
|
+
# Emoji is updated
|
118
|
+
class ServerEmojiUpdateEvent < ServerEvent
|
119
|
+
# @return [Server] the server in question.
|
120
|
+
attr_reader :server
|
121
|
+
|
122
|
+
# @return [Emoji, nil] the emoji data before the event.
|
123
|
+
attr_reader :old_emoji
|
124
|
+
|
125
|
+
# @return [Emoji, nil] the updated emoji data.
|
126
|
+
attr_reader :emoji
|
127
|
+
|
128
|
+
def initialize(server, old_emoji, emoji, bot)
|
129
|
+
@bot = bot
|
130
|
+
@old_emoji = old_emoji
|
131
|
+
@emoji = emoji
|
132
|
+
@server = server
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
# Event handler for {ServerEmojiChangeEvent}
|
137
|
+
class ServerEmojiChangeEventHandler < ServerEventHandler; end
|
138
|
+
|
139
|
+
# Generic handler for emoji create and delete
|
140
|
+
class ServerEmojiCDEventHandler < ServerEventHandler
|
141
|
+
def matches?(event)
|
142
|
+
# Check for the proper event type
|
143
|
+
return false unless event.is_a? ServerEmojiCDEvent
|
144
|
+
|
145
|
+
[
|
146
|
+
matches_all(@attributes[:server], event.server) do |a, e|
|
147
|
+
a == case a
|
148
|
+
when String
|
149
|
+
e.name
|
150
|
+
when Integer
|
151
|
+
e.id
|
152
|
+
else
|
153
|
+
e
|
154
|
+
end
|
155
|
+
end,
|
156
|
+
matches_all(@attributes[:id], event.emoji.id) { |a, e| a.resolve_id == e.resolve_id },
|
157
|
+
matches_all(@attributes[:name], event.emoji.name) { |a, e| a == e }
|
158
|
+
].reduce(true, &:&)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
# Event handler for {ServerEmojiCreateEvent}
|
163
|
+
class ServerEmojiCreateEventHandler < ServerEmojiCDEventHandler; end
|
164
|
+
|
165
|
+
# Event handler for {ServerEmojiDeleteEvent}
|
166
|
+
class ServerEmojiDeleteEventHandler < ServerEmojiCDEventHandler; end
|
167
|
+
|
168
|
+
# Event handler for {ServerEmojiUpdateEvent}
|
169
|
+
class ServerEmojiUpdateEventHandler < EventHandler
|
170
|
+
def matches?(event)
|
171
|
+
# Check for the proper event type
|
172
|
+
return false unless event.is_a? ServerEmojiUpdateEvent
|
173
|
+
|
174
|
+
[
|
175
|
+
matches_all(@attributes[:server], event.server) do |a, e|
|
176
|
+
a == case a
|
177
|
+
when String
|
178
|
+
e.name
|
179
|
+
when Integer
|
180
|
+
e.id
|
181
|
+
else
|
182
|
+
e
|
183
|
+
end
|
184
|
+
end,
|
185
|
+
matches_all(@attributes[:id], event.old_emoji.id) { |a, e| a.resolve_id == e.resolve_id },
|
186
|
+
matches_all(@attributes[:old_name], event.old_emoji.name) { |a, e| a == e },
|
187
|
+
matches_all(@attributes[:name], event.emoji.name) { |a, e| a == e }
|
188
|
+
].reduce(true, &:&)
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|