discordrb 1.3.4 → 1.3.5
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/.rubocop.yml +44 -0
- data/lib/discordrb.rb +4 -3
- data/lib/discordrb/api.rb +4 -3
- data/lib/discordrb/bot.rb +102 -90
- data/lib/discordrb/commands/{command-bot.rb → command_bot.rb} +32 -37
- data/lib/discordrb/commands/events.rb +1 -0
- data/lib/discordrb/commands/parser.rb +15 -14
- data/lib/discordrb/data.rb +49 -50
- data/lib/discordrb/events/{channel-create.rb → channel_create.rb} +50 -48
- data/lib/discordrb/events/{channel-delete.rb → channel_delete.rb} +5 -3
- data/lib/discordrb/events/{channel-update.rb → channel_update.rb} +7 -4
- data/lib/discordrb/events/generic.rb +11 -7
- data/lib/discordrb/events/{guild-member-update.rb → guild_member_update.rb} +8 -6
- data/lib/discordrb/events/{guild-role-create.rb → guild_role_create.rb} +7 -5
- data/lib/discordrb/events/{guild-role-delete.rb → guild_role_delete.rb} +4 -2
- data/lib/discordrb/events/{guild-role-update.rb → guild_role_update.rb} +7 -5
- data/lib/discordrb/events/message.rb +15 -11
- data/lib/discordrb/events/presence.rb +5 -3
- data/lib/discordrb/events/typing.rb +8 -6
- data/lib/discordrb/events/{voice-state-update.rb → voice_state_update.rb} +14 -13
- data/lib/discordrb/exceptions.rb +4 -2
- data/lib/discordrb/games.rb +4 -307
- data/lib/discordrb/games_list.rb +308 -0
- data/lib/discordrb/permissions.rb +10 -9
- data/lib/discordrb/version.rb +2 -1
- metadata +13 -11
| @@ -2,6 +2,7 @@ require 'discordrb/events/generic' | |
| 2 2 | 
             
            require 'discordrb/data'
         | 
| 3 3 |  | 
| 4 4 | 
             
            module Discordrb::Events
         | 
| 5 | 
            +
              # Raised when a channel is deleted
         | 
| 5 6 | 
             
              class ChannelDeleteEvent
         | 
| 6 7 | 
             
                attr_reader :type
         | 
| 7 8 | 
             
                attr_reader :topic
         | 
| @@ -22,20 +23,21 @@ module Discordrb::Events | |
| 22 23 | 
             
                end
         | 
| 23 24 | 
             
              end
         | 
| 24 25 |  | 
| 26 | 
            +
              # Event handler for ChannelDeleteEvent
         | 
| 25 27 | 
             
              class ChannelDeleteEventHandler < EventHandler
         | 
| 26 28 | 
             
                def matches?(event)
         | 
| 27 29 | 
             
                  # Check for the proper event type
         | 
| 28 30 | 
             
                  return false unless event.is_a? ChannelDeleteEvent
         | 
| 29 31 |  | 
| 30 | 
            -
                   | 
| 31 | 
            -
                    matches_all(@attributes[:type], event.type) do |a,e|
         | 
| 32 | 
            +
                  [
         | 
| 33 | 
            +
                    matches_all(@attributes[:type], event.type) do |a, e|
         | 
| 32 34 | 
             
                      if a.is_a? String
         | 
| 33 35 | 
             
                        a == e.name
         | 
| 34 36 | 
             
                      else
         | 
| 35 37 | 
             
                        a == e
         | 
| 36 38 | 
             
                      end
         | 
| 37 39 | 
             
                    end,
         | 
| 38 | 
            -
                    matches_all(@attributes[:name], event.name) do |a,e|
         | 
| 40 | 
            +
                    matches_all(@attributes[:name], event.name) do |a, e|
         | 
| 39 41 | 
             
                      if a.is_a? String
         | 
| 40 42 | 
             
                        a == e.to_s
         | 
| 41 43 | 
             
                      else
         | 
| @@ -2,6 +2,7 @@ require 'discordrb/events/generic' | |
| 2 2 | 
             
            require 'discordrb/data'
         | 
| 3 3 |  | 
| 4 4 | 
             
            module Discordrb::Events
         | 
| 5 | 
            +
              # Raised when a channel is updated (e.g. topic changes)
         | 
| 5 6 | 
             
              class ChannelUpdateEvent
         | 
| 6 7 | 
             
                attr_reader :type
         | 
| 7 8 | 
             
                attr_reader :topic
         | 
| @@ -18,25 +19,27 @@ module Discordrb::Events | |
| 18 19 | 
             
                  @name = data['name']
         | 
| 19 20 | 
             
                  @is_private = data['is_private']
         | 
| 20 21 | 
             
                  @server = bot.server(data['guild_id'].to_i)
         | 
| 21 | 
            -
                  return  | 
| 22 | 
            +
                  return unless @server
         | 
| 23 | 
            +
             | 
| 22 24 | 
             
                  @channel = bot.channel(data['id'].to_i)
         | 
| 23 25 | 
             
                end
         | 
| 24 26 | 
             
              end
         | 
| 25 27 |  | 
| 28 | 
            +
              # Event handler for ChannelUpdateEvent
         | 
| 26 29 | 
             
              class ChannelUpdateEventHandler < EventHandler
         | 
| 27 30 | 
             
                def matches?(event)
         | 
| 28 31 | 
             
                  # Check for the proper event type
         | 
| 29 32 | 
             
                  return false unless event.is_a? ChannelUpdateEvent
         | 
| 30 33 |  | 
| 31 | 
            -
                   | 
| 32 | 
            -
                    matches_all(@attributes[:type], event.type) do |a,e|
         | 
| 34 | 
            +
                  [
         | 
| 35 | 
            +
                    matches_all(@attributes[:type], event.type) do |a, e|
         | 
| 33 36 | 
             
                      if a.is_a? String
         | 
| 34 37 | 
             
                        a == e.name
         | 
| 35 38 | 
             
                      else
         | 
| 36 39 | 
             
                        a == e
         | 
| 37 40 | 
             
                      end
         | 
| 38 41 | 
             
                    end,
         | 
| 39 | 
            -
                    matches_all(@attributes[:name], event.name) do |a,e|
         | 
| 42 | 
            +
                    matches_all(@attributes[:name], event.name) do |a, e|
         | 
| 40 43 | 
             
                      if a.is_a? String
         | 
| 41 44 | 
             
                        a == e.to_s
         | 
| 42 45 | 
             
                      else
         | 
| @@ -1,9 +1,14 @@ | |
| 1 1 | 
             
            require 'active_support/core_ext/module'
         | 
| 2 2 |  | 
| 3 | 
            +
            # Events used by discordrb
         | 
| 3 4 | 
             
            module Discordrb::Events
         | 
| 5 | 
            +
              # A negated object, used to not match something in event parameters
         | 
| 4 6 | 
             
              class Negated
         | 
| 5 7 | 
             
                attr_reader :object
         | 
| 6 | 
            -
             | 
| 8 | 
            +
             | 
| 9 | 
            +
                def initialize(object)
         | 
| 10 | 
            +
                  @object = object
         | 
| 11 | 
            +
                end
         | 
| 7 12 | 
             
              end
         | 
| 8 13 |  | 
| 9 14 | 
             
              def self.matches_all(attributes, to_check, &block)
         | 
| @@ -17,9 +22,7 @@ module Discordrb::Events | |
| 17 22 | 
             
                end
         | 
| 18 23 |  | 
| 19 24 | 
             
                # Second case: there's a single, not-negated attribute
         | 
| 20 | 
            -
                unless attributes.is_a? Array
         | 
| 21 | 
            -
                  return yield(attributes, to_check)
         | 
| 22 | 
            -
                end
         | 
| 25 | 
            +
                return yield(attributes, to_check) unless attributes.is_a? Array
         | 
| 23 26 |  | 
| 24 27 | 
             
                # Third case: it's an array of attributes
         | 
| 25 28 | 
             
                attributes.reduce(false) do |result, element|
         | 
| @@ -27,14 +30,15 @@ module Discordrb::Events | |
| 27 30 | 
             
                end
         | 
| 28 31 | 
             
              end
         | 
| 29 32 |  | 
| 33 | 
            +
              # Generic event handler that can be extended
         | 
| 30 34 | 
             
              class EventHandler
         | 
| 31 35 | 
             
                def initialize(attributes, block)
         | 
| 32 36 | 
             
                  @attributes = attributes
         | 
| 33 37 | 
             
                  @block = block
         | 
| 34 38 | 
             
                end
         | 
| 35 39 |  | 
| 36 | 
            -
                def matches?( | 
| 37 | 
            -
                   | 
| 40 | 
            +
                def matches?(_)
         | 
| 41 | 
            +
                  fail 'Attempted to call matches?() from a generic EventHandler'
         | 
| 38 42 | 
             
                end
         | 
| 39 43 |  | 
| 40 44 | 
             
                def match(event)
         | 
| @@ -48,7 +52,7 @@ module Discordrb::Events | |
| 48 52 |  | 
| 49 53 | 
             
              # Event handler that matches all events
         | 
| 50 54 | 
             
              class TrueEventHandler < EventHandler
         | 
| 51 | 
            -
                def matches?( | 
| 55 | 
            +
                def matches?(_)
         | 
| 52 56 | 
             
                  true
         | 
| 53 57 | 
             
                end
         | 
| 54 58 | 
             
              end
         | 
| @@ -2,6 +2,7 @@ require 'discordrb/events/generic' | |
| 2 2 | 
             
            require 'discordrb/data'
         | 
| 3 3 |  | 
| 4 4 | 
             
            module Discordrb::Events
         | 
| 5 | 
            +
              # Raised when a user updates on a server (e.g. new name)
         | 
| 5 6 | 
             
              class GuildMemberUpdateEvent
         | 
| 6 7 | 
             
                attr_reader :user
         | 
| 7 8 | 
             
                attr_reader :roles
         | 
| @@ -9,25 +10,26 @@ module Discordrb::Events | |
| 9 10 |  | 
| 10 11 | 
             
                def initialize(data, bot)
         | 
| 11 12 | 
             
                  @server = bot.server(data['guild_id'].to_i)
         | 
| 12 | 
            -
                  return  | 
| 13 | 
            -
             | 
| 13 | 
            +
                  return unless @server
         | 
| 14 | 
            +
             | 
| 14 15 | 
             
                  user_id = data['user']['id'].to_i
         | 
| 15 | 
            -
                  @user = @server.members.find {|u| u.id == user_id}
         | 
| 16 | 
            +
                  @user = @server.members.find { |u| u.id == user_id }
         | 
| 16 17 | 
             
                  @roles = []
         | 
| 17 18 | 
             
                  data['roles'].each do |element|
         | 
| 18 19 | 
             
                    role_id = element.to_i
         | 
| 19 | 
            -
                    @roles << @server.roles.find {|r| r.id == role_id}
         | 
| 20 | 
            +
                    @roles << @server.roles.find { |r| r.id == role_id }
         | 
| 20 21 | 
             
                  end
         | 
| 21 22 | 
             
                end
         | 
| 22 23 | 
             
              end
         | 
| 23 24 |  | 
| 25 | 
            +
              # Event handler for GuildMemberUpdateEvent
         | 
| 24 26 | 
             
              class GuildMemberUpdateHandler < EventHandler
         | 
| 25 27 | 
             
                def matches?(event)
         | 
| 26 28 | 
             
                  # Check for the proper event type
         | 
| 27 29 | 
             
                  return false unless event.is_a? GuildMemberUpdateEvent
         | 
| 28 30 |  | 
| 29 | 
            -
                   | 
| 30 | 
            -
                    matches_all(@attributes[:name], event.name) do |a,e|
         | 
| 31 | 
            +
                  [
         | 
| 32 | 
            +
                    matches_all(@attributes[:name], event.name) do |a, e|
         | 
| 31 33 | 
             
                      if a.is_a? String
         | 
| 32 34 | 
             
                        a == e.to_s
         | 
| 33 35 | 
             
                      else
         | 
| @@ -2,26 +2,28 @@ require 'discordrb/events/generic' | |
| 2 2 | 
             
            require 'discordrb/data'
         | 
| 3 3 |  | 
| 4 4 | 
             
            module Discordrb::Events
         | 
| 5 | 
            +
              # Raised when a role is created on a server
         | 
| 5 6 | 
             
              class GuildRoleCreateEvent
         | 
| 6 7 | 
             
                attr_reader :role
         | 
| 7 8 | 
             
                attr_reader :server
         | 
| 8 9 |  | 
| 9 10 | 
             
                def initialize(data, bot)
         | 
| 10 11 | 
             
                  @server = bot.server(data['guild_id'].to_i)
         | 
| 11 | 
            -
                  return  | 
| 12 | 
            -
             | 
| 12 | 
            +
                  return unless @server
         | 
| 13 | 
            +
             | 
| 13 14 | 
             
                  role_id = data['role']['id'].to_i
         | 
| 14 | 
            -
                  @role = @server.roles.find {|r| r.id == role_id}
         | 
| 15 | 
            +
                  @role = @server.roles.find { |r| r.id == role_id }
         | 
| 15 16 | 
             
                end
         | 
| 16 17 | 
             
              end
         | 
| 17 18 |  | 
| 19 | 
            +
              # Event handler for GuildRoleCreateEvent
         | 
| 18 20 | 
             
              class GuildRoleCreateEventHandler < EventHandler
         | 
| 19 21 | 
             
                def matches?(event)
         | 
| 20 22 | 
             
                  # Check for the proper event type
         | 
| 21 23 | 
             
                  return false unless event.is_a? GuildRoleCreateEvent
         | 
| 22 24 |  | 
| 23 | 
            -
                   | 
| 24 | 
            -
                    matches_all(@attributes[:name], event.name) do |a,e|
         | 
| 25 | 
            +
                  [
         | 
| 26 | 
            +
                    matches_all(@attributes[:name], event.name) do |a, e|
         | 
| 25 27 | 
             
                      if a.is_a? String
         | 
| 26 28 | 
             
                        a == e.to_s
         | 
| 27 29 | 
             
                      else
         | 
| @@ -2,6 +2,7 @@ require 'discordrb/events/generic' | |
| 2 2 | 
             
            require 'discordrb/data'
         | 
| 3 3 |  | 
| 4 4 | 
             
            module Discordrb::Events
         | 
| 5 | 
            +
              # Raised when a role is deleted from a server
         | 
| 5 6 | 
             
              class GuildRoleDeleteEvent
         | 
| 6 7 | 
             
                attr_reader :id
         | 
| 7 8 | 
             
                attr_reader :server
         | 
| @@ -16,13 +17,14 @@ module Discordrb::Events | |
| 16 17 | 
             
                end
         | 
| 17 18 | 
             
              end
         | 
| 18 19 |  | 
| 20 | 
            +
              # EventHandler for GuildRoleDeleteEvent
         | 
| 19 21 | 
             
              class GuildRoleDeleteEventHandler < EventHandler
         | 
| 20 22 | 
             
                def matches?(event)
         | 
| 21 23 | 
             
                  # Check for the proper event type
         | 
| 22 24 | 
             
                  return false unless event.is_a? GuildRoleDeleteEvent
         | 
| 23 25 |  | 
| 24 | 
            -
                   | 
| 25 | 
            -
                    matches_all(@attributes[:name], event.name) do |a,e|
         | 
| 26 | 
            +
                  [
         | 
| 27 | 
            +
                    matches_all(@attributes[:name], event.name) do |a, e|
         | 
| 26 28 | 
             
                      if a.is_a? String
         | 
| 27 29 | 
             
                        a == e.to_s
         | 
| 28 30 | 
             
                      else
         | 
| @@ -2,26 +2,28 @@ require 'discordrb/events/generic' | |
| 2 2 | 
             
            require 'discordrb/data'
         | 
| 3 3 |  | 
| 4 4 | 
             
            module Discordrb::Events
         | 
| 5 | 
            +
              # Event raised when a role updates on a server
         | 
| 5 6 | 
             
              class GuildRoleUpdateEvent
         | 
| 6 7 | 
             
                attr_reader :role
         | 
| 7 8 | 
             
                attr_reader :server
         | 
| 8 9 |  | 
| 9 10 | 
             
                def initialize(data, bot)
         | 
| 10 11 | 
             
                  @server = bot.server(data['guild_id'].to_i)
         | 
| 11 | 
            -
                  return  | 
| 12 | 
            -
             | 
| 12 | 
            +
                  return unless @server
         | 
| 13 | 
            +
             | 
| 13 14 | 
             
                  role_id = data['role']['id'].to_i
         | 
| 14 | 
            -
                  @role = @server.roles.find {|r| r.id == role_id}
         | 
| 15 | 
            +
                  @role = @server.roles.find { |r| r.id == role_id }
         | 
| 15 16 | 
             
                end
         | 
| 16 17 | 
             
              end
         | 
| 17 18 |  | 
| 19 | 
            +
              # Event handler for GuildRoleUpdateEvent
         | 
| 18 20 | 
             
              class GuildRoleUpdateEventHandler < EventHandler
         | 
| 19 21 | 
             
                def matches?(event)
         | 
| 20 22 | 
             
                  # Check for the proper event type
         | 
| 21 23 | 
             
                  return false unless event.is_a? GuildRoleUpdateEvent
         | 
| 22 24 |  | 
| 23 | 
            -
                   | 
| 24 | 
            -
                    matches_all(@attributes[:name], event.name) do |a,e|
         | 
| 25 | 
            +
                  [
         | 
| 26 | 
            +
                    matches_all(@attributes[:name], event.name) do |a, e|
         | 
| 25 27 | 
             
                      if a.is_a? String
         | 
| 26 28 | 
             
                        a == e.to_s
         | 
| 27 29 | 
             
                      else
         | 
| @@ -1,6 +1,7 @@ | |
| 1 1 | 
             
            require 'discordrb/events/generic'
         | 
| 2 2 |  | 
| 3 3 | 
             
            module Discordrb::Events
         | 
| 4 | 
            +
              # Event raised when a text message is sent to a channel
         | 
| 4 5 | 
             
              class MessageEvent
         | 
| 5 6 | 
             
                attr_reader :message
         | 
| 6 7 |  | 
| @@ -12,7 +13,9 @@ module Discordrb::Events | |
| 12 13 | 
             
                  @message = message
         | 
| 13 14 | 
             
                end
         | 
| 14 15 |  | 
| 15 | 
            -
                def send_message(content) | 
| 16 | 
            +
                def send_message(content)
         | 
| 17 | 
            +
                  @message.channel.send_message(content)
         | 
| 18 | 
            +
                end
         | 
| 16 19 |  | 
| 17 20 | 
             
                alias_method :user, :author
         | 
| 18 21 | 
             
                alias_method :text, :content
         | 
| @@ -20,26 +23,27 @@ module Discordrb::Events | |
| 20 23 | 
             
                alias_method :respond, :send_message
         | 
| 21 24 | 
             
              end
         | 
| 22 25 |  | 
| 26 | 
            +
              # Event handler for MessageEvent
         | 
| 23 27 | 
             
              class MessageEventHandler < EventHandler
         | 
| 24 28 | 
             
                def matches?(event)
         | 
| 25 29 | 
             
                  # Check for the proper event type
         | 
| 26 30 | 
             
                  return false unless event.is_a? MessageEvent
         | 
| 27 31 |  | 
| 28 | 
            -
                   | 
| 29 | 
            -
                    matches_all(@attributes[:starting_with], event.content) { |a,e| e.start_with? a },
         | 
| 30 | 
            -
                    matches_all(@attributes[:ending_with], event.content) { |a,e| e.end_with? a },
         | 
| 31 | 
            -
                    matches_all(@attributes[:containing], event.content) { |a,e| e.include? a },
         | 
| 32 | 
            -
                    matches_all(@attributes[:in], event.channel) do |a,e|
         | 
| 32 | 
            +
                  [
         | 
| 33 | 
            +
                    matches_all(@attributes[:starting_with], event.content) { |a, e| e.start_with? a },
         | 
| 34 | 
            +
                    matches_all(@attributes[:ending_with], event.content) { |a, e| e.end_with? a },
         | 
| 35 | 
            +
                    matches_all(@attributes[:containing], event.content) { |a, e| e.include? a },
         | 
| 36 | 
            +
                    matches_all(@attributes[:in], event.channel) do |a, e|
         | 
| 33 37 | 
             
                      if a.is_a? String
         | 
| 34 38 | 
             
                        # Make sure to remove the "#" from channel names in case it was specified
         | 
| 35 | 
            -
                        a. | 
| 39 | 
            +
                        a.delete('#') == e.name
         | 
| 36 40 | 
             
                      elsif a.is_a? Fixnum
         | 
| 37 41 | 
             
                        a == e.id
         | 
| 38 42 | 
             
                      else
         | 
| 39 43 | 
             
                        a == e
         | 
| 40 44 | 
             
                      end
         | 
| 41 45 | 
             
                    end,
         | 
| 42 | 
            -
                    matches_all(@attributes[:from], event.author) do |a,e|
         | 
| 46 | 
            +
                    matches_all(@attributes[:from], event.author) do |a, e|
         | 
| 43 47 | 
             
                      if a.is_a? String
         | 
| 44 48 | 
             
                        a == e.name
         | 
| 45 49 | 
             
                      elsif a.is_a? Fixnum
         | 
| @@ -48,9 +52,9 @@ module Discordrb::Events | |
| 48 52 | 
             
                        a == e
         | 
| 49 53 | 
             
                      end
         | 
| 50 54 | 
             
                    end,
         | 
| 51 | 
            -
                    matches_all(@attributes[:with_text], event.content) { |a,e| e == a },
         | 
| 52 | 
            -
                    matches_all(@attributes[:after], event.timestamp) { |a,e| a > e },
         | 
| 53 | 
            -
                    matches_all(@attributes[:before], event.timestamp) { |a,e| a < e }
         | 
| 55 | 
            +
                    matches_all(@attributes[:with_text], event.content) { |a, e| e == a },
         | 
| 56 | 
            +
                    matches_all(@attributes[:after], event.timestamp) { |a, e| a > e },
         | 
| 57 | 
            +
                    matches_all(@attributes[:before], event.timestamp) { |a, e| a < e }
         | 
| 54 58 | 
             
                  ].reduce(true, &:&)
         | 
| 55 59 | 
             
                end
         | 
| 56 60 | 
             
              end
         | 
| @@ -2,6 +2,7 @@ require 'discordrb/events/generic' | |
| 2 2 | 
             
            require 'discordrb/data'
         | 
| 3 3 |  | 
| 4 4 | 
             
            module Discordrb::Events
         | 
| 5 | 
            +
              # Event raised when a user's presence state updates (playing game, idle or back online)
         | 
| 5 6 | 
             
              class PresenceEvent
         | 
| 6 7 | 
             
                attr_reader :server, :user, :status
         | 
| 7 8 |  | 
| @@ -12,13 +13,14 @@ module Discordrb::Events | |
| 12 13 | 
             
                end
         | 
| 13 14 | 
             
              end
         | 
| 14 15 |  | 
| 16 | 
            +
              # Event handler for PresenceEvent
         | 
| 15 17 | 
             
              class PresenceEventHandler < EventHandler
         | 
| 16 18 | 
             
                def matches?(event)
         | 
| 17 19 | 
             
                  # Check for the proper event type
         | 
| 18 20 | 
             
                  return false unless event.is_a? PresenceEvent
         | 
| 19 21 |  | 
| 20 | 
            -
                   | 
| 21 | 
            -
                    matches_all(@attributes[:from], event.user) do |a,e|
         | 
| 22 | 
            +
                  [
         | 
| 23 | 
            +
                    matches_all(@attributes[:from], event.user) do |a, e|
         | 
| 22 24 | 
             
                      if a.is_a? String
         | 
| 23 25 | 
             
                        a == e.name
         | 
| 24 26 | 
             
                      elsif a.is_a? Fixnum
         | 
| @@ -27,7 +29,7 @@ module Discordrb::Events | |
| 27 29 | 
             
                        a == e
         | 
| 28 30 | 
             
                      end
         | 
| 29 31 | 
             
                    end,
         | 
| 30 | 
            -
                    matches_all(@attributes[:status], event.status) do |a,e|
         | 
| 32 | 
            +
                    matches_all(@attributes[:status], event.status) do |a, e|
         | 
| 31 33 | 
             
                      if a.is_a? String
         | 
| 32 34 | 
             
                        a == e.to_s
         | 
| 33 35 | 
             
                      else
         | 
| @@ -1,6 +1,7 @@ | |
| 1 1 | 
             
            require 'discordrb/events/generic'
         | 
| 2 2 |  | 
| 3 3 | 
             
            module Discordrb::Events
         | 
| 4 | 
            +
              # Event raised when a user starts typing
         | 
| 4 5 | 
             
              class TypingEvent
         | 
| 5 6 | 
             
                attr_reader :channel, :user, :timestamp
         | 
| 6 7 |  | 
| @@ -13,22 +14,23 @@ module Discordrb::Events | |
| 13 14 | 
             
                end
         | 
| 14 15 | 
             
              end
         | 
| 15 16 |  | 
| 17 | 
            +
              # Event handler for TypingEvent
         | 
| 16 18 | 
             
              class TypingEventHandler < EventHandler
         | 
| 17 19 | 
             
                def matches?(event)
         | 
| 18 20 | 
             
                  # Check for the proper event type
         | 
| 19 21 | 
             
                  return false unless event.is_a? TypingEvent
         | 
| 20 22 |  | 
| 21 | 
            -
                   | 
| 22 | 
            -
                    matches_all(@attributes[:in], event.channel) do |a,e|
         | 
| 23 | 
            +
                  [
         | 
| 24 | 
            +
                    matches_all(@attributes[:in], event.channel) do |a, e|
         | 
| 23 25 | 
             
                      if a.is_a? String
         | 
| 24 | 
            -
                        a. | 
| 26 | 
            +
                        a.delete('#') == e.name
         | 
| 25 27 | 
             
                      elsif a.is_a? Fixnum
         | 
| 26 28 | 
             
                        a == e.id
         | 
| 27 29 | 
             
                      else
         | 
| 28 30 | 
             
                        a == e
         | 
| 29 31 | 
             
                      end
         | 
| 30 32 | 
             
                    end,
         | 
| 31 | 
            -
                    matches_all(@attributes[:from], event.user) do |a,e|
         | 
| 33 | 
            +
                    matches_all(@attributes[:from], event.user) do |a, e|
         | 
| 32 34 | 
             
                      if a.is_a? String
         | 
| 33 35 | 
             
                        a == e.name
         | 
| 34 36 | 
             
                      elsif a.is_a? Fixnum
         | 
| @@ -37,8 +39,8 @@ module Discordrb::Events | |
| 37 39 | 
             
                        a == e
         | 
| 38 40 | 
             
                      end
         | 
| 39 41 | 
             
                    end,
         | 
| 40 | 
            -
                    matches_all(@attributes[:after], event.timestamp) { |a,e| a > e },
         | 
| 41 | 
            -
                    matches_all(@attributes[:before], event.timestamp) { |a,e| a < e }
         | 
| 42 | 
            +
                    matches_all(@attributes[:after], event.timestamp) { |a, e| a > e },
         | 
| 43 | 
            +
                    matches_all(@attributes[:before], event.timestamp) { |a, e| a < e }
         | 
| 42 44 | 
             
                  ].reduce(true, &:&)
         | 
| 43 45 | 
             
                end
         | 
| 44 46 | 
             
              end
         | 
| @@ -2,6 +2,7 @@ require 'discordrb/events/generic' | |
| 2 2 | 
             
            require 'discordrb/data'
         | 
| 3 3 |  | 
| 4 4 | 
             
            module Discordrb::Events
         | 
| 5 | 
            +
              # Event raised when a user's voice state updates
         | 
| 5 6 | 
             
              class VoiceStateUpdateEvent
         | 
| 6 7 | 
             
                attr_reader :user
         | 
| 7 8 | 
             
                attr_reader :token
         | 
| @@ -23,21 +24,21 @@ module Discordrb::Events | |
| 23 24 | 
             
                  @mute = data['mute']
         | 
| 24 25 | 
             
                  @deaf = data['deaf']
         | 
| 25 26 | 
             
                  @server = bot.server(data['guild_id'].to_i)
         | 
| 26 | 
            -
                  return  | 
| 27 | 
            -
             | 
| 28 | 
            -
             | 
| 29 | 
            -
                  end
         | 
| 27 | 
            +
                  return unless @server
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                  @channel = bot.channel(data['channel_id'].to_i) if data['channel_id']
         | 
| 30 30 | 
             
                  @user = bot.user(data['user_id'].to_i)
         | 
| 31 31 | 
             
                end
         | 
| 32 32 | 
             
              end
         | 
| 33 33 |  | 
| 34 | 
            +
              # Event handler for VoiceStateUpdateEvent
         | 
| 34 35 | 
             
              class VoiceStateUpdateEventHandler < EventHandler
         | 
| 35 36 | 
             
                def matches?(event)
         | 
| 36 37 | 
             
                  # Check for the proper event type
         | 
| 37 38 | 
             
                  return false unless event.is_a? VoiceStateUpdateEvent
         | 
| 38 39 |  | 
| 39 | 
            -
                   | 
| 40 | 
            -
                    matches_all(@attributes[:from], event.user) do |a,e|
         | 
| 40 | 
            +
                  [
         | 
| 41 | 
            +
                    matches_all(@attributes[:from], event.user) do |a, e|
         | 
| 41 42 | 
             
                      if a.is_a? String
         | 
| 42 43 | 
             
                        a == e.name
         | 
| 43 44 | 
             
                      elsif a.is_a? Fixnum
         | 
| @@ -46,35 +47,35 @@ module Discordrb::Events | |
| 46 47 | 
             
                        a == e
         | 
| 47 48 | 
             
                      end
         | 
| 48 49 | 
             
                    end,
         | 
| 49 | 
            -
                    matches_all(@attributes[:mute], event.mute) do |a,e|
         | 
| 50 | 
            +
                    matches_all(@attributes[:mute], event.mute) do |a, e|
         | 
| 50 51 | 
             
                      if a.is_a? Boolean
         | 
| 51 52 | 
             
                        a == e.to_s
         | 
| 52 53 | 
             
                      else
         | 
| 53 54 | 
             
                        a == e
         | 
| 54 55 | 
             
                      end
         | 
| 55 56 | 
             
                    end,
         | 
| 56 | 
            -
                    matches_all(@attributes[:deaf], event.deaf) do |a,e|
         | 
| 57 | 
            +
                    matches_all(@attributes[:deaf], event.deaf) do |a, e|
         | 
| 57 58 | 
             
                      if a.is_a? Boolean
         | 
| 58 59 | 
             
                        a == e.to_s
         | 
| 59 60 | 
             
                      else
         | 
| 60 61 | 
             
                        a == e
         | 
| 61 | 
            -
                      end | 
| 62 | 
            +
                      end
         | 
| 62 63 | 
             
                    end,
         | 
| 63 | 
            -
                    matches_all(@attributes[:self_mute], event.self_mute) do |a,e|
         | 
| 64 | 
            +
                    matches_all(@attributes[:self_mute], event.self_mute) do |a, e|
         | 
| 64 65 | 
             
                      if a.is_a? Boolean
         | 
| 65 66 | 
             
                        a == e.to_s
         | 
| 66 67 | 
             
                      else
         | 
| 67 68 | 
             
                        a == e
         | 
| 68 69 | 
             
                      end
         | 
| 69 70 | 
             
                    end,
         | 
| 70 | 
            -
                    matches_all(@attributes[:self_deaf], event.self_deaf) do |a,e|
         | 
| 71 | 
            +
                    matches_all(@attributes[:self_deaf], event.self_deaf) do |a, e|
         | 
| 71 72 | 
             
                      if a.is_a? Boolean
         | 
| 72 73 | 
             
                        a == e.to_s
         | 
| 73 74 | 
             
                      else
         | 
| 74 75 | 
             
                        a == e
         | 
| 75 | 
            -
                      end | 
| 76 | 
            +
                      end
         | 
| 76 77 | 
             
                    end,
         | 
| 77 | 
            -
                    matches_all(@attributes[:channel], event.channel) do |a,e|
         | 
| 78 | 
            +
                    matches_all(@attributes[:channel], event.channel) do |a, e|
         | 
| 78 79 | 
             
                      if a.is_a? String
         | 
| 79 80 | 
             
                        a == e.name
         | 
| 80 81 | 
             
                      elsif a.is_a? Fixnum
         |