Skip to content

Instantly share code, notes, and snippets.

@futureperfect
Created February 19, 2009 06:07
Show Gist options
  • Save futureperfect/66753 to your computer and use it in GitHub Desktop.
Save futureperfect/66753 to your computer and use it in GitHub Desktop.
A Magic 8-Ball Jabber Bot
# Magic 8-ball Jabber bot
# Stupid pet tricks for your computer
# @author Erik Hollembeak
# Put in the same directory as the script a file called
# credentials.yaml with the credentials for the Jabber account
# you'd like the bot to use with the following syntax:
#
# username: yourusername@domain.com
# password: yourpassword
require 'rubygems'
require 'xmpp4r-simple'
require 'yaml'
messages = ["As I see it, yes",
"Ask again later",
"Better not tell you now",
"Cannot predict now",
"Concentrate and ask again",
"Don't count on it",
"It is certain",
"It is decidedly so",
"Most likely",
"My reply is no",
"My sources say no",
"Outlook good",
"Outlook not so good",
"Reply hazy, try again",
"Signs point to yes",
"Very doubtful",
"Without a doubt",
"Yes",
"Yes - definitely",
"You may rely on it"]
data = YAML::load(File.open('credentials.yaml'))
username = data['username']
password = data['password']
im = Jabber::Simple.new(username, password)
puts "Launching the Magic 8-ball"
while true
im.received_messages { |msg|
#process messages, reply to them, and print out the conversation
puts msg.from.node + ": " + msg.body if msg.type == :chat
reply = messages[rand(messages.length)]
puts "8-ball: " + reply
sleep(rand(5) + 3)
im.deliver(msg.from.to_s, reply)
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment