summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2006-07-22 23:16:40 +0000
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2006-07-22 23:16:40 +0000
commit519d8144025dc734c11aac05a8b5e61c488dfb8a (patch)
treebf88fd0c16f60c09544f32bb6012932fb77cbb4e /lib
parenta2c9a18474c4cb50d45aebb58c2d47bd98a886e7 (diff)
Implement support for the CAPAB IDENTIFY-MSG capability available on some server, therefore providing messages with the identified? method that tells if the sourcenick has identified with services or not
Diffstat (limited to 'lib')
-rw-r--r--lib/rbot/ircbot.rb17
-rw-r--r--lib/rbot/message.rb64
-rw-r--r--lib/rbot/rfc2812.rb10
3 files changed, 69 insertions, 22 deletions
diff --git a/lib/rbot/ircbot.rb b/lib/rbot/ircbot.rb
index f1aa7e50..966e5a84 100644
--- a/lib/rbot/ircbot.rb
+++ b/lib/rbot/ircbot.rb
@@ -83,6 +83,9 @@ class IrcBot
# bot's Language data
attr_reader :lang
+ # capabilities info for the server
+ attr_reader :capabilities
+
# channel info for channels the bot is in
attr_reader :channels
@@ -250,6 +253,19 @@ class IrcBot
@nick = @config['irc.nick']
@client = IrcClient.new
+ @client[:isupport] = proc { |data|
+ if data[:capab]
+ sendq "CAPAB IDENTIFY-MSG"
+ end
+ }
+ @client[:datastr] = proc { |data|
+ debug data.inspect
+ if data[:text] == "IDENTIFY-MSG"
+ @capabilities["identify-msg".to_sym] = true
+ else
+ debug "Not handling RPL_DATASTR #{data[:servermessage]}"
+ end
+ }
@client[:privmsg] = proc { |data|
message = PrivMessage.new(self, data[:source], data[:target], data[:message])
onprivmsg(message)
@@ -430,6 +446,7 @@ class IrcBot
end
@socket.emergency_puts "PASS " + @config['server.password'] if @config['server.password']
@socket.emergency_puts "NICK #{@nick}\nUSER #{@config['irc.user']} 4 #{@config['server.name']} :Ruby bot. (c) Tom Gilbert"
+ @capabilities = Hash.new
start_server_pings
end
diff --git a/lib/rbot/message.rb b/lib/rbot/message.rb
index a92194e9..fcbdbc56 100644
--- a/lib/rbot/message.rb
+++ b/lib/rbot/message.rb
@@ -8,25 +8,25 @@ module Irc
# (a user message is defined as having a source hostmask, a target
# nick/channel and a message part)
class BasicUserMessage
-
+
# associated bot
attr_reader :bot
-
+
# when the message was received
attr_reader :time
# hostmask of message source
attr_reader :source
-
+
# nick of message source
attr_reader :sourcenick
-
+
# url part of message source
attr_reader :sourceaddress
-
+
# nick/channel message was sent to
attr_reader :target
-
+
# contents of the message
attr_accessor :message
@@ -47,18 +47,32 @@ module Irc
@message = BasicUserMessage.stripcolour message
@replied = false
+ @identified = false
+ if @msg_wants_id && @bot.capabilities["identify-msg".to_sym]
+ if @message =~ /([-+])(.*)/
+ @identified = ($1=="+")
+ @message = $2
+ else
+ warning "Message does not have identification"
+ end
+ end
+
# split source into consituent parts
if source =~ /^((\S+)!(\S+))$/
@sourcenick = $2
@sourceaddress = $3
end
-
+
if target && target.downcase == @bot.nick.downcase
@address = true
end
-
+
end
-
+
+ def identified?
+ return @identified
+ end
+
# returns true if the message was addressed to the bot.
# This includes any private message to the bot, or any public message
# which looks like it's addressed to the bot, e.g. "bot: foo", "bot, foo",
@@ -87,10 +101,10 @@ module Irc
# The +message+ member will have any bot addressing "^bot: " removed
# (address? will return true in this case)
class UserMessage < BasicUserMessage
-
+
# for plugin messages, the name of the plugin invoked by the message
attr_reader :plugin
-
+
# for plugin messages, the rest of the message, with the plugin name
# removed
attr_reader :params
@@ -102,11 +116,11 @@ module Irc
# channel the message was in, nil for privately addressed messages
attr_reader :channel
-
+
# for PRIVMSGs, true if the message was a CTCP ACTION (CTCP stuff
# will be stripped from the message)
attr_reader :action
-
+
# instantiate a new UserMessage
# bot:: associated bot class
# source:: hostmask of the message source
@@ -118,7 +132,7 @@ module Irc
@private = false
@plugin = nil
@action = false
-
+
if target.downcase == @bot.nick.downcase
@private = true
@address = true
@@ -137,19 +151,19 @@ module Irc
break
end
}
-
+
# even if they used above prefixes, we allow for silly people who
- # combine all possible types, e.g. "|rbot: hello", or
+ # combine all possible types, e.g. "|rbot: hello", or
# "/msg rbot rbot: hello", etc
if @message.gsub!(/^\s*#{Regexp.escape(bot.nick)}\s*([:;,>]|\s)\s*/i, "")
@address = true
end
-
+
if(@message =~ /^\001ACTION\s(.+)\001/)
@message = $1
@action = true
end
-
+
# free splitting for plugins
@params = @message.dup
if @params.gsub!(/^\s*(\S+)[\s$]*/, "")
@@ -192,10 +206,18 @@ module Irc
# class to manage IRC PRIVMSGs
class PrivMessage < UserMessage
+ def initialize(bot, source, target, message)
+ @msg_wants_id = true
+ super
+ end
end
-
+
# class to manage IRC NOTICEs
class NoticeMessage < UserMessage
+ def initialize(bot, source, target, message)
+ @msg_wants_id = true
+ super
+ end
end
# class to manage IRC KICKs
@@ -204,7 +226,7 @@ module Irc
class KickMessage < BasicUserMessage
# channel user was kicked from
attr_reader :channel
-
+
def initialize(bot, source, target, channel, message="")
super(bot, source, target, message)
@channel = channel
@@ -252,7 +274,7 @@ module Irc
@address = (sourcenick.downcase == @bot.nick.downcase)
end
end
-
+
# class to manage channel parts
# same as a join, but can have a message too
class PartMessage < JoinMessage
diff --git a/lib/rbot/rfc2812.rb b/lib/rbot/rfc2812.rb
index 8dc2016c..965da0a1 100644
--- a/lib/rbot/rfc2812.rb
+++ b/lib/rbot/rfc2812.rb
@@ -809,6 +809,7 @@ module Irc
RPL_STATSPING=246
RPL_STATSBLINE=247
ERR_NOSERVICEHOST=492
+ RPL_DATASTR=290
# implements RFC 2812 and prior IRC RFCs.
# clients register handler proc{}s for different server events and IrcClient
@@ -956,9 +957,13 @@ module Irc
# PREFIX=(ov)@+ CASEMAPPING=ascii CAPAB IRCD=dancer :are available
# on this server"
#
- argv.each {|a|
+ argv[0,argv.length-1].each {|a|
if a =~ /^(.*)=(.*)$/
data[$1.downcase.to_sym] = $2
+ debug "server's #{$1.downcase.to_sym} is #{$2}"
+ else
+ data[a.downcase.to_sym] = true
+ debug "server supports #{a.downcase.to_sym}"
end
}
handle(:isupport, data)
@@ -1030,6 +1035,9 @@ module Irc
when RPL_ENDOFMOTD
data[:motd] = @motd
handle(:motd, data)
+ when RPL_DATASTR
+ data[:text] = argv[1]
+ handle(:datastr, data)
else
handle(:unknown, data)
end