- reaction = Reaction.new(params[:trigger].to_s, params[:reply].to_s, m.sourcenick, Time.now, m.channel)
- @reactions << reaction
- m.reply "added reaction to #{reaction.trigger.last} with #{reaction.reply.last}"
+ 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
+
+ reaction = find_reaction(trigger)
+ if not reaction
+ reaction = Reaction.new(trigger)
+ @reactions << reaction
+ m.reply "Ok, I'll start reacting to #{reaction.raw_trigger}"
+ end
+ 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
+
+ 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"