+
+ 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