X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Falias.rb;h=58d0ef01a0831639f03dd98b8aaf06064e2519b2;hb=91a9024e21ec8b429605a036b5c9193442a580e3;hp=a587736ccff862eaeb21873b532ac35ed2c7e952;hpb=e2bad2a87f98ee801498bd8879570c13be072f6c;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/alias.rb b/data/rbot/plugins/alias.rb index a587736c..58d0ef01 100644 --- a/data/rbot/plugins/alias.rb +++ b/data/rbot/plugins/alias.rb @@ -12,10 +12,10 @@ # exisitng rbot command and that is run. # # == Example Session -# < alias googlerbot *terms => google site:linuxbrit.co.uk/rbot/ +# < alias googlerbot *terms => google site:ruby-rbot.org # > okay # < googlerbot plugins -# > Results for site:linuxbrit.co.uk/rbot/ plugins: .... +# > Results for site:ruby-rbot.org plugins: .... # # == Security # By default, only the owner can define and remove aliases, while everyone else can @@ -36,12 +36,10 @@ class AliasPlugin < Plugin class AliasDefinitionError < ArgumentError end - MAX_RECURSION_DEPTH = 10 - def initialize super - @data_path = "#{@bot.botclass}/alias/" - @data_file = "#{@data_path}/aliases.yaml" + @data_path = datafile + @data_file = File.join(@data_path, 'aliases.yaml') # hash of alias => command entries data = nil aliases = if File.exist?(@data_file) && @@ -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}) @@ -171,7 +160,7 @@ class AliasPlugin < Plugin end.join ' | ' end when 'create' - _('"alias => " => add text as an alias of command. Text can contain placeholders marked with : or * for :words and *multiword arguments. The command can contain placeholders enclosed with < > which will be substituded with argument values. For example: alias googlerbot *terms => google site:linuxbrit.co.uk/rbot/ ') + _('"alias => " => add text as an alias of command. Text can contain placeholders marked with : or * for :words and *multiword arguments. The command can contain placeholders enclosed with < > which will be substituded with argument values. For example: alias googlerbot *terms => google site:ruby-rbot.org ') when 'commands' _('alias list => list defined aliases | alias whatis => show definition of the alias | alias remove => remove defined alias | see the "create" topic about adding aliases') end