Guest User

Untitled

a guest
Apr 25th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. #!/usr/bin/ruby
  2.  
  3. require 'rubygems'
  4. require 'IRC'
  5. require 'IRCConnection'
  6. require 'logger'
  7.  
  8. class EcBot < IRC
  9. attr_reader :log, :default_channel
  10.  
  11. def initialize(*args)
  12. super
  13. @log = Logger.new STDOUT
  14. end
  15. end
  16.  
  17. bot = EcBot.new("ecbot", "chat.freenode.net", "6667", "ecbot")
  18.  
  19.  
  20. IRCEvent.add_callback('endofmotd') do |event|
  21. bot.log.info 'Joining'
  22. bot.add_channel('#ecbot')
  23. end
  24.  
  25. IRCEvent.add_callback('join') do |event|
  26. bot.log.info "Joined #{event.channel}"
  27. unless event.from == bot.nick
  28. bot.send_message(event.channel, "Taste Dog, #{event.from}, It's Yummy!")
  29. end
  30. end
  31.  
  32. # privmsg keyword matching
  33. IRCEvent.add_callback('privmsg') do |event|
  34. bot.log.info "privmsg: #{event.message}"
  35. matches = event.message.scan /beef|pork|goat|chicken|avacado|pig|cow|duck|hamburger|steak/
  36. if matches.length > 0
  37. 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?"
  38. end
  39.  
  40. matches = event.message.scan /^\!(beg|botsnack)/
  41. if matches.length > 0
  42. bot.send_action(event.channel, "begs for a snausage. ")
  43. end
  44. matches = event.message.scan /^!suggest/
  45. if matches.length > 0
  46. bot.send_message(event.channel, "I'd try having a dog, I hear they taste great!")
  47. end
  48. end
  49.  
  50. IRCConnection.add_IO_socket(STDIN) {|sock|
  51. line = sock.readline.chomp
  52. bot.log.info "STDIN: #{line}"
  53. (command, channel, message) = line.split /\s*:\s*/, 3
  54. case command
  55. when "join"
  56. bot.join(channel)
  57. when "part"
  58. bot.part(channel)
  59. when "say"
  60. bot.send_message(channel, message)
  61. when "do"
  62. bot.send_action(channel, message + " ")
  63. when "help"
  64. puts "join:channel"
  65. puts "part:channel"
  66. puts "say:channel:message"
  67. puts "do:channel:action"
  68. end
  69. }
  70.  
  71. bot.connect
Add Comment
Please, Sign In to add comment