summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-10-31 21:25:33 +0000
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-10-31 21:25:33 +0000
commit8b3890935d2880cf488b520a8a5c24a63855684b (patch)
tree7456afac19725e82188fe89049f9ce66dc7bc3d4
parent1d2aba05cb025f51315cb45f0bf9b95879617002 (diff)
reaction plugin: collect trigger syntax into a single regexp
-rw-r--r--data/rbot/plugins/reaction.rb27
1 files 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'