summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-09-20 13:49:19 +0000
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-09-20 13:49:19 +0000
commitaf0e4266eacd0d6df82b5dad0314fa0843ddff2f (patch)
tree10849b6bfb280135476427db9f30d87aae0fe98c
parent5ebe5c74cbc88ed6dec78860a646b8e077abefb2 (diff)
reaction plugin: it is now possible to change the chance of a reaction by 'adding' it again
-rw-r--r--data/rbot/plugins/reaction.rb49
1 files changed, 39 insertions, 10 deletions
diff --git a/data/rbot/plugins/reaction.rb b/data/rbot/plugins/reaction.rb
index 28d9f306..d495887d 100644
--- a/data/rbot/plugins/reaction.rb
+++ b/data/rbot/plugins/reaction.rb
@@ -16,16 +16,32 @@ class ::Reaction
attr_reader :raw_trigger, :raw_replies
class ::Reply
- attr_accessor :act, :reply, :pct, :range
- attr_accessor :author, :date, :channel
- def initialize(act, expr, pct, author, date, channel, range=nil)
+ attr_reader :act, :reply, :pct, :range
+ attr_reader :author, :date, :channel
+ attr_writer :date
+
+ def pct=(val)
+ @pct = val
+ @reaction.make_ranges
+ end
+
+ def author=(name)
+ @author = name.to_s
+ end
+
+ def channel=(name)
+ @channel = name.to_s
+ end
+
+ def initialize(reaction, act, expr, pct, author, date, channel)
+ @reaction = reaction
@act = act
@reply = expr
- @pct = pct
- @author = author.to_s
+ self.pct = pct
+ self.author = author
@date = date
- @channel = channel.to_s
- @range = range
+ self.channel = channel
+ debug self
end
def to_s
@@ -63,8 +79,13 @@ class ::Reaction
if rex.sub!(/^act:/,'')
act = true
end
- @replies << Reply.new(act ? :act : :reply, rex, *args)
- make_ranges
+ @replies << Reply.new(self, act ? :act : :reply, rex, *args)
+ debug @replies.last
+ return @replies.last
+ end
+
+ def find_reply(expr)
+ @replies[@raw_replies.index(expr)] rescue nil
end
def make_ranges
@@ -232,7 +253,15 @@ class ReactionPlugin < Plugin
@reactions << reaction
m.reply "Ok, I'll start reacting to #{reaction.raw_trigger}"
end
- reaction.add_reply(reply, pct, m.sourcenick, Time.now, m.channel)
+ found = reaction.find_reply(reply)
+ if found
+ found.pct = pct
+ found.author = m.sourcenick
+ found.date = Time.now
+ found.channel = m.channel
+ else
+ found = reaction.add_reply(reply, pct, m.sourcenick, Time.now, m.channel)
+ end
m.reply "I'll react to #{reaction.raw_trigger} with #{reaction.raw_replies.last} (#{(reaction.replies.last.pct * 100).to_i}%)"
end