summaryrefslogtreecommitdiff
path: root/data/rbot/plugins/reaction.rb
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-09-19 20:45:32 +0000
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-09-19 20:45:32 +0000
commit691a1facca9ed3e9bdc8e5cbbfb4a48f3354d2e2 (patch)
tree47fd6baef304102c9dbc0e6dc520b7da0db8923d /data/rbot/plugins/reaction.rb
parent0596e4655c70532c2c0a746c6b471bf1070b93db (diff)
reaction plugin: check for existing reaction when adding a new one
Diffstat (limited to 'data/rbot/plugins/reaction.rb')
-rw-r--r--data/rbot/plugins/reaction.rb19
1 files changed, 15 insertions, 4 deletions
diff --git a/data/rbot/plugins/reaction.rb b/data/rbot/plugins/reaction.rb
index 46237361..9b0d546a 100644
--- a/data/rbot/plugins/reaction.rb
+++ b/data/rbot/plugins/reaction.rb
@@ -146,8 +146,21 @@ class ReactionPlugin < Plugin
m.__send__(*args)
end
+ def find_reaction(trigger)
+ @reactions.find { |react|
+ react.raw_trigger == trigger
+ }
+ end
+
def handle_add(m, params)
- reaction = Reaction.new(params[:trigger].to_s, params[:reply].to_s, m.sourcenick, Time.now, m.channel)
+ trigger = params[:trigger].to_s
+ reply = params[:reply].to_s
+ if find_reaction(trigger)
+ m.reply "there's already a reaction to #{trigger}"
+ return
+ end
+
+ reaction = Reaction.new(trigger, reply, m.sourcenick, Time.now, m.channel)
@reactions << reaction
m.reply "added reaction to #{reaction.trigger.last} with #{reaction.reply.last}"
end
@@ -155,9 +168,7 @@ class ReactionPlugin < Plugin
def handle_rm(m, params)
trigger = params[:trigger].to_s
debug trigger.inspect
- found = @reactions.find { |react|
- react.raw_trigger == trigger
- }
+ found = find_reaction(trigger)
if found
@reactions.delete(found)
m.reply "removed reaction to #{found.trigger.last} with #{found.reply.last}"