discordrb 1.4.3 → 1.4.4
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/lib/discordrb.rb +3 -0
- data/lib/discordrb/api.rb +15 -9
- data/lib/discordrb/bot.rb +20 -6
- data/lib/discordrb/data.rb +8 -4
- data/lib/discordrb/logger.rb +15 -0
- data/lib/discordrb/version.rb +1 -1
- metadata +3 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: e2d854d2a25bb8bd4ca304c5038ca48c5faecc73
         | 
| 4 | 
            +
              data.tar.gz: 0c241fd003e0a8f18cf88c93a9b5f7fbba8f8cd9
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 3a5c9019402b2ea016b5cf5c26d420f40ef7b32ad6c5905b0ed652683e425328156b64e84a13d8ab5429d1d51afd8782e0eca274b0c48d3f41e00c537f956a0b
         | 
| 7 | 
            +
              data.tar.gz: 2320f2d4578e4df2b080d0928d6e80aa9cf8d47eb66a3ba160a54473ca0c2314fda92a00d8839e0379313294cd9bb8f622051b291151cc57a3ebd728cf3c6eb3
         | 
    
        data/lib/discordrb.rb
    CHANGED
    
    | @@ -1,8 +1,11 @@ | |
| 1 1 | 
             
            require 'discordrb/version'
         | 
| 2 2 | 
             
            require 'discordrb/bot'
         | 
| 3 3 | 
             
            require 'discordrb/commands/command_bot'
         | 
| 4 | 
            +
            require 'discordrb/logger'
         | 
| 4 5 |  | 
| 5 6 | 
             
            # All discordrb functionality, to be extended by other files
         | 
| 6 7 | 
             
            module Discordrb
         | 
| 7 8 | 
             
              Thread.current[:discordrb_name] = 'main'
         | 
| 9 | 
            +
             | 
| 10 | 
            +
              LOGGER = Logger.new
         | 
| 8 11 | 
             
            end
         | 
    
        data/lib/discordrb/api.rb
    CHANGED
    
    | @@ -26,12 +26,25 @@ module Discordrb::API | |
| 26 26 | 
             
                "#{libraries.join(' ')} #{required}"
         | 
| 27 27 | 
             
              end
         | 
| 28 28 |  | 
| 29 | 
            +
              def raw_request(type, attributes)
         | 
| 30 | 
            +
                RestClient.send(type, *attributes)
         | 
| 31 | 
            +
              end
         | 
| 32 | 
            +
             | 
| 29 33 | 
             
              # Make an API request. Utility function to implement message queueing
         | 
| 30 34 | 
             
              # in the future
         | 
| 31 35 | 
             
              def request(type, *attributes)
         | 
| 32 36 | 
             
                # Add a custom user agent
         | 
| 33 37 | 
             
                attributes.last[:user_agent] = user_agent if attributes.last.is_a? Hash
         | 
| 34 | 
            -
                 | 
| 38 | 
            +
                response = raw_request(type, attributes)
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                while response.code == 429
         | 
| 41 | 
            +
                  wait_seconds = response[:retry_after].to_i / 1000.0
         | 
| 42 | 
            +
                  LOGGER.debug("WARNING: Discord rate limiting will cause a delay of #{wait_seconds} seconds for the request: #{type} #{attributes}")
         | 
| 43 | 
            +
                  sleep wait_seconds / 1000.0
         | 
| 44 | 
            +
                  response = raw_request(type, attributes)
         | 
| 45 | 
            +
                end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                response
         | 
| 35 48 | 
             
              end
         | 
| 36 49 |  | 
| 37 50 | 
             
              # Ban a user from a server and delete their messages from the last message_days days
         | 
| @@ -121,14 +134,7 @@ module Discordrb::API | |
| 121 134 | 
             
                )
         | 
| 122 135 | 
             
              end
         | 
| 123 136 |  | 
| 124 | 
            -
               | 
| 125 | 
            -
              def leave_server(server_id)
         | 
| 126 | 
            -
                request(
         | 
| 127 | 
            -
                  :delete,
         | 
| 128 | 
            -
                  "#{APIBASE}/guilds/#{server_id}",
         | 
| 129 | 
            -
                  Authorization: token
         | 
| 130 | 
            -
                )
         | 
| 131 | 
            -
              end
         | 
| 137 | 
            +
              alias_method :leave_server, :delete_server
         | 
| 132 138 |  | 
| 133 139 | 
             
              # Get a channel's data
         | 
| 134 140 | 
             
              def channel(token, channel_id)
         | 
    
        data/lib/discordrb/bot.rb
    CHANGED
    
    | @@ -72,7 +72,7 @@ module Discordrb | |
| 72 72 | 
             
                    exit
         | 
| 73 73 | 
             
                  end
         | 
| 74 74 |  | 
| 75 | 
            -
                   | 
| 75 | 
            +
                  LOGGER.debug = debug
         | 
| 76 76 | 
             
                  @should_parse_self = false
         | 
| 77 77 |  | 
| 78 78 | 
             
                  @email = email
         | 
| @@ -276,7 +276,20 @@ module Discordrb | |
| 276 276 | 
             
                # @return [Message] The message that was sent.
         | 
| 277 277 | 
             
                def send_message(channel_id, content)
         | 
| 278 278 | 
             
                  debug("Sending message to #{channel_id} with content '#{content}'")
         | 
| 279 | 
            -
             | 
| 279 | 
            +
             | 
| 280 | 
            +
                  # Replace mentions
         | 
| 281 | 
            +
                  mentions = []
         | 
| 282 | 
            +
                  content.gsub!(/<@([0-9]+)>/) do
         | 
| 283 | 
            +
                    id = Regexp.last_match(1).to_i
         | 
| 284 | 
            +
                    if @users[id]
         | 
| 285 | 
            +
                      mentions << id
         | 
| 286 | 
            +
                      "@#{@users[id].name}"
         | 
| 287 | 
            +
                    else
         | 
| 288 | 
            +
                      "<@#{id}}>"
         | 
| 289 | 
            +
                    end
         | 
| 290 | 
            +
                  end
         | 
| 291 | 
            +
             | 
| 292 | 
            +
                  response = API.send_message(@token, channel_id, content, mentions)
         | 
| 280 293 | 
             
                  Message.new(JSON.parse(response), self)
         | 
| 281 294 | 
             
                end
         | 
| 282 295 |  | 
| @@ -353,7 +366,9 @@ module Discordrb | |
| 353 366 | 
             
                end
         | 
| 354 367 |  | 
| 355 368 | 
             
                # Sets debug mode. If debug mode is on, many things will be outputted to STDOUT.
         | 
| 356 | 
            -
                 | 
| 369 | 
            +
                def debug=(new_debug)
         | 
| 370 | 
            +
                  LOGGER.debug = new_debug
         | 
| 371 | 
            +
                end
         | 
| 357 372 |  | 
| 358 373 | 
             
                ##     ##    ###    ##    ## ########  ##       ######## ########   ######
         | 
| 359 374 | 
             
                ##     ##   ## ##   ###   ## ##     ## ##       ##       ##     ## ##    ##
         | 
| @@ -492,12 +507,11 @@ module Discordrb | |
| 492 507 | 
             
                end
         | 
| 493 508 |  | 
| 494 509 | 
             
                def debug(message, important = false)
         | 
| 495 | 
            -
                   | 
| 510 | 
            +
                  LOGGER.debug(message, important)
         | 
| 496 511 | 
             
                end
         | 
| 497 512 |  | 
| 498 513 | 
             
                def log_exception(e)
         | 
| 499 | 
            -
                   | 
| 500 | 
            -
                  e.backtrace.each { |line| debug(line, true) }
         | 
| 514 | 
            +
                  LOGGER.log_exception(e)
         | 
| 501 515 | 
             
                end
         | 
| 502 516 |  | 
| 503 517 | 
             
                def handler_class(event_class)
         | 
    
        data/lib/discordrb/data.rb
    CHANGED
    
    | @@ -4,6 +4,8 @@ require 'ostruct' | |
| 4 4 | 
             
            require 'discordrb/permissions'
         | 
| 5 5 | 
             
            require 'discordrb/api'
         | 
| 6 6 | 
             
            require 'discordrb/games'
         | 
| 7 | 
            +
            require 'discordrb/events/message'
         | 
| 8 | 
            +
            require 'time'
         | 
| 7 9 | 
             
            require 'base64'
         | 
| 8 10 |  | 
| 9 11 | 
             
            # Discordrb module
         | 
| @@ -75,7 +77,7 @@ module Discordrb | |
| 75 77 |  | 
| 76 78 | 
             
                # Add an await for a message from this user
         | 
| 77 79 | 
             
                def await(key, attributes = {}, &block)
         | 
| 78 | 
            -
                  @bot.add_await(key, MessageEvent, { from: @id }.merge(attributes), &block)
         | 
| 80 | 
            +
                  @bot.add_await(key, Discordrb::Events::MessageEvent, { from: @id }.merge(attributes), &block)
         | 
| 79 81 | 
             
                end
         | 
| 80 82 |  | 
| 81 83 | 
             
                # Is the user the bot?
         | 
| @@ -383,7 +385,7 @@ module Discordrb | |
| 383 385 |  | 
| 384 386 | 
             
                # Add an await for a message in this channel
         | 
| 385 387 | 
             
                def await(key, attributes = {}, &block)
         | 
| 386 | 
            -
                  @bot.add_await(key, MessageEvent, { in: @id }.merge(attributes), &block)
         | 
| 388 | 
            +
                  @bot.add_await(key, Discordrb::Events::MessageEvent, { in: @id }.merge(attributes), &block)
         | 
| 387 389 | 
             
                end
         | 
| 388 390 |  | 
| 389 391 | 
             
                def make_invite(max_age = 0, max_uses = 0, temporary = false, xkcd = false)
         | 
| @@ -420,7 +422,7 @@ module Discordrb | |
| 420 422 | 
             
                  @content = data['content']
         | 
| 421 423 | 
             
                  @author = User.new(data['author'], bot)
         | 
| 422 424 | 
             
                  @channel = bot.channel(data['channel_id'].to_i)
         | 
| 423 | 
            -
                  @timestamp = Time. | 
| 425 | 
            +
                  @timestamp = Time.parse(data['timestamp'])
         | 
| 424 426 | 
             
                  @id = data['id'].to_i
         | 
| 425 427 |  | 
| 426 428 | 
             
                  @mentions = []
         | 
| @@ -444,7 +446,7 @@ module Discordrb | |
| 444 446 |  | 
| 445 447 | 
             
                # Add an await for a message with the same user and channel
         | 
| 446 448 | 
             
                def await(key, attributes = {}, &block)
         | 
| 447 | 
            -
                  @bot.add_await(key, MessageEvent, { from: @author.id, in: @channel.id }.merge(attributes), &block)
         | 
| 449 | 
            +
                  @bot.add_await(key, Discordrb::Events::MessageEvent, { from: @author.id, in: @channel.id }.merge(attributes), &block)
         | 
| 448 450 | 
             
                end
         | 
| 449 451 |  | 
| 450 452 | 
             
                def from_bot?
         | 
| @@ -592,6 +594,8 @@ module Discordrb | |
| 592 594 | 
             
                  API.delete_server(@bot.token, @id)
         | 
| 593 595 | 
             
                end
         | 
| 594 596 |  | 
| 597 | 
            +
                alias_method :leave, :delete
         | 
| 598 | 
            +
             | 
| 595 599 | 
             
                def name=(name)
         | 
| 596 600 | 
             
                  update_server_data(name: name)
         | 
| 597 601 | 
             
                end
         | 
| @@ -0,0 +1,15 @@ | |
| 1 | 
            +
            module Discordrb
         | 
| 2 | 
            +
              # Logs debug messages
         | 
| 3 | 
            +
              class Logger
         | 
| 4 | 
            +
                attr_writer :debug
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                def debug(message, important = false)
         | 
| 7 | 
            +
                  puts "[DEBUG : #{Thread.current[:discordrb_name]} @ #{Time.now}] #{message}" if @debug || important
         | 
| 8 | 
            +
                end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                def log_exception(e)
         | 
| 11 | 
            +
                  debug("Exception: #{e.inspect}", true)
         | 
| 12 | 
            +
                  e.backtrace.each { |line| debug(line, true) }
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
              end
         | 
| 15 | 
            +
            end
         | 
    
        data/lib/discordrb/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: discordrb
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1.4. | 
| 4 | 
            +
              version: 1.4.4
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - meew0
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2015-12- | 
| 11 | 
            +
            date: 2015-12-18 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: faye-websocket
         | 
| @@ -128,6 +128,7 @@ files: | |
| 128 128 | 
             
            - lib/discordrb/exceptions.rb
         | 
| 129 129 | 
             
            - lib/discordrb/games.rb
         | 
| 130 130 | 
             
            - lib/discordrb/games_list.rb
         | 
| 131 | 
            +
            - lib/discordrb/logger.rb
         | 
| 131 132 | 
             
            - lib/discordrb/permissions.rb
         | 
| 132 133 | 
             
            - lib/discordrb/version.rb
         | 
| 133 134 | 
             
            - util/update_lists.rb
         |