Created
May 9, 2011 13:55
-
-
Save gsathya/962553 to your computer and use it in GitHub Desktop.
Polkabot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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