# has the message been replied to/handled by a plugin?
attr_accessor :replied
+ alias :replied? :replied
# should the message be ignored?
attr_accessor :ignored
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
@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
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
# (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
@ctcp = false
@action = false
- if target == @bot.myself
+ if @address = (target == @bot.myself)
@private = true
- @address = true
@channel = nil
@replyto = source
else
@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
# 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
# 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
# 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
def newnick
return @message
end
+
+ def inspect
+ fields = ' old=' << oldnick
+ fields << ' new=' << newnick
+ super(fields)
+ end
end
# class to manage mode changes
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
super(bot, server, source, target, message)
@users = []
end
+
+ def inspect
+ fields = ' users=' << users.inspect
+ super(fields)
+ end
end
class QuitMessage < BasicUserMessage
@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