# Convert a String or Symbol into a color number
def Irc.find_color(data)
- if Integer === data
+ "%02d" % if Integer === data
data
else
f = if String === data
def Irc.color(fg=nil,bg=nil)
str = Color.dup
if fg
- str << Irc.find_color(fg).to_s
+ str << Irc.find_color(fg)
end
if bg
- str << "," << Irc.find_color(bg).to_s
+ str << "," << Irc.find_color(bg)
end
return str
end
# contents of the message
attr_accessor :message
+ # contents of the message (for logging purposes)
+ attr_accessor :logmessage
+
# has the message been replied to/handled by a plugin?
attr_accessor :replied
+ # should the message be ignored?
+ attr_accessor :ignored
+ alias :ignored? :ignored
+
# instantiate a new Message
# bot:: associated bot class
# server:: Server where the message took place
@message = BasicUserMessage.stripcolour message
@replied = false
@server = server
+ @ignored = false
@identified = false
if @msg_wants_id && @server.capabilities[:"identify-msg"]
warning "Message does not have identification"
end
end
+ @logmessage = @message.dup
if target && target == @bot.myself
@address = true
# Access the botuser corresponding to the source, if any
#
def botuser
- m.source.botuser rescue @bot.auth.everyone
+ source.botuser rescue @bot.auth.everyone
end
@message = $3 || String.new
@action = @ctcp == 'ACTION'
debug "Received CTCP command #{@ctcp} with options #{@message} (action? #{@action})"
+ @logmessage = @message.dup
end
# free splitting for plugins
# the nick or core.reply_with_nick is set to false
#
def reply(string, options={})
- if @bot.config['core.reply_with_nick'] and not string =~ /\b#{@source}\b/
+ if @bot.config['core.reply_with_nick'] and not string =~ /\b#{Regexp.escape(@source.to_s)}\b/
return nickreply(string, options)
end
plainreply(string, options)
plainokay
end
+ # send a NOTICE to the message source
+ #
+ def notify(msg,opts={})
+ @bot.notice(sourcenick, msg, opts)
+ end
+
end
# class to manage IRC PRIVMSGs
end
end
+ # class to manage IRC INVITEs
+ # +address?+ can be used as a shortcut to see if the bot was invited,
+ # which should be true except for server bugs
+ class InviteMessage < BasicUserMessage
+ # channel user was invited to
+ attr_reader :channel
+
+ def initialize(bot, server, source, target, channel, message="")
+ super(bot, server, source, target, message)
+ @channel = channel
+ end
+ end
+
# class to pass IRC Nick changes in. @message contains the old nickame,
# @sourcenick contains the new one.
class NickMessage < BasicUserMessage