+#-- vim:sw=2:et
+#++
+#
+# :title: IRC message datastructures
+
module Irc
- BotConfig.register BotConfigArrayValue.new('core.address_prefix',
- :default => [], :wizard => true,
- :desc => "what non nick-matching prefixes should the bot respond to as if addressed (e.g !, so that '!foo' is treated like 'rbot: foo')"
- )
- BotConfig.register BotConfigBooleanValue.new('core.reply_with_nick',
- :default => false, :wizard => true,
- :desc => "if true, the bot will prepend the nick to what he has to say when replying (e.g. 'markey: you can't do that!')"
- )
- BotConfig.register BotConfigStringValue.new('core.nick_postfix',
- :default => ':', :wizard => true,
- :desc => "when replying with nick put this character after the nick of the user the bot is replying to"
- )
+ class Bot
+ module Config
+ Config.register ArrayValue.new('core.address_prefix',
+ :default => [], :wizard => true,
+ :desc => "what non nick-matching prefixes should the bot respond to as if addressed (e.g !, so that '!foo' is treated like 'rbot: foo')"
+ )
+
+ Config.register BooleanValue.new('core.reply_with_nick',
+ :default => false, :wizard => true,
+ :desc => "if true, the bot will prepend the nick to what he has to say when replying (e.g. 'markey: you can't do that!')"
+ )
+
+ Config.register StringValue.new('core.nick_postfix',
+ :default => ':', :wizard => true,
+ :desc => "when replying with nick put this character after the nick of the user the bot is replying to"
+ )
+ end
+ end
+
# Define standard IRC attriubtes (not so standard actually,
# but the closest thing we have ...)
# 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
warning "Message does not have identification"
end
end
+ @logmessage = @message.dup
if target && target == @bot.myself
@address = true
"#{@source.user}@#{@source.host}" rescue @source.to_s
end
+ # Access the botuser corresponding to the source, if any
+ #
+ def botuser
+ source.botuser rescue @bot.auth.everyone
+ end
+
+
# Was the message from an identified user?
def identified?
return @identified
@address = true
end
- if(@message =~ /^\001(\S+)\s(.+)\001/)
+ if(@message =~ /^\001(\S+)(\s(.+))?\001/)
@ctcp = $1
- @message = $2
+ # FIXME need to support quoting of NULL and CR/LF, see
+ # http://www.irchelp.org/irchelp/rfc/ctcpspec.html
+ @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
@replied = true
end
- # send a CTCP response, i.e. a private notice to the sender
- def ctcp_reply(command, string, options={})
- @bot.ctcp_notice @source, command, string, options
+ # send a CTCP response, i.e. a private NOTICE to the sender
+ # with the same CTCP command and the reply as a parameter
+ def ctcp_reply(string, options={})
+ @bot.ctcp_notice @source, @ctcp, string, options
end
# convenience method to reply "okay" in the current language to the