discordrb 1.1.3 → 1.2.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.
Potentially problematic release.
This version of discordrb might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.gitignore +9 -9
- data/.travis.yml +4 -4
- data/Gemfile +4 -4
- data/LICENSE.txt +21 -21
- data/README.md +78 -78
- data/Rakefile +4 -4
- data/bin/console +14 -14
- data/bin/setup +7 -7
- data/discordrb.gemspec +28 -28
- data/examples/ping.rb +11 -11
- data/examples/pm.rb +11 -11
- data/lib/discordrb.rb +6 -6
- data/lib/discordrb/bot.rb +525 -342
- data/lib/discordrb/data.rb +391 -140
- data/lib/discordrb/endpoints/endpoints.rb +16 -16
- data/lib/discordrb/events/channel-create.rb +48 -0
- data/lib/discordrb/events/channel-delete.rb +48 -0
- data/lib/discordrb/events/channel-update.rb +49 -0
- data/lib/discordrb/events/generic.rb +59 -59
- data/lib/discordrb/events/guild-member-update.rb +40 -0
- data/lib/discordrb/events/guild-role-create.rb +34 -0
- data/lib/discordrb/events/guild-role-delete.rb +35 -0
- data/lib/discordrb/events/guild-role-update.rb +34 -0
- data/lib/discordrb/events/lifetime.rb +9 -9
- data/lib/discordrb/events/message.rb +59 -59
- data/lib/discordrb/events/presence.rb +40 -40
- data/lib/discordrb/events/typing.rb +45 -45
- data/lib/discordrb/events/voice-state-update.rb +89 -0
- data/lib/discordrb/exceptions.rb +10 -10
- data/lib/discordrb/version.rb +3 -3
- metadata +10 -2
@@ -1,16 +1,16 @@
|
|
1
|
-
module Discordrb::Endpoints
|
2
|
-
BASE = "https://discordapp.com/"
|
3
|
-
APIBASE = BASE + "api"
|
4
|
-
|
5
|
-
#WEBSOCKET_HUB = "wss://discordapp.com/hub"
|
6
|
-
GATEWAY = APIBASE + "/gateway"
|
7
|
-
|
8
|
-
LOGIN = APIBASE + "/auth/login"
|
9
|
-
LOGOUT = APIBASE + "/auth/logout"
|
10
|
-
|
11
|
-
SERVERS = APIBASE + "/guilds"
|
12
|
-
|
13
|
-
CHANNELS = APIBASE + "/channels"
|
14
|
-
|
15
|
-
USERS = APIBASE + "/users"
|
16
|
-
end
|
1
|
+
module Discordrb::Endpoints
|
2
|
+
BASE = "https://discordapp.com/"
|
3
|
+
APIBASE = BASE + "api"
|
4
|
+
|
5
|
+
#WEBSOCKET_HUB = "wss://discordapp.com/hub"
|
6
|
+
GATEWAY = APIBASE + "/gateway"
|
7
|
+
|
8
|
+
LOGIN = APIBASE + "/auth/login"
|
9
|
+
LOGOUT = APIBASE + "/auth/logout"
|
10
|
+
|
11
|
+
SERVERS = APIBASE + "/guilds"
|
12
|
+
|
13
|
+
CHANNELS = APIBASE + "/channels"
|
14
|
+
|
15
|
+
USERS = APIBASE + "/users"
|
16
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'discordrb/events/generic'
|
2
|
+
require 'discordrb/data'
|
3
|
+
|
4
|
+
module Discordrb::Events
|
5
|
+
class ChannelCreateEvent
|
6
|
+
attr_reader :type
|
7
|
+
attr_reader :topic
|
8
|
+
attr_reader :position
|
9
|
+
attr_reader :name
|
10
|
+
attr_reader :is_private
|
11
|
+
attr_reader :id
|
12
|
+
attr_reader :server
|
13
|
+
|
14
|
+
def initialize(data, bot)
|
15
|
+
@type = data['type']
|
16
|
+
@topic = data['topic']
|
17
|
+
@position = data['position']
|
18
|
+
@name = data['name']
|
19
|
+
@is_private = data['is_private']
|
20
|
+
@id = data['id']
|
21
|
+
@server = bot.server(data['guild_id'].to_i)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class ChannelCreateEventHandler < EventHandler
|
26
|
+
def matches?(event)
|
27
|
+
# Check for the proper event type
|
28
|
+
return false unless event.is_a? ChannelCreateEvent
|
29
|
+
|
30
|
+
return [
|
31
|
+
matches_all(@attributes[:type], event.type) do |a,e|
|
32
|
+
if a.is_a? String
|
33
|
+
a == e.name
|
34
|
+
else
|
35
|
+
a == e
|
36
|
+
end
|
37
|
+
end,
|
38
|
+
matches_all(@attributes[:name], event.name) do |a,e|
|
39
|
+
if a.is_a? String
|
40
|
+
a == e.to_s
|
41
|
+
else
|
42
|
+
a == e
|
43
|
+
end
|
44
|
+
end
|
45
|
+
].reduce(true, &:&)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'discordrb/events/generic'
|
2
|
+
require 'discordrb/data'
|
3
|
+
|
4
|
+
module Discordrb::Events
|
5
|
+
class ChannelDeleteEvent
|
6
|
+
attr_reader :type
|
7
|
+
attr_reader :topic
|
8
|
+
attr_reader :position
|
9
|
+
attr_reader :name
|
10
|
+
attr_reader :is_private
|
11
|
+
attr_reader :id
|
12
|
+
attr_reader :server
|
13
|
+
|
14
|
+
def initialize(data, bot)
|
15
|
+
@type = data['type']
|
16
|
+
@topic = data['topic']
|
17
|
+
@position = data['position']
|
18
|
+
@name = data['name']
|
19
|
+
@is_private = data['is_private']
|
20
|
+
@id = data['id'].to_i
|
21
|
+
@server = bot.server(data['guild_id'].to_i)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class ChannelDeleteEventHandler < EventHandler
|
26
|
+
def matches?(event)
|
27
|
+
# Check for the proper event type
|
28
|
+
return false unless event.is_a? ChannelDeleteEvent
|
29
|
+
|
30
|
+
return [
|
31
|
+
matches_all(@attributes[:type], event.type) do |a,e|
|
32
|
+
if a.is_a? String
|
33
|
+
a == e.name
|
34
|
+
else
|
35
|
+
a == e
|
36
|
+
end
|
37
|
+
end,
|
38
|
+
matches_all(@attributes[:name], event.name) do |a,e|
|
39
|
+
if a.is_a? String
|
40
|
+
a == e.to_s
|
41
|
+
else
|
42
|
+
a == e
|
43
|
+
end
|
44
|
+
end
|
45
|
+
].reduce(true, &:&)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'discordrb/events/generic'
|
2
|
+
require 'discordrb/data'
|
3
|
+
|
4
|
+
module Discordrb::Events
|
5
|
+
class ChannelUpdateEvent
|
6
|
+
attr_reader :type
|
7
|
+
attr_reader :topic
|
8
|
+
attr_reader :position
|
9
|
+
attr_reader :name
|
10
|
+
attr_reader :is_private
|
11
|
+
attr_reader :channel
|
12
|
+
attr_reader :server
|
13
|
+
|
14
|
+
def initialize(data, bot)
|
15
|
+
@type = data['type']
|
16
|
+
@topic = data['topic']
|
17
|
+
@position = data['position']
|
18
|
+
@name = data['name']
|
19
|
+
@is_private = data['is_private']
|
20
|
+
@server = bot.server(data['guild_id'].to_i)
|
21
|
+
return if !@server
|
22
|
+
@channel = bot.channel(data['id'].to_i)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class ChannelUpdateEventHandler < EventHandler
|
27
|
+
def matches?(event)
|
28
|
+
# Check for the proper event type
|
29
|
+
return false unless event.is_a? ChannelUpdateEvent
|
30
|
+
|
31
|
+
return [
|
32
|
+
matches_all(@attributes[:type], event.type) do |a,e|
|
33
|
+
if a.is_a? String
|
34
|
+
a == e.name
|
35
|
+
else
|
36
|
+
a == e
|
37
|
+
end
|
38
|
+
end,
|
39
|
+
matches_all(@attributes[:name], event.name) do |a,e|
|
40
|
+
if a.is_a? String
|
41
|
+
a == e.to_s
|
42
|
+
else
|
43
|
+
a == e
|
44
|
+
end
|
45
|
+
end
|
46
|
+
].reduce(true, &:&)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -1,59 +1,59 @@
|
|
1
|
-
require 'active_support/core_ext/module'
|
2
|
-
|
3
|
-
module Discordrb::Events
|
4
|
-
class Negated
|
5
|
-
attr_reader :object
|
6
|
-
def initialize(object); @object = object; end
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.matches_all(attributes, to_check, &block)
|
10
|
-
# "Zeroth" case: attributes is nil
|
11
|
-
return true unless attributes
|
12
|
-
|
13
|
-
# First case: there's a single negated attribute
|
14
|
-
if attributes.is_a? Negated
|
15
|
-
# The contained object might also be an array, so recursively call matches_all (and negate the result)
|
16
|
-
return !matches_all(attributes.object, to_check, &block)
|
17
|
-
end
|
18
|
-
|
19
|
-
# Second case: there's a single, not-negated attribute
|
20
|
-
unless attributes.is_a? Array
|
21
|
-
return yield(attributes, to_check)
|
22
|
-
end
|
23
|
-
|
24
|
-
# Third case: it's an array of attributes
|
25
|
-
attributes.reduce(false) do |result, element|
|
26
|
-
result || yield(element, to_check)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
class EventHandler
|
31
|
-
def initialize(attributes, block)
|
32
|
-
@attributes = attributes
|
33
|
-
@block = block
|
34
|
-
end
|
35
|
-
|
36
|
-
def matches?(event)
|
37
|
-
raise "Attempted to call matches?() from a generic EventHandler"
|
38
|
-
end
|
39
|
-
|
40
|
-
def match(event)
|
41
|
-
@block.call(event) if matches? event
|
42
|
-
end
|
43
|
-
|
44
|
-
def matches_all(attributes, to_check, &block)
|
45
|
-
Discordrb::Events.matches_all(attributes, to_check, &block)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
# Event handler that matches all events
|
50
|
-
class TrueEventHandler < EventHandler
|
51
|
-
def matches?(event)
|
52
|
-
true
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def not!(object)
|
58
|
-
Discordrb::Events::Negated.new(object)
|
59
|
-
end
|
1
|
+
require 'active_support/core_ext/module'
|
2
|
+
|
3
|
+
module Discordrb::Events
|
4
|
+
class Negated
|
5
|
+
attr_reader :object
|
6
|
+
def initialize(object); @object = object; end
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.matches_all(attributes, to_check, &block)
|
10
|
+
# "Zeroth" case: attributes is nil
|
11
|
+
return true unless attributes
|
12
|
+
|
13
|
+
# First case: there's a single negated attribute
|
14
|
+
if attributes.is_a? Negated
|
15
|
+
# The contained object might also be an array, so recursively call matches_all (and negate the result)
|
16
|
+
return !matches_all(attributes.object, to_check, &block)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Second case: there's a single, not-negated attribute
|
20
|
+
unless attributes.is_a? Array
|
21
|
+
return yield(attributes, to_check)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Third case: it's an array of attributes
|
25
|
+
attributes.reduce(false) do |result, element|
|
26
|
+
result || yield(element, to_check)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class EventHandler
|
31
|
+
def initialize(attributes, block)
|
32
|
+
@attributes = attributes
|
33
|
+
@block = block
|
34
|
+
end
|
35
|
+
|
36
|
+
def matches?(event)
|
37
|
+
raise "Attempted to call matches?() from a generic EventHandler"
|
38
|
+
end
|
39
|
+
|
40
|
+
def match(event)
|
41
|
+
@block.call(event) if matches? event
|
42
|
+
end
|
43
|
+
|
44
|
+
def matches_all(attributes, to_check, &block)
|
45
|
+
Discordrb::Events.matches_all(attributes, to_check, &block)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# Event handler that matches all events
|
50
|
+
class TrueEventHandler < EventHandler
|
51
|
+
def matches?(event)
|
52
|
+
true
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def not!(object)
|
58
|
+
Discordrb::Events::Negated.new(object)
|
59
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'discordrb/events/generic'
|
2
|
+
require 'discordrb/data'
|
3
|
+
|
4
|
+
module Discordrb::Events
|
5
|
+
class GuildMemberUpdateEvent
|
6
|
+
attr_reader :user
|
7
|
+
attr_reader :roles
|
8
|
+
attr_reader :server
|
9
|
+
|
10
|
+
def initialize(data, bot)
|
11
|
+
@server = bot.server(data['guild_id'].to_i)
|
12
|
+
return if !@server
|
13
|
+
|
14
|
+
user_id = data['user']['id'].to_i
|
15
|
+
@user = @server.members.find {|u| u.id == user_id}
|
16
|
+
@roles = []
|
17
|
+
data['roles'].each do |element|
|
18
|
+
role_id = element.to_i
|
19
|
+
@roles << @server.roles.find {|r| r.id == role_id}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class GuildMemberUpdateHandler < EventHandler
|
25
|
+
def matches?(event)
|
26
|
+
# Check for the proper event type
|
27
|
+
return false unless event.is_a? GuildMemberUpdateEvent
|
28
|
+
|
29
|
+
return [
|
30
|
+
matches_all(@attributes[:name], event.name) do |a,e|
|
31
|
+
if a.is_a? String
|
32
|
+
a == e.to_s
|
33
|
+
else
|
34
|
+
a == e
|
35
|
+
end
|
36
|
+
end
|
37
|
+
].reduce(true, &:&)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'discordrb/events/generic'
|
2
|
+
require 'discordrb/data'
|
3
|
+
|
4
|
+
module Discordrb::Events
|
5
|
+
class GuildRoleCreateEvent
|
6
|
+
attr_reader :role
|
7
|
+
attr_reader :server
|
8
|
+
|
9
|
+
def initialize(data, bot)
|
10
|
+
@server = bot.server(data['guild_id'].to_i)
|
11
|
+
return if !@server
|
12
|
+
|
13
|
+
role_id = data['role']['id'].to_i
|
14
|
+
@role = @server.roles.find {|r| r.id == role_id}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class GuildRoleCreateEventHandler < EventHandler
|
19
|
+
def matches?(event)
|
20
|
+
# Check for the proper event type
|
21
|
+
return false unless event.is_a? GuildRoleCreateEvent
|
22
|
+
|
23
|
+
return [
|
24
|
+
matches_all(@attributes[:name], event.name) do |a,e|
|
25
|
+
if a.is_a? String
|
26
|
+
a == e.to_s
|
27
|
+
else
|
28
|
+
a == e
|
29
|
+
end
|
30
|
+
end
|
31
|
+
].reduce(true, &:&)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'discordrb/events/generic'
|
2
|
+
require 'discordrb/data'
|
3
|
+
|
4
|
+
module Discordrb::Events
|
5
|
+
class GuildRoleDeleteEvent
|
6
|
+
attr_reader :id
|
7
|
+
attr_reader :server
|
8
|
+
|
9
|
+
def initialize(data, bot)
|
10
|
+
# The role should already be deleted from the server's list
|
11
|
+
# by the time we create this event, so we'll create a temporary
|
12
|
+
# role object for event consumers to use.
|
13
|
+
@id = data['role_id'].to_i
|
14
|
+
server_id = data['guild_id'].to_i
|
15
|
+
@server = bot.server(server_id)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class GuildRoleDeleteEventHandler < EventHandler
|
20
|
+
def matches?(event)
|
21
|
+
# Check for the proper event type
|
22
|
+
return false unless event.is_a? GuildRoleDeleteEvent
|
23
|
+
|
24
|
+
return [
|
25
|
+
matches_all(@attributes[:name], event.name) do |a,e|
|
26
|
+
if a.is_a? String
|
27
|
+
a == e.to_s
|
28
|
+
else
|
29
|
+
a == e
|
30
|
+
end
|
31
|
+
end
|
32
|
+
].reduce(true, &:&)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'discordrb/events/generic'
|
2
|
+
require 'discordrb/data'
|
3
|
+
|
4
|
+
module Discordrb::Events
|
5
|
+
class GuildRoleUpdateEvent
|
6
|
+
attr_reader :role
|
7
|
+
attr_reader :server
|
8
|
+
|
9
|
+
def initialize(data, bot)
|
10
|
+
@server = bot.server(data['guild_id'].to_i)
|
11
|
+
return if !@server
|
12
|
+
|
13
|
+
role_id = data['role']['id'].to_i
|
14
|
+
@role = @server.roles.find {|r| r.id == role_id}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class GuildRoleUpdateEventHandler < EventHandler
|
19
|
+
def matches?(event)
|
20
|
+
# Check for the proper event type
|
21
|
+
return false unless event.is_a? GuildRoleUpdateEvent
|
22
|
+
|
23
|
+
return [
|
24
|
+
matches_all(@attributes[:name], event.name) do |a,e|
|
25
|
+
if a.is_a? String
|
26
|
+
a == e.to_s
|
27
|
+
else
|
28
|
+
a == e
|
29
|
+
end
|
30
|
+
end
|
31
|
+
].reduce(true, &:&)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|