Skip to content

Instantly share code, notes, and snippets.

@hugoferreira
Created April 18, 2011 22:26
Show Gist options
  • Save hugoferreira/926374 to your computer and use it in GitHub Desktop.
Save hugoferreira/926374 to your computer and use it in GitHub Desktop.
FEUP Bot
#!/usr/bin/env ruby
require 'socket'
class SimpleIrcBot
def initialize(server, port, channel)
@channel = channel
@socket = TCPSocket.open(server, port)
say "NICK BytterBot"
say "USER BytterBot 0 * BytterBot"
say "JOIN ##{@channel}"
say_to_chan "#{1.chr}ACTION is here to help#{1.chr}"
end
def say(msg)
puts msg
@socket.puts msg
end
def say_to_chan(msg)
say "PRIVMSG ##{@channel} :#{msg}"
end
def run
until @socket.eof? do
msg = @socket.gets
puts msg
if msg.match(/^PING :(.*)$/)
say "PONG #{$~[1]}"
next
end
if msg.match(/PRIVMSG ##{@channel} :(.*)$/)
content = $~[1]
#put matchers here
if content.match()
say_to_chan('your response')
end
end
end
end
def quit
say "PART ##{@channel} :Daisy, Daisy, give me your answer do"
say 'QUIT'
end
end
bot = SimpleIrcBot.new("irc.freenode.net", 6667, 'FEUP')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment