From 8b3890935d2880cf488b520a8a5c24a63855684b Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Wed, 31 Oct 2007 21:25:33 +0000 Subject: [PATCH] reaction plugin: collect trigger syntax into a single regexp --- data/rbot/plugins/reaction.rb | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/data/rbot/plugins/reaction.rb b/data/rbot/plugins/reaction.rb index f65c4b1a..0714029c 100644 --- a/data/rbot/plugins/reaction.rb +++ b/data/rbot/plugins/reaction.rb @@ -139,6 +139,10 @@ class ReactionPlugin < Plugin ADD_SYNTAX = 'react to *trigger with *reply [at :chance chance]' MOVE_SYNTAX = 'reaction move *source to *dest' + # We'd like to use backreferences for the trigger syntax + # but we can't because it will be merged with the Plugin#map() + # regexp + TRIGGER_SYNTAX = /^(?:act:)?(?:!.*?!|\/.*?\/|".*?"|'.*?')/ def add_syntax return ADD_SYNTAX @@ -148,6 +152,10 @@ class ReactionPlugin < Plugin return MOVE_SYNTAX end + def trigger_syntax + return TRIGGER_SYNTAX + end + attr :reactions def initialize @@ -349,13 +357,7 @@ end plugin = ReactionPlugin.new plugin.map plugin.add_syntax, :action => 'handle_add', - :requirements => { :trigger => /^(?:act:)?!.*?!/ } -plugin.map plugin.add_syntax, :action => 'handle_add', - :requirements => { :trigger => /^(?:act:)?\/.*?\// } -plugin.map plugin.add_syntax, :action => 'handle_add', - :requirements => { :trigger => /^(?:act:)?".*?"/ } -plugin.map plugin.add_syntax, :action => 'handle_add', - :requirements => { :trigger => /^(?:act:)?'.*?'/ } + :requirements => { :trigger => plugin.trigger_syntax } plugin.map plugin.add_syntax.sub('*', ':'), :action => 'handle_add' plugin.map 'reaction list [:page]', :action => 'handle_list', @@ -364,13 +366,10 @@ plugin.map 'reaction list [:page]', :action => 'handle_list', plugin.map 'reaction show *trigger', :action => 'handle_show' plugin.map plugin.move_syntax, :action => 'handle_move', - :requirements => { :source => /^(?:act:)?!.*?!/ } -plugin.map plugin.move_syntax, :action => 'handle_move', - :requirements => { :source => /^(?:act:)?\/.*?\// } -plugin.map plugin.move_syntax, :action => 'handle_move', - :requirements => { :source => /^(?:act:)?".*?"/ } -plugin.map plugin.move_syntax, :action => 'handle_move', - :requirements => { :source => /^(?:act:)?'.*?'/ } + :requirements => { + :source => plugin.trigger_syntax, + :dest => plugin.trigger_syntax + } plugin.map plugin.move_syntax.sub('*', ':'), :action => 'handle_move' -- 2.39.5