summaryrefslogtreecommitdiff
path: root/data/rbot/plugins/alias.rb
diff options
context:
space:
mode:
authorYaohan Chen <yaohan.chen@gmail.com>2007-07-23 19:14:37 +0000
committerYaohan Chen <yaohan.chen@gmail.com>2007-07-23 19:14:37 +0000
commit98dde0dfe318d01e108acaed2413cc842a907b12 (patch)
tree3063de1c7eeb0582c1c42204d93a071842deba26 /data/rbot/plugins/alias.rb
parentd2d414a0fec91dfc2d79705b6e974f8830561dc5 (diff)
* Prevent the alias from including arguments not substituded in command, as a check for
possible incorrect command usage
Diffstat (limited to 'data/rbot/plugins/alias.rb')
-rw-r--r--data/rbot/plugins/alias.rb6
1 files changed, 4 insertions, 2 deletions
diff --git a/data/rbot/plugins/alias.rb b/data/rbot/plugins/alias.rb
index 900df2c4..2fba9324 100644
--- a/data/rbot/plugins/alias.rb
+++ b/data/rbot/plugins/alias.rb
@@ -29,6 +29,7 @@
# to detect and stop this, but a few recursive calls can still cause spamming
require 'yaml'
+require 'set'
class AliasPlugin < Plugin
# an exception raised when loading or getting input of invalid alias definitions
@@ -103,8 +104,9 @@ class AliasPlugin < Plugin
# each alias is implemented by adding a message map, whose handler creates a message
# containing the aliased command
- command.grep(/<(\w+)>/) {$1}.all? {|s| text =~ /(?:^|\s)[:*]#{s}(?:\s|$)/ } or
- raise AliasDefinitionError.new(_('Not all substitutions in command text have matching arguments in alias text'))
+ command.grep(/<(\w+)>/) {$1}.to_set ==
+ text.grep(/(?:^|\s)[:*](\w+)(?:\s|$)/) {$1}.to_set or
+ raise AliasDefinitionError.new(_('The arguments in alias must match the substitutions in command, and vice versa'))
@aliases[text] = command
map text, :action => :"alias_handle<#{text}>", :auth_path => 'run'