Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/ruby
- require 'rubygems'
- require 'IRC'
- require 'IRCConnection'
- require 'logger'
- class EcBot < IRC
- attr_reader :log, :default_channel
- def initialize(*args)
- super
- @log = Logger.new STDOUT
- end
- end
- bot = EcBot.new("ecbot", "chat.freenode.net", "6667", "ecbot")
- IRCEvent.add_callback('endofmotd') do |event|
- bot.log.info 'Joining'
- bot.add_channel('#ecbot')
- end
- IRCEvent.add_callback('join') do |event|
- bot.log.info "Joined #{event.channel}"
- unless event.from == bot.nick
- bot.send_message(event.channel, "Taste Dog, #{event.from}, It's Yummy!")
- end
- end
- # privmsg keyword matching
- IRCEvent.add_callback('privmsg') do |event|
- bot.log.info "privmsg: #{event.message}"
- matches = event.message.scan /beef|pork|goat|chicken|avacado|pig|cow|duck|hamburger|steak/
- if matches.length > 0
- bot.send_message event.channel, "What? How can you possibly mention the \'#{(matches[0].split(//))[0]}\' word when theres a tasty tasty dog on the grill?"
- end
- matches = event.message.scan /^\!(beg|botsnack)/
- if matches.length > 0
- bot.send_action(event.channel, "begs for a snausage. ")
- end
- matches = event.message.scan /^!suggest/
- if matches.length > 0
- bot.send_message(event.channel, "I'd try having a dog, I hear they taste great!")
- end
- end
- IRCConnection.add_IO_socket(STDIN) {|sock|
- line = sock.readline.chomp
- bot.log.info "STDIN: #{line}"
- (command, channel, message) = line.split /\s*:\s*/, 3
- case command
- when "join"
- bot.join(channel)
- when "part"
- bot.part(channel)
- when "say"
- bot.send_message(channel, message)
- when "do"
- bot.send_action(channel, message + " ")
- when "help"
- puts "join:channel"
- puts "part:channel"
- puts "say:channel:message"
- puts "do:channel:action"
- end
- }
- bot.connect
Add Comment
Please, Sign In to add comment