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"
22 # this plugin only wants to store strings!
34 return unless m.params
37 when (/^password\s*(\S*)\s*(.*)$/)
40 @registry[nick] = passwd
44 @bot.sendmsg "PRIVMSG", "NickServ", "REGISTER " + passwd
45 @registry[@bot.nick] = passwd
47 when (/^register\s*(\S*)\s*(.*)$/)
50 @bot.sendmsg "PRIVMSG", "NickServ", "REGISTER " + passwd + " " + email
51 @registry[@bot.nick] = passwd
53 when (/^register\s*(.*)\s*$/)
55 @bot.sendmsg "PRIVMSG", "NickServ", "REGISTER " + passwd
56 @registry[@bot.nick] = passwd
59 if @bot.auth.allow?("config", m.source, m.replyto)
60 if @registry.length > 0
62 @bot.say m.sourcenick, "#{k} => #{v}"
69 if @registry.has_key?(@bot.nick)
70 @bot.sendmsg "PRIVMSG", "NickServ", "IDENTIFY " + @registry[@bot.nick]
73 m.reply "I dunno the nickserv password for the nickname #{@bot.nick} :("
79 return unless(m.kind_of? NoticeMessage)
81 if (m.sourcenick == "NickServ" && m.message =~ /This nickname is owned by someone else/)
82 puts "nickserv asked us to identify for nick #{@bot.nick}"
83 if @registry.has_key?(@bot.nick)
84 @bot.sendmsg "PRIVMSG", "NickServ", "IDENTIFY " + @registry[@bot.nick]
90 # generate a random password
93 passwd += (rand(26) + (rand(2) == 0 ? 65 : 97) ).chr
98 plugin = NickServPlugin.new
99 plugin.register("nickserv")