]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - lib/rbot/message.rb
geoip plugin: thread command
[user/henk/code/ruby/rbot.git] / lib / rbot / message.rb
index 1fb68e2003a47b5235ba2c0093ad55449a9f40cc..f6e38e80a73d8f2359f38508466807b51b30c7b4 100644 (file)
@@ -133,6 +133,7 @@ module Irc
 
     # has the message been replied to/handled by a plugin?
     attr_accessor :replied
+    alias :replied? :replied
 
     # should the message be ignored?
     attr_accessor :ignored
@@ -142,6 +143,25 @@ module Irc
     attr_accessor :in_thread
     alias :in_thread? :in_thread
 
+    def inspect(fields=nil)
+      ret = self.__to_s__[0..-2]
+      ret << ' bot=' << @bot.__to_s__
+      ret << ' server=' << server.to_s
+      ret << ' time=' << time.to_s
+      ret << ' source=' << source.to_s
+      ret << ' target=' << target.to_s
+      ret << ' message=' << message.inspect
+      ret << ' logmessage=' << logmessage.inspect
+      ret << ' plainmessage=' << plainmessage.inspect
+      ret << fields if fields
+      ret << ' (identified)' if identified?
+      ret << ' (addressed to me)' if address?
+      ret << ' (replied)' if replied?
+      ret << ' (ignored)' if ignored?
+      ret << ' (in thread)' if in_thread?
+      ret << '>'
+    end
+
     # instantiate a new Message
     # bot::      associated bot class
     # server::   Server where the message took place
@@ -175,9 +195,7 @@ module Irc
       @plainmessage = BasicUserMessage.strip_formatting(@message)
       @message = BasicUserMessage.strip_initial_formatting(@message)
 
-      if target && target == @bot.myself
-        @address = true
-      end
+      @address = true if source == @bot.myself
 
     end
 
@@ -213,11 +231,6 @@ module Irc
       return @address
     end
 
-    # has this message been replied to by a plugin?
-    def replied?
-      return @replied
-    end
-
     # strip mIRC colour escapes from a string
     def BasicUserMessage.stripcolour(string)
       return "" unless string
@@ -252,6 +265,24 @@ module Irc
   # (address? will return true in this case)
   class UserMessage < BasicUserMessage
 
+    def inspect
+      fields = ' plugin=' << plugin.inspect
+      fields << ' params=' << params.inspect
+      fields << ' channel=' << channel.to_s if channel
+      fields << ' (reply to ' << replyto.to_s << ')'
+      if self.private?
+        fields << ' (private)'
+      else
+        fields << ' (public)'
+      end
+      if self.action?
+        fields << ' (action)'
+      elsif ctcp
+        fields << ' (CTCP ' << ctcp << ')'
+      end
+      super(fields)
+    end
+
     # for plugin messages, the name of the plugin invoked by the message
     attr_reader :plugin
 
@@ -290,9 +321,8 @@ module Irc
       @ctcp = false
       @action = false
 
-      if target == @bot.myself
+      if @address = (target == @bot.myself)
         @private = true
-        @address = true
         @channel = nil
         @replyto = source
       else
@@ -324,6 +354,8 @@ module Irc
         @action = @ctcp == 'ACTION'
         debug "Received CTCP command #{@ctcp} with options #{@message} (action? #{@action})"
         @logmessage = @message.dup
+        @plainmessage = BasicUserMessage.strip_formatting(@message)
+        @message = BasicUserMessage.strip_initial_formatting(@message)
       end
 
       # free splitting for plugins
@@ -429,17 +461,17 @@ module Irc
 
   # class to manage IRC PRIVMSGs
   class PrivMessage < UserMessage
-    def initialize(bot, server, source, target, message)
-      @msg_wants_id = true
-      super
+    def initialize(bot, server, source, target, message, opts={})
+      @msg_wants_id = opts[:handle_id]
+      super(bot, server, source, target, message)
     end
   end
 
   # class to manage IRC NOTICEs
   class NoticeMessage < UserMessage
-    def initialize(bot, server, source, target, message)
-      @msg_wants_id = true
-      super
+    def initialize(bot, server, source, target, message, opts={})
+      @msg_wants_id = opts[:handle_id]
+      super(bot, server, source, target, message)
     end
   end
 
@@ -450,6 +482,11 @@ module Irc
     # channel user was kicked from
     attr_reader :channel
 
+    def inspect
+      fields = ' channel=' << channel.to_s
+      super(fields)
+    end
+
     def initialize(bot, server, source, target, channel, message="")
       super(bot, server, source, target, message)
       @channel = channel
@@ -463,6 +500,11 @@ module Irc
     # channel user was invited to
     attr_reader :channel
 
+    def inspect
+      fields = ' channel=' << channel.to_s
+      super(fields)
+    end
+
     def initialize(bot, server, source, target, channel, message="")
       super(bot, server, source, target, message)
       @channel = channel
@@ -485,6 +527,12 @@ module Irc
     def newnick
       return @message
     end
+
+    def inspect
+      fields = ' old=' << oldnick
+      fields << ' new=' << newnick
+      super(fields)
+    end
   end
 
   # class to manage mode changes
@@ -492,9 +540,27 @@ module Irc
     attr_accessor :modes
     def initialize(bot, server, source, target, message="")
       super(bot, server, source, target, message)
-      @address = (source == @bot.myself)
       @modes = []
     end
+
+    def inspect
+      fields = ' modes=' << modes.inspect
+      super(fields)
+    end
+  end
+
+  # class to manage WHOIS replies
+  class WhoisMessage < BasicUserMessage
+    attr_reader :whois
+    def initialize(bot, server, source, target, whois)
+      super(bot, server, source, target, "")
+      @whois = whois
+    end
+
+    def inspect
+      fields = ' whois=' << whois.inspect
+      super(fields)
+    end
   end
 
   # class to manage NAME replies
@@ -504,6 +570,11 @@ module Irc
       super(bot, server, source, target, message)
       @users = []
     end
+
+    def inspect
+      fields = ' users=' << users.inspect
+      super(fields)
+    end
   end
 
   class QuitMessage < BasicUserMessage
@@ -531,17 +602,28 @@ module Irc
       @channel = channel
       @info_or_set = nil
     end
+
+    def inspect
+      fields = ' topic=' << topic
+      fields << ' (set on ' << timestamp << ')'
+      super(fields)
+    end
   end
 
   # class to manage channel joins
   class JoinMessage < BasicUserMessage
     # channel joined
     attr_reader :channel
+
+    def inspect
+      fields = ' channel=' << channel.to_s
+      super(fields)
+    end
+
     def initialize(bot, server, source, channel, message="")
       super(bot, server, source, channel, message)
       @channel = channel
       # in this case sourcenick is the nick that could be the bot
-      @address = (source == @bot.myself)
     end
   end