4 # :title: Nickserv management plugin for rbot
6 # Author:: Tom Gilbert (giblet) <tom@linuxbrit.co.uk>
7 # Author:: Giuseppe "Oblomov" Bilotta <giuseppe.bilotta@gmail.com>
9 # Copyright:: (C) 2002-2005 Tom Gilbert
10 # Copyright:: (C) 2006 Tom Gilbert, Giuseppe Bilotta
11 # Copyright:: (C) 2006-2007 Giuseppe Bilotta
13 # Automatically lookup nicks in @registry and identify when asked
15 # Takes over proper nick if required and nick is registered
17 # TODO:: allow custom IDENTIFY and GHOST names
19 class NickServPlugin < Plugin
21 BotConfig.register BotConfigStringValue.new('nickserv.name',
22 :default => "nickserv", :requires_restart => false,
23 :desc => "Name of the nick server (all lowercase)")
24 BotConfig.register BotConfigStringValue.new('nickserv.ident_request',
25 :default => "IDENTIFY", :requires_restart => false,
26 :on_change => Proc.new { |bot, v| bot.plugins.delegate "set_ident_request", v },
27 :desc => "String to look for to see if the nick server is asking us to identify")
28 BotConfig.register BotConfigStringValue.new('nickserv.nick_avail',
29 :default => "not (currently )?online|killed|recovered|disconnesso|libero",
30 :requires_restart => false,
31 :on_change => Proc.new { |bot, v| bot.plugins.delegate "set_nick_avail", v },
32 :desc => "String to look for to see if the nick server is informing us that our nick is now available")
33 BotConfig.register BotConfigBooleanValue.new('nickserv.wants_nick',
34 :default => false, :requires_restart => false,
35 :desc => "Set to false if the nick server doesn't expect the nick as a parameter in the identify command")
36 BotConfig.register BotConfigIntegerValue.new('nickserv.wait',
37 :default => 30, :validate => Proc.new { |v| v > 0 }, :requires_restart => false,
38 :desc => "Seconds to wait after sending a message to nickserv, e.g. after ghosting")
40 def help(plugin, topic="")
43 return "nickserv plugin: handles nickserv protected IRC nicks. topics password, register, identify, listnicks"
45 return "nickserv password [<nick>] <passwd>: remember the password for nick <nick> and use it to identify in future"
47 return "nickserv register [<password> [<email>]]: register the current nick, choosing a random password unless <password> is supplied - current nick must not already be registered for this to work. Also specify email if required by your services"
49 return "nickserv identify: identify with nickserv - shouldn't be needed - bot should identify with nickserv immediately on request - however this could be useful after splits or service disruptions, or when you just set the password for the current nick"
51 return "nickserv listnicks: lists nicknames and associated password the bot knows about - you will need config level auth access to do this one and it will reply by privmsg only"
56 return Irc::Auth.random_password
59 def set_ident_request(val)
60 @ident_request = Regexp.new(val)
63 def set_nick_avail(val)
64 @nick_avail = Regexp.new(val)
69 # this plugin only wants to store strings!
78 set_ident_request(@bot.config['nickserv.ident_request'])
79 set_nick_avail(@bot.config['nickserv.nick_avail'])
82 # Returns the nickserv name
84 @bot.config['nickserv.name']
87 # say something to nickserv
92 def password(m, params)
93 nick = params[:nick] || @bot.nick
94 passwd = params[:passwd]
96 ns_say "SET PASSWORD #{passwd}"
98 m.reply "I'm only changing this in my database, I won't inform #{ns_nick} of the change"
100 @registry[nick] = passwd
104 def nick_register(m, params)
105 passwd = params[:passwd] ? params[:passwd] : genpasswd
106 message = "REGISTER #{passwd}"
107 message += " #{params[:email]}" if params[:email]
109 @registry[@bot.nick] = passwd
113 def listnicks(m, params)
114 if @registry.length > 0
115 @registry.each {|k,v|
116 @bot.say m.sourcenick, "#{k} => #{v}"
123 def do_identify(nick=@bot.nick)
124 if @registry.has_key?(nick)
125 if @bot.config['nickserv.wants_nick']
126 ns_say "IDENTIFY #{nick} #{@registry[nick]}"
129 ns_say "IDENTIFY #{@registry[nick]}"
131 # We cannot identify for different nicks if we can't use the nickname ...
140 def identify(m, params)
146 m.reply "I cannot identify for a this nick"
148 m.reply "I dunno the nickserv password for the nickname #{@bot.nick} :("
150 m.reply "uh ... something went wrong ..."
159 if @registry.has_key?(nick)
160 ns_say "GHOST #{nick} #{@registry[nick]}"
165 return unless(m.kind_of? NoticeMessage)
166 return unless m.source.downcase == ns_nick.downcase
170 debug "nickserv asked us to identify for nick #{@bot.nick}"
173 debug "our nick seems to be free now"
174 @bot.nickchg @bot.config['irc.nick']
179 plugin = NickServPlugin.new
180 plugin.map 'nickserv password [:nick] :passwd', :action => "password"
181 plugin.map 'nickserv register :passwd :email', :action => 'nick_register',
182 :defaults => {:passwd => false, :email => false}
183 plugin.map 'nickserv listnicks', :action => "listnicks"
184 plugin.map 'nickserv identify', :action => "identify"
186 plugin.default_auth('*', false)