class Twitchbot::ChannelPlugin

Plugin to handle joining the specified channel, as well as maintaining a list of users who have joined or left the channel

TODO: Handle 353 and 366 (NAMES list)

Public Instance Methods

join_channel(handler) click to toggle source

Listen for the response from AuthPlugin#request_caps and request to join the channel

> :tmi.twitch.tv CAP * ACK :twitch.tv/tags twitch.tv/commands twitch.tv/membership
# File lib/twitchbot/plugin/channel_plugin.rb, line 17
def join_channel(handler)
  handler.send_raw "JOIN ##{handler.bot.channel.name}"
end
process_join(handler) click to toggle source

Listen for any JOIN commands and add the user to the channel user list

> :<user>!<user>@<user>.tmi.twitch.tv JOIN #<channel>
# File lib/twitchbot/plugin/channel_plugin.rb, line 25
def process_join(handler)
  channel = handler.bot.channel
  handler.messages.each do |message|
    /:(?<sender>\w+)/ =~ message.raw
    unless channel.users.key? sender
      channel.users[sender] = User.new sender
    end
  end
end
process_part(handler) click to toggle source

Listen for any PART commands and remove the user from the channel user list

> :<user>!<user>@<user>.tmi.twitch.tv PART #<channel>
# File lib/twitchbot/plugin/channel_plugin.rb, line 40
def process_part(handler)
  channel = handler.bot.channel
  handler.messages.each do |message|
    /:(?<sender>\w+)/ =~ message.raw
    if channel.users.key? sender
      channel.users.delete sender
    end
  end
end