1 # Automatically lookup nicks in @registry and identify when asked
2 # Takes over proper nick if required and nick is registered
3 # TODO allow custom IDENTIFY and GHOST names
5 class NickServPlugin < Plugin
7 BotConfig.register BotConfigStringValue.new('nickserv.name',
8 :default => "nickserv", :requires_restart => false,
9 :desc => "Name of the nick server (all lowercase)")
10 BotConfig.register BotConfigStringValue.new('nickserv.ident_request',
11 :default => "IDENTIFY", :requires_restart => false,
12 :on_change => Proc.new { |bot, v| bot.plugins.delegate "set_ident_request", v },
13 :desc => "String to look for to see if the nick server is asking us to identify")
14 BotConfig.register BotConfigStringValue.new('nickserv.nick_avail',
15 :default => "not (currently )?online|killed|recovered|disconnesso|libero",
16 :requires_restart => false,
17 :on_change => Proc.new { |bot, v| bot.plugins.delegate "set_nick_avail", v },
18 :desc => "String to look for to see if the nick server is informing us that our nick is now available")
19 BotConfig.register BotConfigBooleanValue.new('nickserv.wants_nick',
20 :default => false, :requires_restart => false,
21 :desc => "Set to false if the nick server doesn't expect the nick as a parameter in the identify command")
22 BotConfig.register BotConfigIntegerValue.new('nickserv.wait',
23 :default => 30, :validate => Proc.new { |v| v > 0 }, :requires_restart => false,
24 :desc => "Seconds to wait after sending a message to nickserv, e.g. after ghosting")
26 def help(plugin, topic="")
29 return "nickserv plugin: handles nickserv protected IRC nicks. topics password, register, identify, listnicks"
31 return "nickserv password [<nick>] <passwd>: remember the password for nick <nick> and use it to identify in future"
33 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"
35 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"
37 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"
42 return Irc::Auth.random_password
45 def set_ident_request(val)
46 @ident_request = Regexp.new(val)
49 def set_nick_avail(val)
50 @nick_avail = Regexp.new(val)
55 # this plugin only wants to store strings!
64 set_ident_request(@bot.config['nickserv.ident_request'])
65 set_nick_avail(@bot.config['nickserv.nick_avail'])
68 # Returns the nickserv name
70 @bot.config['nickserv.name']
73 # say something to nickserv
78 def password(m, params)
79 nick = params[:nick] || @bot.nick
80 passwd = params[:passwd]
82 ns_say "SET PASSWORD #{passwd}"
84 m.reply "I'm only changing this in my database, I won't inform #{ns_nick} of the change"
86 @registry[nick] = passwd
90 def nick_register(m, params)
91 passwd = params[:passwd] ? params[:passwd] : genpasswd
92 message = "REGISTER #{passwd}"
93 message += " #{params[:email]}" if params[:email]
95 @registry[@bot.nick] = passwd
99 def listnicks(m, params)
100 if @registry.length > 0
101 @registry.each {|k,v|
102 @bot.say m.sourcenick, "#{k} => #{v}"
109 def do_identify(nick=@bot.nick)
110 if @registry.has_key?(nick)
111 if @bot.config['nickserv.wants_nick']
112 ns_say "IDENTIFY #{nick} #{@registry[nick]}"
115 ns_say "IDENTIFY #{@registry[nick]}"
117 # We cannot identify for different nicks if we can't use the nickname ...
126 def identify(m, params)
132 m.reply "I cannot identify for a this nick"
134 m.reply "I dunno the nickserv password for the nickname #{@bot.nick} :("
136 m.reply "uh ... something went wrong ..."
145 if @registry.has_key?(nick)
146 ns_say "GHOST #{nick} #{@registry[nick]}"
151 return unless(m.kind_of? NoticeMessage)
152 return unless m.source.downcase == ns_nick.downcase
156 debug "nickserv asked us to identify for nick #{@bot.nick}"
159 debug "our nick seems to be free now"
160 @bot.nickchg @bot.config['irc.nick']
165 plugin = NickServPlugin.new
166 plugin.map 'nickserv password [:nick] :passwd', :action => "password"
167 plugin.map 'nickserv register :passwd :email', :action => 'nick_register',
168 :defaults => {:passwd => false, :email => false}
169 plugin.map 'nickserv listnicks', :action => "listnicks"
170 plugin.map 'nickserv identify', :action => "identify"
172 plugin.default_auth('*', false)