1 # automatically lookup nicks in @registry and identify when asked
3 class NickServPlugin < Plugin
5 def help(plugin, topic="")
8 return "nickserv plugin: handles nickserv protected IRC nicks. topics password, register, identify, listnicks"
10 return "nickserv password <nick> <passwd>: remember the password for nick <nick> and use it to identify in future"
12 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"
14 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"
16 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"
21 # generate a random password
24 passwd += (rand(26) + (rand(2) == 0 ? 65 : 97) ).chr
31 # this plugin only wants to store strings!
42 def password(m, params)
43 @registry[params[:nick]] = params[:passwd]
46 def nick_register(m, params)
47 passwd = params[:passwd] ? params[:passwd] : genpasswd
48 message = "REGISTER #{passwd}"
49 message += " #{params[:email]}" if params[:email]
50 @bot.sendmsg "PRIVMSG", "NickServ", message
51 @registry[@bot.nick] = passwd
54 def listnicks(m, params)
55 if @registry.length > 0
57 @bot.say m.sourcenick, "#{k} => #{v}"
63 def identify(m, params)
64 if @registry.has_key?(@bot.nick)
65 @bot.sendmsg "PRIVMSG", "NickServ", "IDENTIFY #{@registry[@bot.nick]}"
68 m.reply "I dunno the nickserv password for the nickname #{@bot.nick} :("
73 return unless(m.kind_of? NoticeMessage)
75 if (m.sourcenick == "NickServ" && m.message =~ /\002IDENTIFY\002/)
76 debug "nickserv asked us to identify for nick #{@bot.nick}"
77 if @registry.has_key?(@bot.nick)
78 @bot.sendmsg "PRIVMSG", "NickServ", "IDENTIFY " + @registry[@bot.nick]
84 plugin = NickServPlugin.new
85 plugin.map 'nickserv password :nick :passwd', :action => "password"
86 plugin.map 'nickserv register :passwd :email', :action => 'nick_register',
87 :defaults => {:passwd => false, :email => false}
88 plugin.map 'nickserv listnicks', :action => "listnicks"
89 plugin.map 'nickserv identify', :action => "identify"