Skip to content

Instantly share code, notes, and snippets.

@gsathya
Created May 9, 2011 13:55
Show Gist options
  • Save gsathya/962553 to your computer and use it in GitHub Desktop.
Save gsathya/962553 to your computer and use it in GitHub Desktop.
Polkabot
require 'socket'
require 'Plugin'
module Bot
class Polkabot < Plugin
def initialize(server,port,nick,channel)
@server = server
@port = port
@socket = TCPSocket.open(@server, @port)
@nick = nick
@channel = channel
say "NICK #{@nick}"
say "USER #{@nick} 0 * #{@nick}"
say "JOIN ##{@channel}"
say "PRIVMSG ##{@channel} : All hail gsathya"
end
def say(msg)
puts msg
@socket.puts msg
end
def parse(msg)
match msg,@channel
rescue LocalJumpError
puts "Local Jump Error"
end
def die
say "PART ##{@channel}"
say 'QUIT'
@socket.close
end
def run
until @socket.eof? do
msg = @socket.gets.strip
puts msg
parse msg
end
rescue IOError
puts "Flush Socket"
end
end
end
require 'bot'
module Bot
class Bye < Polkabot
def execute(msg,username,channel)
if msg.match('polkabot[:,] (bye|Bye|ciao|Ciao)$') then
puts msg
say "PRIVMSG ##{channel} :#{username}, Ciao"
end
end
end
end
require 'bot'
module Bot
def self.letItRip
polkabot = Polkabot.new('irc.freenode.net',6667,'polkabot','ceglug')
polkabot.run
trap("INT"){ polkabot.quit }
end
end
if __FILE__ == $0
Bot.letItRip
end
require 'Quit'
require 'Hello'
require 'Bye'
module Bot
class Plugin
def match(msg,channel)
@username = msg.match("(:)(.*)(!)").to_s.delete(':!')
puts @username
Bye.new.execute msg,@username,channel
# %w[Quit Hello Bye].map {|plugin| plugin.new.execute msg,@username}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment