Skip to content

Instantly share code, notes, and snippets.

@bastos
Created September 18, 2008 14:36
Show Gist options
  • Save bastos/11434 to your computer and use it in GitHub Desktop.
Save bastos/11434 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/ruby
#Just a joke!
require "socket"
# Don't allow use of "tainted" data by potentially dangerous operations
$SAFE=1
NICK_REGEX = "[a-zA-Z][a-zA-Z0-9\\-_\\[\\]\\{\\}\\\\|`\\^]+"
prefixo = ["Meu, ","No mercado vertical mano","Lá em Sampa meu,","Aê Fio","Po meu", "Um amigo chegou pra mim e falou Edu,", "Ahhh, de boa?", "Tá me tirando, fio?"]
pessoas = ["Adóbe","Mina", "Mano"]
adjetivos = ["paluda", "de boa",""]
verbos = ["usaaa","faz","tem"]
coisas = ["flex","Subverziôun","jruby","flash","ruby EN rails","select WALL", "code COMPLETATION"]
sufixo = ["de boa", "aaahhh", "de boa aê", "fio", "mano", "aê", "e esse monitor é meu mano", "e terminei minha *ichue* valeu"]
$frases = []
#Stupid code, fix it later...
prefixo.each { |pr|
pessoas.each { |p|
adjetivos.each { |a|
verbos.each { |v|
coisas.each { |c|
sufixo.each { |s|
$frases << "#{pr} #{p} #{a} #{v} #{c} #{s}"
}
}
}
}
}
}
module Edu
def self.say_something(texto="")
return "Iiii vai demorar 2 semanas..." if texto =~ /^faz/
return "De boa aê!" if texto =~ /^De boa\?/
return "Bom dia aê" if texto =~ /^bom dia/
return "Boa tarde aê fio" if texto =~ /^boa tarde/
return "Flex aê!" if texto =~ /flex/
return "Eu adoro dance aê" if texto =~ /(m?sica)|(musica)/
frase = $frases.detect {|el| el =~ /#{texto}/ }
if frase and texto != ""
return frase
else
return $frases[rand($frases.size)]
end
end
end
# The irc class, which talks to the server and holds the main event loop
class IRC
def initialize(server, port, nick, channel)
@server = server
@port = port
@nick = nick
@channel = channel
end
def send(s)
# Send a message to the irc server and print it to the screen
puts "--> #{s}"
@irc.send "#{s}\n", 0
end
def connect()
# Connect to the IRC server
@irc = TCPSocket.open(@server, @port)
send "USER blah blah blah :blah blah"
send "NICK #{@nick}"
send "JOIN #{@channel}"
send "PRIVMSG #{@channel} :De boa? A adobe me mandou um computador, um iphone e uma caixa de KY"
end
def handle_server_input(s)
# This isn't at all efficient, but it shows what we can do with Ruby
# (Dave Thomas calls this construct "a multiway if on steroids")
case s.strip
when /jruby/i
send "PRIVMSG #{@channel} :JJJJJRUUUBEEE A Adobe usa"
when /^:(#{NICK_REGEX})!(\S+?)@(\S+?)\s+([A-Z]+)\s+(.*?)\s+:(#{NICK_REGEX})[,:]\s+(.*?)[\r\n]*$/
send "PRIVMSG #{$5} :#{Edu.say_something($7)}" if $6 == @nick
when /^PING :(.+)$/i
puts "[ Server ping ]"
send "PONG :#{$1}"
when /^:(.+?)!(.+?)@(.+?)\sPRIVMSG\s.+\s:[\001]PING (.+)[\001]$/i
puts "[ CTCP PING from #{$1}!#{$2}@#{$3} ]"
send "NOTICE #{$1} :\001PING #{$4}\001"
when /^:(.+?)!(.+?)@(.+?)\sPRIVMSG\s.+\s:[\001]VERSION[\001]$/i
puts "[ CTCP VERSION from #{$1}!#{$2}@#{$3} ]"
send "NOTICE #{$1} :\001VERSION Ruby-irc v0.042\001"
else
puts s
end
end
def main_loop()
while true
ready = select([@irc, $stdin], nil, nil, nil)
next if !ready
for s in ready[0]
if s == $stdin then
return if $stdin.eof
s = $stdin.gets
send s
elsif s == @irc then
return if @irc.eof
s = @irc.gets
handle_server_input(s)
end
end
end
end
end
irc = IRC.new('ip', 6667, 'nick', '#channel')
irc.connect()
begin
irc.main_loop()
rescue Interrupt
rescue Exception => detail
puts detail.message()
print detail.backtrace.join("\n")
retry
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment