Permalink
Browse files

Jokes are stored per channel.

  • Loading branch information...
wilkie committed Feb 7, 2012
1 parent 20e6513 commit 5e1415cce0ee4f356ce7416972edb157550eda43
Showing with 9 additions and 7 deletions.
  1. +9 −7 lib/xombot/plugins/joke.rb
View
@@ -7,6 +7,8 @@ class Joke < XOmBot::Plugin
def initialize *args
@agent = Mechanize.new
+ @joke = {}
+ @answer = {}
super *args
end
@@ -23,25 +25,25 @@ def tell_joke(m)
page = @agent.get "#{JOKE_DOMAIN}/#{JOKE_ACTIONS[:joke]}"
joke_div = page.search '//div[@class="jokermediumtext"]'
- @joke = nil
- @answer = nil
+ @joke[m.channel] = nil
+ @answer[m.channel] = nil
# The joke and answer are separated by <br/>, so just
# enumerate the text of the div.
joke_div.first.children.each do |c|
if c.text?
- if @joke.nil?
- @joke = c.content
+ if @joke[m.channel].nil?
+ @joke[m.channel] = c.content
else
- @answer = c.content.chop
+ @answer[m.channel] = c.content.chop
end
end
end
- m.reply @joke
+ m.reply @joke[m.channel]
end
def tell_answer(m)
- m.reply "#{@answer}! Oh ho ho ho... brains."
+ m.reply "#{@answer[m.channel]}! Oh ho ho ho... brains."
end
end

0 comments on commit 5e1415c

Please sign in to comment.