module Twitchbot::WhisperPlugin

Constants

COMMANDS

Public Class Methods

included(klass) click to toggle source

Define a class method called register on each class that includes this module, which allows the user to add methods to the COMMANDS constant

def self.register(command:, method:)
  COMMANDS[base] = {} if COMMANDS[base].nil?
  COMMANDS[base][params[:command]] = params[:method]
end
# File lib/twitchbot/whisper_plugin.rb, line 39
def self.included(klass)
  klass.instance_eval do
    define_singleton_method 'register' do |params|
      COMMANDS[klass] = {} if COMMANDS[klass].nil?
      COMMANDS[klass][params[:command]] = params[:method]
    end
  end
end

Public Instance Methods

close(handler) click to toggle source

Method that can be overriden to react to the eventmachine :close event

# File lib/twitchbot/whisper_plugin.rb, line 30
def close(handler) end
error(handler) click to toggle source

Method that can be overriden to react to the eventmachine :error event

# File lib/twitchbot/whisper_plugin.rb, line 27
def error(handler) end
message(handler) click to toggle source
# File lib/twitchbot/whisper_plugin.rb, line 9
def message(handler)
  handler.messages.each do |message|
    if message.whisper?
      # TODO: Extract this block from WhisperPlugin and MessagePlugin
      prefix = handler.bot.command_prefix
      _, _command, arguments = message.payload.partition(
          /#{Regexp.escape prefix}\S+/
      )
      command = _command.delete prefix
      commands = COMMANDS[self.class]
      if !command.nil? && !commands[command].nil?
        send(commands[command], message, arguments.lstrip)
      end
    end
  end
end
open(handler) click to toggle source

Method that can be overriden to react to the eventmachine :open event

# File lib/twitchbot/whisper_plugin.rb, line 7
def open(handler) end