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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5d928acdf371b64591d0438c7bcf45ea0f2bbba1
4
- data.tar.gz: b5e0e4847acb2a5624598f19949c6b36e9da1d89
3
+ metadata.gz: be27c379055ef4c2c5a4f0b0bbaad96edb5c65e4
4
+ data.tar.gz: ebd782951477ccd5cc10f8f4764d324a2f269969
5
5
  SHA512:
6
- metadata.gz: 81fdfef418a981ed4318b46854b7071565dda588432353bd4b5a4fb0eb1bb01dcda575dfa4b462ee0cc3d74cb9c6454d1e1fc76c90ac39da24fac584c4c01ecd
7
- data.tar.gz: 071a0ad1b506297193216409f3a2327e5318b4a0228f6dfe7243738b4f5e33ded817a0315760037de28eff5a5964e4b37b27d18400a0a69c5f1428090301d640
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
- require 'discordrb'
25
+ ```ruby
26
+ require 'discordrb'
26
27
 
27
- bot = Discordrb::Bot.new "email@example.com", "hunter2"
28
+ bot = Discordrb::Bot.new "email@example.com", "hunter2"
28
29
 
29
- bot.message(with_text: "Ping!") do |event|
30
- event.respond "Pong!"
31
- end
30
+ bot.message(with_text: "Ping!") do |event|
31
+ event.respond "Pong!"
32
+ end
32
33
 
33
- bot.run
34
+ bot.run
35
+ ```
34
36
 
35
37
  This bot responds to every "Ping!" with a "Pong!".
36
38
 
@@ -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
- @event_handlers[MessageEvent] ||= []
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
- @event_handlers[ReadyEvent] ||= []
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
- @event_handlers[DisconnectEvent] ||= []
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
- @event_handlers[TypingEvent] ||= []
89
- @event_handlers[TypingEvent] << TypingEvent.new(attributes, block)
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}")
@@ -4,7 +4,8 @@ module Discordrb::Events
4
4
  class MessageEvent
5
5
  attr_reader :message
6
6
 
7
- def initialize(message)
7
+ def initialize(message, bot)
8
+ @bot = bot
8
9
  @message = message
9
10
  end
10
11
 
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Discordrb
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
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.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