Created
April 18, 2009 02:51
-
-
Save atamis/97400 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/ruby | |
$factoids = { | |
"ping" => "pong" | |
} | |
def get_factoid(channel, msg) | |
msg = msg.downcase | |
# if $factoids[msg].exists? | |
puts "Factoid: #{$factoid[msg]}" | |
send("PRIVMSG #{channel} #{$factoids[msg]}") | |
# end | |
end |
This file contains 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
#/usr/bin/ruby | |
require "lib/dice.rb" | |
require "lib/toys.rb" | |
require "lib/inference.rb" | |
def proccess(nick, user, host, channel, msg) | |
msg = msg.split | |
puts "\"#{nick}\"" | |
case msg[0] | |
when /reload/ | |
if nick == "indigo747" | |
system("ruby hellfire_irc_bot.rb") | |
exit | |
else | |
puts "You are not my master! NO!" | |
send("PRIVMSG #{channel} Auth fail, nope, I'm not reloading.") | |
end | |
when /eval/ | |
string = msg[1..msg.length].join(" ") | |
if nick == "indigo747" | |
puts "Evaling #{string}" | |
send(string) | |
else | |
puts "Unauthenticated eval request by #{nick}" | |
send("PRIVMSG #{channel} #{nick}: no") | |
end | |
when /bofh/ | |
excuses = IO.readlines("data/excuses.txt") | |
out = excuses[rand(excuses.length)] | |
puts "--> BOFH excuse: #{out}" | |
send("PRIVMSG #{channel} #{nick}: #{out}") | |
when /version/ | |
puts "Somebody asking for version... #{$version.to_s}, by the way." | |
send("PRIVMSG #{channel} #{nick}: #{$version.to_s}") | |
when /time/ | |
puts "--> Time: #{Time.now}" | |
send("PRIVMSG #{channel} #{nick}: #{Time.now}") | |
# when /roll/ | |
# dice = Dice.new(msg[1]) | |
# out = dice.roll | |
# puts "--> Rolling dice: die string: #{msg[1]} result: #{out}" | |
# send "PRIVMSG #{channel} #{nick}: #{out}" | |
when /dong/ | |
puts "Donging" | |
get_dong.times do |n| | |
# print (n+1).to_s + ": " | |
puts "--> DONG!" | |
send("PRIVMSG #{channel} DONG!") | |
end | |
when /say/ | |
output = msg[1..msg.length].join(" ") | |
puts "--> saying #{output}" | |
send("PRIVMSG #{channel} #{nick}: #{output}") | |
when /join/ | |
if nick == "indigo747" | |
puts "--> Joining #{msg[1]}" | |
send "JOIN #{msg[1]}" | |
else | |
puts "--> Authentication fail" | |
send "PRIVMSG #{channel} You aren't my master! I don't take orders from you!" | |
end | |
when /word/ | |
word = get_random_word | |
puts "--> Sending word: #{word}" | |
send("PRIVMSG #{channel} #{nick}: #{word}") | |
when /roll/ | |
result = RollDice.new(msg[1]) | |
result = result.roll | |
puts "--> Rolling die. String: #{msg[1]} Result: #{result}" | |
send("PRIVMSG #{channel} #{nick} rolled a #{result}") | |
when /shoot/ | |
$weapon.shoot(nick, msg[1], channel) | |
when /name/ | |
name = MakeName.new | |
puts "--> Generated name: #{name.result}" | |
send("PRIVMSG #{channel} #{nick}: #{name.result}") | |
# when /inf/ | |
# output = $engine.proccess(msg[1..msg.length].join(" ")) | |
# puts "Inference engine: saying #{output}" | |
# send("PRIVMSG #{channel} #{nick}: #{output}") | |
else | |
# out = "#{nick} said \"#{msg.join(" ")}\", but I'm not sure what that means. Are you going to teach me that, indigo747?" | |
# puts "Debug--> #{out}" | |
# send("PRIVMSG #{channel} #{out}") | |
puts "Unknown command. From: #{nick}!#{user}@#{host} Channel: #{channel} Msg: #{msg.join(" ")}" | |
end | |
end | |
def public_proccess(nick, user, host, channel, msg) | |
msg = msg.split | |
case msg[0] | |
when /botsnack/ | |
puts "--> BOTSNACK!" | |
send "PRIVMSG #{channel} ::D" | |
$botsnacks += 1 | |
when /bofh/ | |
excuses = IO.readlines("data/excuses.txt") | |
out = excuses[rand(excuses.length)] | |
puts "--> BOFH excuse: #{out}" | |
send("PRIVMSG #{channel} #{out}") | |
when /botsnacks/ | |
puts "Somebody asking for the # of botsnacks, #{$botsnacks}, by the way" | |
send "PRIVMSG #{channel} I have gorged myself on #{$botsnacks} botsnack(s) since I was last restarted. Maybe someday I could have a file that said exactly how many botsnacks I had had in my lifetime! Wouldn't that be cool!" | |
end | |
end | |
def init | |
puts "Init is working." | |
$botsnacks = 0 | |
$weapon = Weapon.new("missile") | |
$engine = Inference.new | |
end |
This file contains 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
#!/usr/bin/ruby | |
$version = 0.1 | |
require "socket" | |
require 'lib/irc' | |
require 'lib/general.rb' | |
require 'lib/toys.rb' | |
require 'lib/roll.rb' | |
require 'lib/inference.rb' | |
# Configuration variables: | |
server = "irc.foonetic.net" | |
nick = "RBHellfire" | |
channel = ["#bots"] | |
port = 6667 # You mostly won't need to change this | |
# Don't allow use of "tainted" data by potentially dangerous operations | |
$SAFE=0 | |
# The main program | |
# If we get an exception, then print it out and keep going (we do NOT want | |
# to disconnect unexpectedly!) | |
irc = IRC.new(server, port, nick, channel) | |
irc.connect() | |
begin | |
irc.main_loop() | |
rescue Interrupt | |
rescue Exception => detail | |
puts detail.message() | |
print detail.backtrace.join("\n") | |
retry | |
end |
This file contains 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
#!/usr/bin/ruby | |
require 'lib/factoid' | |
class IRC | |
def initialize(server, port, nick, channel) | |
@server = server | |
@port = port | |
@nick = nick | |
@channel = channel | |
init | |
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 #{@nick} #{@nick} #{@nick} :Owned by indigo747" | |
send "NICK #{@nick}" | |
send "MODE #{@nick} +B" | |
# send "JOIN #{@channel}" | |
end | |
def evaluate(s) | |
# Make sure we have a valid expression (for security reasons), and | |
# evaluate it if we do, otherwise return an error message | |
if s =~ /^[-+*\/\d\s\eE.()]*$/ then | |
begin | |
s.untaint | |
return eval(s).to_s | |
rescue Exception => detail | |
puts detail.message() | |
end | |
end | |
return "Error" | |
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 /^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" | |
when /^:(.+?)!(.+?)@(.+?)\sPRIVMSG\s(.+)\s:EVAL (.+)$/i | |
puts "[ EVAL #{$5} from #{$1}!#{$2}@#{$3} ]" | |
send "PRIVMSG #{(($4==@nick)?$1:$4)} :#{evaluate($5)}" | |
when /^:(.+?)!(.+?)@(.+?)\sPRIVMSG\s(.+)\s:>(.+)$/i | |
proccess($1, $2, $3, $4, $5) | |
when /^:(.+?)!(.+?)@(.+?)\sPRIVMSG\s(.+)\s:RBHellfire: (.+)$/i | |
proccess($1, $2, $3, $4, $5) | |
# when /^:(.+?)!(.+?)@(.+?)\sPRIVMSG\s(.+)\s:(.+)$/i | |
# public_proccess($1, $2, $3, $4, $5) | |
when /^:(.+?)!(.+?)@(.+?)\sPRIVMSG\s(.+)\s:FACTOID: (.+)$/i | |
get_factoid($4, $5) | |
when /End of \/MOTD/ | |
@channel.each { |c| send("JOIN #{c}") } | |
else | |
puts s | |
end | |
end | |
def main_loop() | |
# Just keep on truckin' until we disconnect | |
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 |
This file contains 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
#!/usr/bin/ruby | |
def get_random_word | |
words = IO.readlines("/usr/share/dict/american-english") | |
return words[rand(words.length)] | |
end | |
def get_dong | |
time = Time.now.hour | |
time -= 12 if time > 12 | |
return time | |
end | |
class Weapon | |
attr_reader :type | |
attr_writer :type | |
def initialize(type) | |
@type = type | |
@ammo = 50 | |
end | |
def reload(channel) | |
@ammo = 50 | |
puts "--> Reloading with type: #{@type}" | |
send("PRIVMSG #{channel} Reloaded") | |
end | |
def shoot(shootee, shooter, channel) | |
@ammo -= 1 | |
puts "--> #{shooter} shot #{shootee} on #{channel}" | |
send("PRIVMSG #{channel} #{shooter} shoots #{shootee} with #{@type} (ammo: #{@ammo.to_s})") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment