4 # :title: QuakeNet Auth Plugin
6 # Author:: Raine Virta <rane@kapsi.fi>
7 # Copyright:: (C) 2008 Raine Virta
10 # Automatically auths with Q on QuakeNet servers
12 class QPlugin < Plugin
14 def help(plugin, topic="")
17 return "qauth plugin: handles Q auths. topics set, identify, register"
19 return "qauth set <user> <password>: set the Q user and password and use it to identify in future"
21 return "qauth identify: identify with Q (if user and auth are set)"
23 return "qauth register <email>: register with Q, an email on how to proceed will be sent to the email address you provide"
29 # this plugin only wants to store strings!
42 @registry['quakenet.user'] = params[:nick]
43 @registry['quakenet.auth'] = params[:password]
48 identify(nil, nil) if on_quakenet?
51 def identify(m, params)
52 @source = m.replyto if m
53 @registry['quakenet.auth'] = params[:password] if params[:password]
55 if @registry.has_key?('quakenet.user') && @registry.has_key?('quakenet.auth')
56 user = @registry['quakenet.user']
57 pass = @registry['quakenet.auth']
59 debug "authing with Q using #{user} #{pass}"
60 msg_q "auth #{user} #{pass}"
62 m.reply "not configured, try 'qauth set :nick :password' or 'qauth register :email'" if m
67 if m.source.user == "TheQBot" && m.source.host = "CServe.quakenet.org"
69 when /a user with that name already exists/i
70 @bot.say @source, "user with my name already exists, identify if it belongs to you"
71 when /created successfully/
72 @registry['quakenet.user'] = @bot.nick
73 @bot.say @source, "an email on how to proceed should have been sent to #{@email} -- 'qauth identify <password>' next"
74 when /too many accounts exist from this email address/i
75 @bot.say @source, "too many accounts on that email address"
76 when /registration service is unavailable/
77 @bot.say @source, "the registration service is unavailable, try again later"
78 when /password incorrect/
79 @bot.say @source, "username or password incorrect" if @source
80 when /you are now logged in/i
81 @bot.say @source, "authed successfully" if @source
82 when /auth is not available/
83 @bot.say @source, "already authed" if @source
88 def register_nick(m, params)
89 # check nick for invalid characters
90 if @bot.nick =~ /[`~\^\[\]{}|_\\]/
91 m.reply "for me to be able to register, my nick cannot have any of the following characters: `~^[]{}|_\\"
95 @email = params[:email]
98 msg_q "hello #{@email} #{@email}"
102 @bot.say "Q@CServe.quakenet.org", message if on_quakenet?
106 @bot.server.hostname.split(".")[-2] == "quakenet"
111 plugin.map 'qauth set :nick :password', :action => "set"
112 plugin.map 'qauth identify [:password]', :action => "identify"
113 plugin.map 'qauth register :email', :action => "register_nick"
115 plugin.default_auth('*', false)