X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;ds=sidebyside;f=data%2Frbot%2Fplugins%2Fnickserv.rb;h=85270933c794a51439d8bcb1e34bc94341e1b3f6;hb=edd1cf77be07ae507014574141e920ad23eb164d;hp=5c2e068f79d58b1725c50a4f6a4fa39e543e7d00;hpb=6b4751c8b6e99dcff80cfe5e66c746cf9106dc6a;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/nickserv.rb b/data/rbot/plugins/nickserv.rb index 5c2e068f..85270933 100644 --- a/data/rbot/plugins/nickserv.rb +++ b/data/rbot/plugins/nickserv.rb @@ -1,8 +1,20 @@ +#-- vim:sw=2:et +#++ +# +# :title: Nickserv management plugin for rbot +# +# Author:: Tom Gilbert (giblet) +# Author:: Giuseppe "Oblomov" Bilotta +# +# Copyright:: (C) 2002-2005 Tom Gilbert +# Copyright:: (C) 2006 Tom Gilbert, Giuseppe Bilotta +# Copyright:: (C) 2006-2007 Giuseppe Bilotta +# # Automatically lookup nicks in @registry and identify when asked +# # Takes over proper nick if required and nick is registered -# TODO allow custom IDENTIFY and GHOST names -# TODO instead of nickserv.wait it would be ideal if we could just -# set up "don't send further commands until you receive this particular message" + +# TODO:: allow custom IDENTIFY and GHOST names class NickServPlugin < Plugin @@ -13,8 +25,13 @@ class NickServPlugin < Plugin :default => "IDENTIFY", :requires_restart => false, :on_change => Proc.new { |bot, v| bot.plugins.delegate "set_ident_request", v }, :desc => "String to look for to see if the nick server is asking us to identify") + BotConfig.register BotConfigStringValue.new('nickserv.nick_avail', + :default => "not (currently )?online|killed|recovered|disconnesso|libero", + :requires_restart => false, + :on_change => Proc.new { |bot, v| bot.plugins.delegate "set_nick_avail", v }, + :desc => "String to look for to see if the nick server is informing us that our nick is now available") BotConfig.register BotConfigBooleanValue.new('nickserv.wants_nick', - :default => true, :requires_restart => false, + :default => false, :requires_restart => false, :desc => "Set to false if the nick server doesn't expect the nick as a parameter in the identify command") BotConfig.register BotConfigIntegerValue.new('nickserv.wait', :default => 30, :validate => Proc.new { |v| v > 0 }, :requires_restart => false, @@ -25,7 +42,7 @@ class NickServPlugin < Plugin when "" return "nickserv plugin: handles nickserv protected IRC nicks. topics password, register, identify, listnicks" when "password" - return "nickserv password : remember the password for nick and use it to identify in future" + return "nickserv password [] : remember the password for nick and use it to identify in future" when "register" return "nickserv register [ []]: register the current nick, choosing a random password unless is supplied - current nick must not already be registered for this to work. Also specify email if required by your services" when "identify" @@ -36,18 +53,17 @@ class NickServPlugin < Plugin end def genpasswd - # generate a random password - passwd = "" - 8.times do - passwd += (rand(26) + (rand(2) == 0 ? 65 : 97) ).chr - end - return passwd + return Irc::Auth.random_password end def set_ident_request(val) @ident_request = Regexp.new(val) end + def set_nick_avail(val) + @nick_avail = Regexp.new(val) + end + def initialize super # this plugin only wants to store strings! @@ -60,15 +76,26 @@ class NickServPlugin < Plugin end end set_ident_request(@bot.config['nickserv.ident_request']) + set_nick_avail(@bot.config['nickserv.nick_avail']) + end + + # Returns the nickserv name + def ns_nick + @bot.config['nickserv.name'] + end + + # say something to nickserv + def ns_say(msg) + @bot.say ns_nick, msg end def password(m, params) nick = params[:nick] || @bot.nick passwd = params[:passwd] if nick == @bot.nick - @bot.say @bot.config['nickserv.name'], "SET PASSWORD #{passwd}" + ns_say "SET PASSWORD #{passwd}" else - m.reply "I'm only changing this in my database, I won't inform #{@bot.config['nickserv.name']} of the change" + m.reply "I'm only changing this in my database, I won't inform #{ns_nick} of the change" end @registry[nick] = passwd m.okay @@ -78,7 +105,7 @@ class NickServPlugin < Plugin passwd = params[:passwd] ? params[:passwd] : genpasswd message = "REGISTER #{passwd}" message += " #{params[:email]}" if params[:email] - @bot.sendmsg "PRIVMSG", @bot.config['nickserv.name'], message + ns_say message @registry[@bot.nick] = passwd m.okay end @@ -96,10 +123,10 @@ class NickServPlugin < Plugin def do_identify(nick=@bot.nick) if @registry.has_key?(nick) if @bot.config['nickserv.wants_nick'] - @bot.sendmsg "PRIVMSG", @bot.config['nickserv.name'], "IDENTIFY #{nick} #{@registry[nick]}" + ns_say "IDENTIFY #{nick} #{@registry[nick]}" else if nick == @bot.nick - @bot.sendmsg "PRIVMSG", @bot.config['nickserv.name'], "IDENTIFY #{@registry[nick]}" + ns_say "IDENTIFY #{@registry[nick]}" else # We cannot identify for different nicks if we can't use the nickname ... return false @@ -107,14 +134,20 @@ class NickServPlugin < Plugin end return true end - return false + return nil end def identify(m, params) - if do_identify + ided = do_identify + case ided + when true m.okay - else + when false + m.reply "I cannot identify for a this nick" + when nil m.reply "I dunno the nickserv password for the nickname #{@bot.nick} :(" + else + m.reply "uh ... something went wrong ..." end end @@ -124,26 +157,21 @@ class NickServPlugin < Plugin def nicktaken(nick) if @registry.has_key?(nick) - @bot.sendmsg "PRIVMSG", @bot.config['nickserv.name'], "GHOST #{nick} #{@registry[nick]}" - if do_identify nick - sleep @bot.config['nickserv.wait'] - @bot.nickchg nick - # We need to wait after changing nick, otherwise the server - # might refuse to execute further commangs, e.g. subsequent JOIN - # commands until the nick has changed. - sleep @bot.config['nickserv.wait'] - else - debug "Failed to identify for nick #{nick}, cannot take over" - end + ns_say "GHOST #{nick} #{@registry[nick]}" end end def listen(m) return unless(m.kind_of? NoticeMessage) + return unless m.source.downcase == ns_nick.downcase - if (m.sourcenick == @bot.config['nickserv.name'] && m.message =~ @ident_request) + case m.message + when @ident_request debug "nickserv asked us to identify for nick #{@bot.nick}" do_identify + when @nick_avail + debug "our nick seems to be free now" + @bot.nickchg @bot.config['irc.nick'] end end