]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/linkbot.rb
webhook: gitlab support
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / linkbot.rb
index a47f4b49cb71353881a5a8a9c0f257cd02ad5ddf..b9e7f5119afaabfc072795ba42b1bed80c9da878 100644 (file)
@@ -31,7 +31,7 @@ class LinkBot < Plugin
     :desc => "List of regexp which match linkbot messages; each regexp needs to have three captures, which in order are the nickname of the original speaker, network, and original message",
     :on_change => proc {|bot, v| bot.plugins['linkbot'].update_patterns})
   # TODO use template strings instead of regexp for user friendliness
-  
+
   # Initialize the plugin
   def initialize
     super
@@ -45,11 +45,10 @@ class LinkBot < Plugin
   end
 
   # Main method
-  def listen(m)
+  def message(m)
     linkbots = @bot.config['linkbot.nicks']
     return if linkbots.empty?
     return unless linkbots.include?(m.sourcenick)
-    return unless m.kind_of?(PrivMessage)
     # Now we know that _m_ is a PRIVMSG from a linkbot. Let's split it
     # in nick, network, message
     if @message_patterns.any? {|p| m.message =~ p}
@@ -60,25 +59,14 @@ class LinkBot < Plugin
       # strip any formatting codes in the new_nick. some people configure their linkbots
       # to embed these codes in nicknames (such as to\B\Bm), to avoid triggering the
       # person's highlight
-      new_nick.gsub! /[#{Bold}#{Underline}#{Reverse}#{Italic}#{NormalText}]/, ''
+      new_nick.gsub!(/[#{Bold}#{Underline}#{Reverse}#{Italic}#{NormalText}]/, '')
       debug "#{m.sourcenick} reports that #{new_nick} said #{message.inspect} on #{network}"
-      # One way to pass the new message back to the bot is to create a PrivMessage
-      # and delegate it to the plugins
-      new_m = PrivMessage.new(@bot, m.server, m.server.user(new_nick), m.target, message)
-      @bot.plugins.delegate "listen", new_m
-      @bot.plugins.privmsg(new_m) if new_m.address?
-
-      ## Another way is to create a data Hash with source, target and message keys
-      ## and then letting the bot client :privmsg handler handle it
-      ## Note that this will also create irclog entries for the fake PRIVMSG
-      ## TODO we could probably add a :no_irc_log entry to the data passed to the
-      ## @bot.client handlers, or something like that
-      # data = {
-      #   :source => m.server.user(new_nick)
-      #   :target => m.target
-      #   :message => message
-      # }
-      # @bot.client[:privmsg].call(data)
+      begin
+        # Pass the new message back to the bot
+        fake_message(message, :from => m, :source => m.server.user(new_nick))
+      rescue RecurseTooDeep => e
+        error e
+      end
     end
   end
 end