discordrb 1.0.0 → 1.0.1
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/README.md +8 -6
- data/lib/discordrb/bot.rb +22 -8
- data/lib/discordrb/events/message.rb +2 -1
- data/lib/discordrb/events/presence.rb +40 -0
- data/lib/discordrb/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be27c379055ef4c2c5a4f0b0bbaad96edb5c65e4
|
4
|
+
data.tar.gz: ebd782951477ccd5cc10f8f4764d324a2f269969
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b738fdba2605b6b5a7fa1bc8ebdffcd2e93756c4ed01f7765b9c2ddf357d64095b35e05ebc801dfba8049179256a9f9dd66e77da6b43e54554a7ea98c4938f71
|
7
|
+
data.tar.gz: c42f9f0a1c6a76e592e59b2ce7854a0bae353ef712ab79c847d21c59f9fcd7d3f8aff3d5eede31c77fdd9e7746c1465d7cae26a25405ac8fc93e3479c42f8db2
|
data/README.md
CHANGED
@@ -22,15 +22,17 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
You can make a simple bot like this:
|
24
24
|
|
25
|
-
|
25
|
+
```ruby
|
26
|
+
require 'discordrb'
|
26
27
|
|
27
|
-
|
28
|
+
bot = Discordrb::Bot.new "email@example.com", "hunter2"
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
30
|
+
bot.message(with_text: "Ping!") do |event|
|
31
|
+
event.respond "Pong!"
|
32
|
+
end
|
32
33
|
|
33
|
-
|
34
|
+
bot.run
|
35
|
+
```
|
34
36
|
|
35
37
|
This bot responds to every "Ping!" with a "Pong!".
|
36
38
|
|
data/lib/discordrb/bot.rb
CHANGED
@@ -7,6 +7,7 @@ require 'discordrb/endpoints/endpoints'
|
|
7
7
|
require 'discordrb/events/message'
|
8
8
|
require 'discordrb/events/typing'
|
9
9
|
require 'discordrb/events/lifetime'
|
10
|
+
require 'discordrb/events/presence'
|
10
11
|
|
11
12
|
require 'discordrb/exceptions'
|
12
13
|
require 'discordrb/data'
|
@@ -55,6 +56,10 @@ module Discordrb
|
|
55
56
|
@users[id]
|
56
57
|
end
|
57
58
|
|
59
|
+
def server(id)
|
60
|
+
@servers[id]
|
61
|
+
end
|
62
|
+
|
58
63
|
def send_message(channel_id, content)
|
59
64
|
debug("Sending message to #{channel_id} with content '#{content}'")
|
60
65
|
data = {
|
@@ -70,23 +75,23 @@ module Discordrb
|
|
70
75
|
end
|
71
76
|
|
72
77
|
def message(attributes = {}, &block)
|
73
|
-
|
74
|
-
@event_handlers[MessageEvent] << MessageEventHandler.new(attributes, block)
|
78
|
+
register_event(MessageEvent, attributes, block)
|
75
79
|
end
|
76
80
|
|
77
81
|
def ready(attributes = {}, &block)
|
78
|
-
|
79
|
-
@event_handlers[ReadyEvent] << ReadyEventHandler.new(attributes, block)
|
82
|
+
register_event(ReadyEvent, attributes, block)
|
80
83
|
end
|
81
84
|
|
82
85
|
def disconnected(attributes = {}, &block)
|
83
|
-
|
84
|
-
@event_handlers[DisconnectEvent] << DisconnectEventHandler.new(attributes, block)
|
86
|
+
register_event(DisconnectEvent, attributes, block)
|
85
87
|
end
|
86
88
|
|
87
89
|
def typing(attributes = {}, &block)
|
88
|
-
|
89
|
-
|
90
|
+
register_event(TypingEvent, attributes, block)
|
91
|
+
end
|
92
|
+
|
93
|
+
def presence(attributes = {}, &block)
|
94
|
+
register_event(PresenceEvent, attributes, block)
|
90
95
|
end
|
91
96
|
|
92
97
|
private
|
@@ -162,6 +167,9 @@ module Discordrb
|
|
162
167
|
when "TYPING_START"
|
163
168
|
event = TypingEvent.new(data, self)
|
164
169
|
raise_event(event)
|
170
|
+
when "PRESENCE_UPDATE"
|
171
|
+
event = PresenceEvent.new(data, self)
|
172
|
+
raise_event(event)
|
165
173
|
end
|
166
174
|
end
|
167
175
|
|
@@ -197,6 +205,12 @@ module Discordrb
|
|
197
205
|
end
|
198
206
|
end
|
199
207
|
|
208
|
+
def register_event(clazz, attributes, block)
|
209
|
+
handler = Kernel.const_get(clazz.to_s + "Handler")
|
210
|
+
@event_handlers[clazz] ||= []
|
211
|
+
@event_handlers[clazz] << handler.new(attributes, block)
|
212
|
+
end
|
213
|
+
|
200
214
|
def send_heartbeat
|
201
215
|
millis = Time.now.strftime("%s%L").to_i
|
202
216
|
debug("Sending heartbeat at #{millis}")
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'discordrb/events/generic'
|
2
|
+
require 'discordrb/data'
|
3
|
+
|
4
|
+
module Discordrb::Events
|
5
|
+
class PresenceEvent
|
6
|
+
attr_reader :server, :user, :status
|
7
|
+
|
8
|
+
def initialize(data, bot)
|
9
|
+
@user = Discordrb::User.new(data['user'], bot)
|
10
|
+
@status = data['status'].to_sym
|
11
|
+
@server = bot.server(data['guild_id'])
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class PresenceEventHandler < EventHandler
|
16
|
+
def matches?(event)
|
17
|
+
# Check for the proper event type
|
18
|
+
return false unless event.is_a? PresenceEvent
|
19
|
+
|
20
|
+
return [
|
21
|
+
matches_all(@attributes[:from], event.user) do |a,e|
|
22
|
+
if a.is_a? String
|
23
|
+
a == e.name
|
24
|
+
elsif a.is_a? Fixnum
|
25
|
+
a == e.id
|
26
|
+
else
|
27
|
+
a == e
|
28
|
+
end
|
29
|
+
end,
|
30
|
+
matches_all(@attributes[:status], event.status) 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
|
data/lib/discordrb/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: discordrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- meew0
|
@@ -90,6 +90,7 @@ files:
|
|
90
90
|
- lib/discordrb/events/generic.rb
|
91
91
|
- lib/discordrb/events/lifetime.rb
|
92
92
|
- lib/discordrb/events/message.rb
|
93
|
+
- lib/discordrb/events/presence.rb
|
93
94
|
- lib/discordrb/events/typing.rb
|
94
95
|
- lib/discordrb/exceptions.rb
|
95
96
|
- lib/discordrb/version.rb
|