summaryrefslogtreecommitdiff
path: root/data/rbot
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2008-04-08 16:09:14 +0200
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2008-04-08 16:09:14 +0200
commit52895a145e3327919b1a40647d4352bd2e9bc707 (patch)
tree78b9f20dc290bf85d4f82669f634e61ed04927af /data/rbot
parent6661440096cce02c0afbc304ed0d84d3697c87d1 (diff)
alias plugin: use fake_message()
Diffstat (limited to 'data/rbot')
-rw-r--r--data/rbot/plugins/alias.rb25
1 files changed, 7 insertions, 18 deletions
diff --git a/data/rbot/plugins/alias.rb b/data/rbot/plugins/alias.rb
index bafd8528..f947d81c 100644
--- a/data/rbot/plugins/alias.rb
+++ b/data/rbot/plugins/alias.rb
@@ -36,8 +36,6 @@ class AliasPlugin < Plugin
class AliasDefinitionError < ArgumentError
end
- MAX_RECURSION_DEPTH = 10
-
def initialize
super
@data_path = "#{@bot.botclass}/alias/"
@@ -130,25 +128,16 @@ class AliasPlugin < Plugin
if name.to_s =~ /\Aalias_handle<(.+)>\Z/
text = $1
m, params = args
- # messages created by alias handler will have a depth method, which returns the
- # depth of "recursion" caused by the message
- current_depth = if m.respond_to?(:depth) then m.depth else 0 end
- if current_depth > MAX_RECURSION_DEPTH
- m.reply _('The alias seems to have caused infinite recursion. Please examine your alias definitions')
- return
- end
command = @aliases[text]
if command
- # create a fake message containing the intended command
- new_msg = PrivMessage.new(@bot, m.server, m.server.user(m.source), m.target,
- command.gsub(/<(\w+)>/) {|arg| params[:"#{$1}"].to_s})
- # tag incremented depth on the message
- class << new_msg
- self
- end.send(:define_method, :depth) {current_depth + 1}
-
- @bot.plugins.privmsg(new_msg)
+ begin
+ # create a fake message containing the intended command
+ @bot.plugins.privmsg fake_message(command.gsub(/<(\w+)>/) {|arg| params[:"#{$1}"].to_s}, :from => m, :delegate => false)
+ rescue RecurseTooDeep
+ m.reply _('The alias seems to have caused infinite recursion. Please examine your alias definitions')
+ return
+ end
else
m.reply(_("Error handling the alias, The alias %{text} is not defined or has beeen removed. I will stop responding to it after rescan,") %
{:text => text})