discordrb 1.5.4 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of discordrb might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.rubocop.yml +11 -0
- data/.yardopts +1 -1
- data/CHANGELOG.md +27 -0
- data/README.md +4 -0
- data/discordrb.gemspec +2 -0
- data/lib/discordrb.rb +17 -0
- data/lib/discordrb/api.rb +57 -31
- data/lib/discordrb/await.rb +2 -1
- data/lib/discordrb/bot.rb +125 -49
- data/lib/discordrb/commands/command_bot.rb +7 -2
- data/lib/discordrb/commands/parser.rb +2 -0
- data/lib/discordrb/data.rb +471 -112
- data/lib/discordrb/events/bans.rb +54 -0
- data/lib/discordrb/events/channel_create.rb +10 -10
- data/lib/discordrb/events/channel_delete.rb +10 -10
- data/lib/discordrb/events/channel_update.rb +10 -10
- data/lib/discordrb/events/guild_role_create.rb +5 -5
- data/lib/discordrb/events/guild_role_delete.rb +5 -5
- data/lib/discordrb/events/guild_role_update.rb +5 -5
- data/lib/discordrb/events/guilds.rb +7 -8
- data/lib/discordrb/events/members.rb +5 -5
- data/lib/discordrb/events/message.rb +48 -0
- data/lib/discordrb/events/presence.rb +25 -29
- data/lib/discordrb/events/typing.rb +7 -7
- data/lib/discordrb/events/voice_state_update.rb +34 -34
- data/lib/discordrb/permissions.rb +1 -1
- data/lib/discordrb/token_cache.rb +2 -3
- data/lib/discordrb/version.rb +2 -1
- data/lib/discordrb/voice/encoder.rb +32 -2
- data/lib/discordrb/voice/network.rb +87 -11
- data/lib/discordrb/voice/voice_bot.rb +77 -20
- metadata +33 -3
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'discordrb/events/generic'
|
2
|
+
|
3
|
+
module Discordrb::Events
|
4
|
+
# Raised when a user is banned
|
5
|
+
class UserBanEvent
|
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
|
+
if a.is_a? String
|
29
|
+
a == e.name
|
30
|
+
elsif a.is_a? Integer
|
31
|
+
a == e.id
|
32
|
+
elsif a == :bot
|
33
|
+
e.bot?
|
34
|
+
else
|
35
|
+
a == e
|
36
|
+
end
|
37
|
+
end,
|
38
|
+
matches_all(@attributes[:server], event.server) do |a, e|
|
39
|
+
if a.is_a? String
|
40
|
+
a == e.name
|
41
|
+
elsif a.is_a? Integer
|
42
|
+
a == e.id
|
43
|
+
else
|
44
|
+
a == e
|
45
|
+
end
|
46
|
+
end
|
47
|
+
].reduce(true, &:&)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Raised when a user is unbanned from a server
|
52
|
+
class UserUnbanEvent < UserBanEvent; end
|
53
|
+
class UserUnbanEventHandler < UserBanEventHandler; end
|
54
|
+
end
|
@@ -25,18 +25,18 @@ module Discordrb::Events
|
|
25
25
|
|
26
26
|
[
|
27
27
|
matches_all(@attributes[:type], event.type) do |a, e|
|
28
|
-
if a.is_a? String
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
a == if a.is_a? String
|
29
|
+
e.name
|
30
|
+
else
|
31
|
+
e
|
32
|
+
end
|
33
33
|
end,
|
34
34
|
matches_all(@attributes[:name], event.name) do |a, e|
|
35
|
-
if a.is_a? String
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
35
|
+
a == if a.is_a? String
|
36
|
+
e.to_s
|
37
|
+
else
|
38
|
+
e
|
39
|
+
end
|
40
40
|
end
|
41
41
|
].reduce(true, &:&)
|
42
42
|
end
|
@@ -25,18 +25,18 @@ module Discordrb::Events
|
|
25
25
|
|
26
26
|
[
|
27
27
|
matches_all(@attributes[:type], event.type) do |a, e|
|
28
|
-
if a.is_a? String
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
a == if a.is_a? String
|
29
|
+
e.name
|
30
|
+
else
|
31
|
+
e
|
32
|
+
end
|
33
33
|
end,
|
34
34
|
matches_all(@attributes[:name], event.name) do |a, e|
|
35
|
-
if a.is_a? String
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
35
|
+
a == if a.is_a? String
|
36
|
+
e.to_s
|
37
|
+
else
|
38
|
+
e
|
39
|
+
end
|
40
40
|
end
|
41
41
|
].reduce(true, &:&)
|
42
42
|
end
|
@@ -27,18 +27,18 @@ module Discordrb::Events
|
|
27
27
|
|
28
28
|
[
|
29
29
|
matches_all(@attributes[:type], event.type) do |a, e|
|
30
|
-
if a.is_a? String
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
30
|
+
a == if a.is_a? String
|
31
|
+
e.name
|
32
|
+
else
|
33
|
+
e
|
34
|
+
end
|
35
35
|
end,
|
36
36
|
matches_all(@attributes[:name], event.name) do |a, e|
|
37
|
-
if a.is_a? String
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
37
|
+
a == if a.is_a? String
|
38
|
+
e.to_s
|
39
|
+
else
|
40
|
+
e
|
41
|
+
end
|
42
42
|
end
|
43
43
|
].reduce(true, &:&)
|
44
44
|
end
|
@@ -23,11 +23,11 @@ module Discordrb::Events
|
|
23
23
|
|
24
24
|
[
|
25
25
|
matches_all(@attributes[:name], event.name) do |a, e|
|
26
|
-
if a.is_a? String
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
a == if a.is_a? String
|
27
|
+
e.to_s
|
28
|
+
else
|
29
|
+
e
|
30
|
+
end
|
31
31
|
end
|
32
32
|
].reduce(true, &:&)
|
33
33
|
end
|
@@ -24,11 +24,11 @@ module Discordrb::Events
|
|
24
24
|
|
25
25
|
[
|
26
26
|
matches_all(@attributes[:name], event.name) do |a, e|
|
27
|
-
if a.is_a? String
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
27
|
+
a == if a.is_a? String
|
28
|
+
e.to_s
|
29
|
+
else
|
30
|
+
e
|
31
|
+
end
|
32
32
|
end
|
33
33
|
].reduce(true, &:&)
|
34
34
|
end
|
@@ -23,11 +23,11 @@ module Discordrb::Events
|
|
23
23
|
|
24
24
|
[
|
25
25
|
matches_all(@attributes[:name], event.name) do |a, e|
|
26
|
-
if a.is_a? String
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
a == if a.is_a? String
|
27
|
+
e.to_s
|
28
|
+
else
|
29
|
+
e
|
30
|
+
end
|
31
31
|
end
|
32
32
|
].reduce(true, &:&)
|
33
33
|
end
|
@@ -12,7 +12,6 @@ module Discordrb::Events
|
|
12
12
|
|
13
13
|
def init_server(data, bot)
|
14
14
|
@server = bot.server(data['id'].to_i)
|
15
|
-
return unless @server
|
16
15
|
end
|
17
16
|
end
|
18
17
|
|
@@ -24,13 +23,13 @@ module Discordrb::Events
|
|
24
23
|
|
25
24
|
[
|
26
25
|
matches_all(@attributes[:server], event.server) do |a, e|
|
27
|
-
if a.is_a? String
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
26
|
+
a == if a.is_a? String
|
27
|
+
e.name
|
28
|
+
elsif a.is_a? Fixnum
|
29
|
+
e.id
|
30
|
+
else
|
31
|
+
e
|
32
|
+
end
|
34
33
|
end
|
35
34
|
].reduce(true, &:&)
|
36
35
|
end
|
@@ -39,11 +39,11 @@ module Discordrb::Events
|
|
39
39
|
|
40
40
|
[
|
41
41
|
matches_all(@attributes[:username], event.user.name) do |a, e|
|
42
|
-
if a.is_a? String
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
42
|
+
a == if a.is_a? String
|
43
|
+
e.to_s
|
44
|
+
else
|
45
|
+
e
|
46
|
+
end
|
47
47
|
end
|
48
48
|
].reduce(true, &:&)
|
49
49
|
end
|
@@ -95,4 +95,52 @@ module Discordrb::Events
|
|
95
95
|
|
96
96
|
class PrivateMessageEvent < MessageEvent; end
|
97
97
|
class PrivateMessageEventHandler < MessageEventHandler; end
|
98
|
+
|
99
|
+
# A subset of MessageEvent that only contains a message ID and a channel
|
100
|
+
class MessageIDEvent
|
101
|
+
# @return [Integer] the ID associated with this event
|
102
|
+
attr_reader :id
|
103
|
+
|
104
|
+
# @return [Channel] the channel in which this event occurred
|
105
|
+
attr_reader :channel
|
106
|
+
|
107
|
+
# @!visibility private
|
108
|
+
def initialize(data, bot)
|
109
|
+
@id = data['id'].to_i
|
110
|
+
@channel = bot.channel(data['channel_id'].to_i)
|
111
|
+
@bot = bot
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
# Event handler for {MessageIDEvent}
|
116
|
+
class MessageIDEventHandler < EventHandler
|
117
|
+
def matches?(event)
|
118
|
+
# Check for the proper event type
|
119
|
+
return false unless event.is_a? MessageIDEvent
|
120
|
+
|
121
|
+
[
|
122
|
+
matches_all(@attributes[:id], event.id) do |a, e|
|
123
|
+
a.resolve_id == e.resolve_id
|
124
|
+
end,
|
125
|
+
matches_all(@attributes[:in], event.channel) do |a, e|
|
126
|
+
if a.is_a? String
|
127
|
+
# Make sure to remove the "#" from channel names in case it was specified
|
128
|
+
a.delete('#') == e.name
|
129
|
+
elsif a.is_a? Integer
|
130
|
+
a == e.id
|
131
|
+
else
|
132
|
+
a == e
|
133
|
+
end
|
134
|
+
end
|
135
|
+
].reduce(true, &:&)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
# Raised when a message is edited
|
140
|
+
class MessageEditEvent < MessageIDEvent; end
|
141
|
+
class MessageEditEventHandler < MessageIDEventHandler; end
|
142
|
+
|
143
|
+
# Raised when a message is deleted
|
144
|
+
class MessageDeleteEvent < MessageIDEvent; end
|
145
|
+
class MessageDeleteEventHandler < MessageIDEventHandler; end
|
98
146
|
end
|
@@ -21,20 +21,20 @@ module Discordrb::Events
|
|
21
21
|
|
22
22
|
[
|
23
23
|
matches_all(@attributes[:from], event.user) do |a, e|
|
24
|
-
if a.is_a? String
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
24
|
+
a == if a.is_a? String
|
25
|
+
e.name
|
26
|
+
elsif a.is_a? Fixnum
|
27
|
+
e.id
|
28
|
+
else
|
29
|
+
e
|
30
|
+
end
|
31
31
|
end,
|
32
32
|
matches_all(@attributes[:status], event.status) do |a, e|
|
33
|
-
if a.is_a? String
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
33
|
+
a == if a.is_a? String
|
34
|
+
e.to_s
|
35
|
+
else
|
36
|
+
e
|
37
|
+
end
|
38
38
|
end
|
39
39
|
].reduce(true, &:&)
|
40
40
|
end
|
@@ -47,11 +47,7 @@ module Discordrb::Events
|
|
47
47
|
def initialize(data, bot)
|
48
48
|
@user = bot.user(data['user']['id'].to_i)
|
49
49
|
|
50
|
-
|
51
|
-
@game = data['game']['name']
|
52
|
-
else
|
53
|
-
@game = nil
|
54
|
-
end
|
50
|
+
@game = data['game'] ? data['game']['name'] : nil
|
55
51
|
|
56
52
|
@server = bot.server(data['guild_id'].to_i)
|
57
53
|
end
|
@@ -65,20 +61,20 @@ module Discordrb::Events
|
|
65
61
|
|
66
62
|
[
|
67
63
|
matches_all(@attributes[:from], event.user) do |a, e|
|
68
|
-
if a.is_a? String
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
64
|
+
a == if a.is_a? String
|
65
|
+
e.name
|
66
|
+
elsif a.is_a? Fixnum
|
67
|
+
e.id
|
68
|
+
else
|
69
|
+
e
|
70
|
+
end
|
75
71
|
end,
|
76
72
|
matches_all(@attributes[:game], event.game) do |a, e|
|
77
|
-
if a.is_a? String
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
73
|
+
a == if a.is_a? String
|
74
|
+
e.name
|
75
|
+
else
|
76
|
+
e
|
77
|
+
end
|
82
78
|
end
|
83
79
|
].reduce(true, &:&)
|
84
80
|
end
|
@@ -31,13 +31,13 @@ module Discordrb::Events
|
|
31
31
|
end
|
32
32
|
end,
|
33
33
|
matches_all(@attributes[:from], event.user) do |a, e|
|
34
|
-
if a.is_a? String
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
34
|
+
a == if a.is_a? String
|
35
|
+
e.name
|
36
|
+
elsif a.is_a? Fixnum
|
37
|
+
e.id
|
38
|
+
else
|
39
|
+
e
|
40
|
+
end
|
41
41
|
end,
|
42
42
|
matches_all(@attributes[:after], event.timestamp) { |a, e| a > e },
|
43
43
|
matches_all(@attributes[:before], event.timestamp) { |a, e| a < e }
|
@@ -30,50 +30,50 @@ module Discordrb::Events
|
|
30
30
|
|
31
31
|
[
|
32
32
|
matches_all(@attributes[:from], event.user) do |a, e|
|
33
|
-
if a.is_a? String
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
33
|
+
a == if a.is_a? String
|
34
|
+
e.name
|
35
|
+
elsif a.is_a? Integer
|
36
|
+
e.id
|
37
|
+
else
|
38
|
+
e
|
39
|
+
end
|
40
40
|
end,
|
41
41
|
matches_all(@attributes[:mute], event.mute) do |a, e|
|
42
|
-
if a.is_a?
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
42
|
+
a == if a.is_a?(TrueClass) || a.is_a?(FalseClass)
|
43
|
+
e.to_s
|
44
|
+
else
|
45
|
+
e
|
46
|
+
end
|
47
47
|
end,
|
48
48
|
matches_all(@attributes[:deaf], event.deaf) do |a, e|
|
49
|
-
if a.is_a?
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
49
|
+
a == if a.is_a?(TrueClass) || a.is_a?(FalseClass)
|
50
|
+
e.to_s
|
51
|
+
else
|
52
|
+
e
|
53
|
+
end
|
54
54
|
end,
|
55
55
|
matches_all(@attributes[:self_mute], event.self_mute) do |a, e|
|
56
|
-
if a.is_a?
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
56
|
+
a == if a.is_a?(TrueClass) || a.is_a?(FalseClass)
|
57
|
+
e.to_s
|
58
|
+
else
|
59
|
+
e
|
60
|
+
end
|
61
61
|
end,
|
62
62
|
matches_all(@attributes[:self_deaf], event.self_deaf) do |a, e|
|
63
|
-
if a.is_a?
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
63
|
+
a == if a.is_a?(TrueClass) || a.is_a?(FalseClass)
|
64
|
+
e.to_s
|
65
|
+
else
|
66
|
+
e
|
67
|
+
end
|
68
68
|
end,
|
69
69
|
matches_all(@attributes[:channel], event.channel) do |a, e|
|
70
|
-
if a.is_a? String
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
70
|
+
a == if a.is_a? String
|
71
|
+
e.name
|
72
|
+
elsif a.is_a? Fixnum
|
73
|
+
e.id
|
74
|
+
else
|
75
|
+
e
|
76
|
+
end
|
77
77
|
end
|
78
78
|
].reduce(true, &:&)
|
79
79
|
end
|