Class: Twitchbot::EventHandler
- Inherits:
-
Object
- Object
- Twitchbot::EventHandler
- Defined in:
- lib/twitchbot/event_handler.rb
Overview
Class responsible for handling the eventmachine event that is provided whenever an event is fired
Instance Attribute Summary collapse
-
#bot ⇒ Bot
readonly
The bot that the channel is a member of.
-
#connection ⇒ Faye::WebSocket::Client
readonly
The WebSocket client instance.
-
#messages ⇒ Array
readonly
The different messages received.
Instance Method Summary collapse
-
#initialize(event, connection, bot) ⇒ EventHandler
constructor
A new instance of EventHandler.
-
#message ⇒ Object
Method that provides a shortcut to grab the first message in an event handler.
-
#send_channel(message) ⇒ Object
Add a formatted channel message to the message queue.
-
#send_raw(message) ⇒ Object
Add a raw message to the message queue.
-
#send_whisper(user, message) ⇒ Object
Add a whisper to the specified user to the message queue.
Constructor Details
#initialize(event, connection, bot) ⇒ EventHandler
Returns a new instance of EventHandler.
14 15 16 17 18 19 20 21 22 23 24 25 |
# 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 |
Instance Attribute Details
#bot ⇒ Bot (readonly)
Returns The bot that the channel is a member of.
8 9 10 |
# File 'lib/twitchbot/event_handler.rb', line 8 def bot @bot end |
#connection ⇒ Faye::WebSocket::Client (readonly)
Returns The WebSocket client instance.
12 13 14 |
# File 'lib/twitchbot/event_handler.rb', line 12 def connection @connection end |
#messages ⇒ Array (readonly)
Returns The different messages received.
10 11 12 |
# File 'lib/twitchbot/event_handler.rb', line 10 def @messages end |
Instance Method Details
#message ⇒ Object
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
46 47 48 |
# File 'lib/twitchbot/event_handler.rb', line 46 def @messages.first end |
#send_channel(message) ⇒ Object
Add a formatted channel message to the message queue
33 34 35 |
# File 'lib/twitchbot/event_handler.rb', line 33 def send_channel() @bot..push("PRIVMSG ##{bot.channel.name} :#{}") end |
#send_raw(message) ⇒ Object
Add a raw message to the message queue
28 29 30 |
# File 'lib/twitchbot/event_handler.rb', line 28 def send_raw() @bot..push() end |
#send_whisper(user, message) ⇒ Object
Add a whisper to the specified user to the message queue
38 39 40 |
# File 'lib/twitchbot/event_handler.rb', line 38 def send_whisper(user, ) @bot..push("PRIVMSG #jtv :/w #{user} #{}") end |