+ trigger = params[:trigger].to_s
+ reply = params[:reply].to_s
+
+ pct = params[:chance] || "1"
+ if pct.sub!(/%$/,'')
+ pct = (pct.to_f/100).clip(0,1)
+ else
+ pct = pct.to_f.clip(0,1)
+ end
+
+ new_reaction = false
+
+ reaction = find_reaction(trigger)
+ if not reaction
+ reaction = Reaction.new(trigger)
+ @reactions << reaction
+ new_reaction = true
+ end
+
+ found = reaction.find_reply(reply)
+ if found
+ # ruby replies need special permission
+ if can_add?(m, found)
+ found.pct = pct
+ found.author = m.sourcenick
+ found.date = Time.now
+ found.channel = m.channel
+ else
+ m.reply _("Sorry, you're not allowed to change %{act} replies here") % {
+ :act => found.act
+ }
+ return
+ end
+ else
+ found = reaction.add_reply(reply, pct, m.sourcenick, Time.now, m.channel)
+ unless can_add?(m, found)
+ m.reply _("Sorry, you're not allowed to add %{act} replies here") % {
+ :act => found.act
+ }
+ reaction.rm_reply(reaction.replies.length)
+ if new_reaction
+ @reactions.delete(reaction)
+ end
+ return
+ end
+ end
+
+ if new_reaction
+ m.reply "Ok, I'll start reacting to #{reaction.raw_trigger}"
+ end
+ m.reply "I'll react to #{reaction.raw_trigger} with #{reaction.raw_replies.last} (#{(reaction.replies.last.pct * 100).to_i}%)"
+ end
+
+ def handle_move(m, params)
+ source = params[:source].to_s
+ dest = params[:dest].to_s
+ found = find_reaction(source)
+ if not found
+ m.reply "I don't react to #{source}"
+ return
+ end
+ if find_reaction(dest)
+ m.reply "I already react to #{dest}, so I won't move #{source} to #{dest}"
+ return
+ end
+ found.trigger=dest
+ m.reply "Ok, I'll react to #{found.raw_trigger} now"