class Twitchbot::Bot
Main Bot
class that we pass all bot account information to, as well as any plugins that should be used
Constants
- DEFAULT_EVENTS
The events that eventmachine dispatches to any plugins in use
- DEFAULT_PLUGINS
The built-in plugins to be used
- DEFAULT_URL
The connection URL for Twitch
Attributes
@return [Channel] The channel that the bot is connected to
@return [String] The prefix to use when defining and parsing commands e.g. +!+
@return [Boolean] Whether the bot should display debug info to STDOUT
@return [Array] The array of messages that are to be sent to the server
@return [String] Password of the bot account
@return [Array] The plugins that are in use by the bot
@return [String] Username of the bot account
Public Class Methods
Create a new Bot
instance, passing a block to set the necessary attributes to have the bot function
# File lib/twitchbot/bot.rb, line 44 def initialize @username = '' @password = '' @channel = '' @plugins = [] @message_queue = Queue.new @command_prefix = '!' yield self @channel = Channel.new(@channel) end
Public Instance Methods
Start the event loop, initiate the websocket client, and register the plugins with eventmachine
# File lib/twitchbot/bot.rb, line 59 def start EM.run do connection = Faye::WebSocket::Client.new DEFAULT_URL plugins = (@plugins << DEFAULT_PLUGINS).flatten!.reverse!.map! &:new DEFAULT_EVENTS.each do |default_event| connection.on(default_event) do |em_event| handler = EventHandler.new em_event, connection, self plugins.each do |plugin| plugin.send(default_event, handler) end end end end end