class Twitchbot::EventHandler

Class responsible for handling the eventmachine event that is provided whenever an event is fired

Attributes

bot[R]

@return [Bot] The bot that the channel is a member of

connection[R]

@return [Faye::WebSocket::Client] The WebSocket client instance

messages[R]

@return [Array] The different messages received

Public Class Methods

new(event, connection, bot) click to toggle source
# File lib/twitchbot/event_handler.rb, line 14
def initialize(event, connection, bot)
  @connection = connection
  @bot = bot

  if event.respond_to? :data
    @chunks = event.data.split "\n"
    @messages = []
    @chunks.each do |chunk|
      @messages << Message.new(self, chunk.chomp)
    end
  end
end

Public Instance Methods

message() click to toggle source

Method that provides a shortcut to grab the first message in an event handler. We can typically use this after authenticating, but there is no guarantee that twitch will not send multiple 'messages' in a single :message event

# File lib/twitchbot/event_handler.rb, line 46
def message
  @messages.first
end
send_channel(message) click to toggle source

Add a formatted channel message to the message queue

# File lib/twitchbot/event_handler.rb, line 33
def send_channel(message)
  @bot.message_queue.push("PRIVMSG ##{bot.channel.name} :#{message}")
end
send_raw(message) click to toggle source

Add a raw message to the message queue

# File lib/twitchbot/event_handler.rb, line 28
def send_raw(message)
  @bot.message_queue.push(message)
end
send_whisper(user, message) click to toggle source

Add a whisper to the specified user to the message queue

# File lib/twitchbot/event_handler.rb, line 38
def send_whisper(user, message)
  @bot.message_queue.push("PRIVMSG #jtv :/w #{user} #{message}")
end