Class: Twitchbot::ChannelPlugin

Inherits:
Object
  • Object
show all
Includes:
Plugin
Defined in:
lib/twitchbot/plugin/channel_plugin.rb

Overview

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)

Constant Summary

Constants included from Plugin

Plugin::COMMANDS

Instance Method Summary collapse

Methods included from Plugin

#close, #error, included, #message, #open

Instance Method Details

#join_channel(handler) ⇒ Object

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


17
18
19
# 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) ⇒ Object

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

> :<user>!<user>@<user>.tmi.twitch.tv JOIN #<channel>


25
26
27
28
29
30
31
32
33
# 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) ⇒ Object

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

> :<user>!<user>@<user>.tmi.twitch.tv PART #<channel>


40
41
42
43
44
45
46
47
48
# 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