Skip to content

Instantly share code, notes, and snippets.

@Elevina
Created January 10, 2011 20:17
Show Gist options
  • Save Elevina/773377 to your computer and use it in GitHub Desktop.
Save Elevina/773377 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/ruby
require 'socket'
class IRC
def initialize(server, port, channel)
@channel = channel
@nick = "Ulla"
@socket = TCPSocket.open(server, port)
nick "Ulla"
send "USER #{@nick} 0 * #{@nick}"
join_channel(@channel)
end
def send(s)
puts "--> #{s}"
@irc.send "#{s}\n", 0
end
def join_channel(channel)
send "JOIN ##{channel}"
end
def nick(nick)
@nick = "#{nick}"
send "NICK #{@nick}"
end
def send(msg)
puts msg
@socket.puts msg
end
def send_to_channel(channel, msg, person)
send "PRIVMSG ##{channel} :#{msg} #{person}"
end
def perform_mode(channel, flags, person)
send "MODE ##{channel} #{flags} #{person}"
end
def run
until @socket.eof? do
msg = @socket.gets
puts msg
if msg.match(/^PING :(.*)$/)
send "PONG #{$~[1]}"
next
end
if msg.match(/INVITE #{@nick} :#(.*)$/)
content = $~[1]
join_channel(content)
send_to_channel(content, "But i dont wanna")
end
if msg.match(/PRIVMSG ##{@channel} :(.*)$/)
content = $~[1]
if content.match(/Gailor/)
send_to_channel(content, "Sailor you faggot")
end
if content.match(/!op/)
_,pers = content.split(' ')
perform_mode(@channel, 'o', pers)
end
if content.match(/!deop/)
_,pers = content.split(' ')
perform_mode(@channel, '-o', pers)
end
if content.match(/!voice/)
_,pers = content.split(' ')
perform_mode(@channel, 'v', pers)
end
if content.match(/!devoice/)
_,pers = content.split(' ')
perform_mode(@channel, '-v', pers)
end
if content.match(/!say/)
_,content = content.split(' ', 2)
send_to_channel(@channel, "#{content}")
end
if content.match(/!do/)
_,content = content.split(' ', 2)
end
if content.match(/!kick/)
_,person = content.split(' ')
send "KICK ##{@channel} #{person} Die!"
end
if content.match(/!ban/)
_,pers = content.split(' ')
_,person = content.split(' ')
perform_mode(@channel, '+b', pers)
send "KICK ##{@channel} #{person} Banned."
end
if content.match(/!unban/)
_,pers = content.split(' ')
perform_mode(@channel, '-b', pers)
end
if content.match(/!die/)
send "QUIT ##{@channel}"
end
end
end
end
def quit
send "PART ##{@channel} :Bye"
end
end
bot = IRC.new('irc.pantheonserver.com', 6667, 'test')
interrupted = false
trap("INT"){ interrupted = true }
if interrupted
bot.quit
end
bot.run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment