Skip to content

Instantly share code, notes, and snippets.

@diegorv
Created March 12, 2009 17:16
Show Gist options
  • Select an option

  • Save diegorv/78178 to your computer and use it in GitHub Desktop.

Select an option

Save diegorv/78178 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rubygems'
require 'jabber/bot'
require "mysql"
# Create a public Jabber::Bot
bot = Jabber::Bot.new(
:name => "Robo",
:jabber_id => 'bot@dominio',
:password => 'eita',
:master => 'diego@dominio',
:presence => :chat,
:priority => 5,
:status => 'Olá, eu sou um robo, que vai lhe ajudar.',
:is_public => true
)
bot.add_command(
:syntax => 'acre',
:description => 'Conecta no mysql e faz algo',
:regex => /^acre/,
:is_public => true
) {
my = Mysql::new("127.0.0.1", "root", "root99", "sistema_busca_development")
res = my.query("select * from estados WHERE id = '1'")
while row = res.fetch_row do
var = row[1]
end
"Number of rows returned: #{var}"
}
# Give your bot a public command
bot.add_command(
:syntax => 'rand',
:description => 'Produce a random number from 0 to 10',
:regex => /^rand$/,
:is_public => true
) { rand(10).to_s }
# Manda uma mensagem para alguem
bot.add_command(
:syntax => 'msg',
:description => 'Manda uma mensagem para alguem',
:regex => /^msg\s+.+$/
) do |sender, message|
bot.deliver("#{message}@editoradominio", "Teste do robo")
end
# Menu de ajuda
bot.add_command(
:syntax => 'menu',
:description => 'Lista o menu',
:regex => /^menu/
) {
"------- Lista de comandos -------
help - para tal coisa
teta - pra tal coisa"
}
# Give your bot a private command with an alias
bot.add_command(
:syntax => 'puts <string>',
:description => 'Write something to $stdout',
:regex => /^puts\s+.+$/,
:alias => [
:syntax => 'p <string>',
:regex => /^p\s+.+$/
]
) do |sender, message|
puts "#{sender} says #{message}."
"'#{message}' written to $stdout."
end
# Bring your new bot to life
bot.connect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment