lib/twitch/bot/adapter/irc.rb in twitch-bot-5.0.1 vs lib/twitch/bot/adapter/irc.rb in twitch-bot-5.0.2
- old
+ new
@@ -7,10 +7,11 @@
module Adapter
# Handle the bot's IRC connection
class Irc
def initialize(client:)
@client = client
+ @channel = nil
open_socket
end
def connect
@@ -27,30 +28,30 @@
irc_message = IrcMessage.new(raw_message)
Twitch::Bot::MessageParser.new(irc_message).message
end
def send_message(text)
- privmsg = "PRIVMSG ##{channel.name} :#{text}"
+ privmsg = "PRIVMSG ##{@channel.name} :#{text}"
send_data(privmsg)
end
def send_data(data)
send_data_to_socket(data)
end
- def join_channel(channel)
- @channel = channel
- send_data "JOIN ##{channel.name}"
+ def join_channel(channel_object)
+ @channel = channel_object
+ send_data "JOIN ##{@channel.name}"
end
def part_channel
- send_data "PART ##{channel.name}"
+ send_data "PART ##{@channel.name}" if @channel
@channel = nil
end
private
- attr_reader :socket, :client, :channel
+ attr_reader :socket, :client
def open_socket
@socket = ::TCPSocket.new(
client.config.setting("irc_hostname") || "irc.chat.twitch.tv",
client.config.setting("irc_port") || 6667,