summaryrefslogtreecommitdiff
path: root/lib/rbot/message.rb
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-09-02 07:16:10 +0000
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-09-02 07:16:10 +0000
commite680c0565bf3fd0fede9cc124f9a40484f309c56 (patch)
treeb8cd5781532e18aac7c11272a692dcafb7a84ca4 /lib/rbot/message.rb
parenta4384d0c8a0d723897cf36fb423ba26fb0d1b083 (diff)
+ cleaner support for CTCP commands
Diffstat (limited to 'lib/rbot/message.rb')
-rw-r--r--lib/rbot/message.rb20
1 files changed, 17 insertions, 3 deletions
diff --git a/lib/rbot/message.rb b/lib/rbot/message.rb
index c539843b..7527940a 100644
--- a/lib/rbot/message.rb
+++ b/lib/rbot/message.rb
@@ -208,6 +208,12 @@ module Irc
# channel the message was in, nil for privately addressed messages
attr_reader :channel
+ # for PRIVMSGs, false unless the message was a CTCP command,
+ # in which case it evaluates to the CTCP command itself
+ # (TIME, PING, VERSION, etc). The CTCP command parameters
+ # are then stored in the message.
+ attr_reader :ctcp
+
# for PRIVMSGs, true if the message was a CTCP ACTION (CTCP stuff
# will be stripped from the message)
attr_reader :action
@@ -222,6 +228,7 @@ module Irc
@target = target
@private = false
@plugin = nil
+ @ctcp = false
@action = false
if target == @bot.myself
@@ -250,9 +257,11 @@ module Irc
@address = true
end
- if(@message =~ /^\001ACTION\s(.+)\001/)
- @message = $1
- @action = true
+ if(@message =~ /^\001(\S+)\s(.+)\001/)
+ @ctcp = $1
+ @message = $2
+ @action = @ctcp == 'ACTION'
+ debug "Received CTCP command #{@ctcp} with options #{@message} (action? #{@action})"
end
# free splitting for plugins
@@ -315,6 +324,11 @@ module Irc
@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
+ end
+
# convenience method to reply "okay" in the current language to the
# message
def plainokay