2003-03-27 08:57:27 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
###
|
|
|
|
# Copyright (c) 2002, Jeremiah Fincher
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions are met:
|
|
|
|
#
|
|
|
|
# * Redistributions of source code must retain the above copyright notice,
|
|
|
|
# this list of conditions, and the following disclaimer.
|
|
|
|
# * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
# this list of conditions, and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
|
|
|
# * Neither the name of the author of this software nor the name of
|
|
|
|
# contributors to this software may be used to endorse or promote products
|
|
|
|
# derived from this software without specific prior written consent.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
# POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
###
|
|
|
|
|
|
|
|
"""
|
2003-09-03 11:50:04 +02:00
|
|
|
Provides commands useful to users in general. This plugin is loaded by default.
|
2003-03-27 08:57:27 +01:00
|
|
|
"""
|
|
|
|
|
2003-11-25 18:33:58 +01:00
|
|
|
__revision__ = "$Id$"
|
|
|
|
|
|
|
|
import fix
|
|
|
|
|
2003-12-01 22:27:26 +01:00
|
|
|
import re
|
2003-10-28 16:13:53 +01:00
|
|
|
import getopt
|
2003-03-27 08:57:27 +01:00
|
|
|
import string
|
2003-12-01 21:57:00 +01:00
|
|
|
import fnmatch
|
2003-12-01 21:57:00 +01:00
|
|
|
from itertools import imap, ifilter
|
2003-03-27 08:57:27 +01:00
|
|
|
|
|
|
|
import conf
|
2003-12-01 21:57:00 +01:00
|
|
|
import utils
|
2003-03-27 08:57:27 +01:00
|
|
|
import ircdb
|
|
|
|
import ircutils
|
|
|
|
import privmsgs
|
|
|
|
import callbacks
|
|
|
|
|
2003-10-21 08:03:57 +02:00
|
|
|
class User(callbacks.Privmsg):
|
2003-03-27 08:57:27 +01:00
|
|
|
def _checkNotChannel(self, irc, msg, password=' '):
|
|
|
|
if password and ircutils.isChannel(msg.args[0]):
|
2003-12-09 01:02:51 +01:00
|
|
|
raise callbacks.Error, conf.replyRequiresPrivacy
|
2003-03-27 08:57:27 +01:00
|
|
|
|
2003-12-01 21:57:00 +01:00
|
|
|
def list(self, irc, msg, args):
|
|
|
|
"""[<glob>]
|
|
|
|
|
|
|
|
Returns the valid registered usernames matching <glob>. If <glob> is
|
|
|
|
not given, returns all registered usernames.
|
|
|
|
"""
|
|
|
|
glob = privmsgs.getArgs(args, required=0, optional=1)
|
|
|
|
if glob:
|
|
|
|
if '*' not in glob and '?' not in glob:
|
|
|
|
glob = '*%s*' % glob
|
2003-12-01 22:27:26 +01:00
|
|
|
r = re.compile(fnmatch.translate(glob), re.I)
|
2003-12-01 21:57:00 +01:00
|
|
|
def p(s):
|
2003-12-01 22:27:26 +01:00
|
|
|
return r.match(s) is not None
|
2003-12-01 21:57:00 +01:00
|
|
|
else:
|
|
|
|
def p(s):
|
|
|
|
return True
|
2003-12-02 00:24:25 +01:00
|
|
|
users = [u.name for u in ircdb.users if p(u.name)]
|
2003-12-01 21:57:00 +01:00
|
|
|
if users:
|
|
|
|
utils.sortBy(str.lower, users)
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.reply(utils.commaAndify(users))
|
2003-12-01 21:57:00 +01:00
|
|
|
else:
|
2003-12-01 22:17:29 +01:00
|
|
|
if glob:
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.reply('There are no matching registered users.')
|
2003-12-01 22:17:29 +01:00
|
|
|
else:
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.reply('There are no registered users.')
|
2003-12-01 21:57:00 +01:00
|
|
|
|
2003-03-27 08:57:27 +01:00
|
|
|
def register(self, irc, msg, args):
|
2003-10-28 16:13:53 +01:00
|
|
|
"""[--hashed] <name> <password>
|
2003-03-27 08:57:27 +01:00
|
|
|
|
|
|
|
Registers <name> with the given password <password> and the current
|
2003-09-25 16:21:46 +02:00
|
|
|
hostmask of the person registering. This command (and all other
|
|
|
|
commands that include a password) must be sent to the bot privately,
|
2003-10-28 16:13:53 +01:00
|
|
|
not in a channel. If --hashed is given, the password will be hashed
|
|
|
|
on disk, rather than being stored in plaintext.
|
2003-03-27 08:57:27 +01:00
|
|
|
"""
|
2003-10-28 16:13:53 +01:00
|
|
|
(optlist, rest) = getopt.getopt(args, '', ['hashed'])
|
2003-11-11 14:20:06 +01:00
|
|
|
(name, password) = privmsgs.getArgs(rest, required=2)
|
2003-10-28 16:13:53 +01:00
|
|
|
hashed = False
|
|
|
|
for (option, arg) in optlist:
|
|
|
|
if option == '--hashed':
|
|
|
|
hashed = True
|
2003-12-09 01:02:51 +01:00
|
|
|
self._checkNotChannel(irc, msg, password)
|
2003-09-12 22:06:58 +02:00
|
|
|
try:
|
|
|
|
ircdb.users.getUserId(name)
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error('That name is already assigned to someone.')
|
2003-04-20 10:54:27 +02:00
|
|
|
return
|
2003-09-12 22:06:58 +02:00
|
|
|
except KeyError:
|
|
|
|
pass
|
2003-03-27 08:57:27 +01:00
|
|
|
if ircutils.isUserHostmask(name):
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error('Hostmasks aren\'t valid usernames.')
|
2003-04-20 10:54:27 +02:00
|
|
|
return
|
2003-10-04 00:21:48 +02:00
|
|
|
try:
|
|
|
|
u = ircdb.users.getUser(msg.prefix)
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error('Your hostmask is already registered to %s' % u.name)
|
2003-10-04 00:21:48 +02:00
|
|
|
return
|
|
|
|
except KeyError:
|
|
|
|
pass
|
2003-09-12 22:06:58 +02:00
|
|
|
(id, user) = ircdb.users.newUser()
|
|
|
|
user.name = name
|
2003-10-28 16:13:53 +01:00
|
|
|
user.setPassword(password, hashed=hashed)
|
2003-03-27 08:57:27 +01:00
|
|
|
user.addHostmask(msg.prefix)
|
2003-09-12 22:06:58 +02:00
|
|
|
ircdb.users.setUser(id, user)
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.replySuccess()
|
2003-03-27 08:57:27 +01:00
|
|
|
|
2003-09-13 15:44:13 +02:00
|
|
|
def unregister(self, irc, msg, args):
|
|
|
|
"""<name> <password>
|
|
|
|
|
|
|
|
Unregisters <name> from the user database.
|
|
|
|
"""
|
2003-11-11 14:20:06 +01:00
|
|
|
(name, password) = privmsgs.getArgs(args, required=2)
|
2003-12-09 01:02:51 +01:00
|
|
|
self._checkNotChannel(irc, msg, password)
|
2003-09-13 15:44:13 +02:00
|
|
|
try:
|
|
|
|
id = ircdb.users.getUserId(name)
|
|
|
|
user = ircdb.users.getUser(id)
|
|
|
|
except KeyError:
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error('That username isn\'t registered.')
|
2003-09-13 15:44:13 +02:00
|
|
|
return
|
|
|
|
if user.checkPassword(password):
|
|
|
|
ircdb.users.delUser(id)
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.replySuccess()
|
2003-09-13 15:44:13 +02:00
|
|
|
else:
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error(conf.replyIncorrectAuth)
|
2003-09-13 15:44:13 +02:00
|
|
|
|
2003-12-09 01:02:51 +01:00
|
|
|
def changename(self, irc, msg, args):
|
2003-09-18 09:52:34 +02:00
|
|
|
"""<name> <new name> [<password>]
|
|
|
|
|
|
|
|
Changes your current user database name to the new name given.
|
|
|
|
<password> is only necessary if the user isn't recognized by hostmask.
|
2003-09-25 16:21:46 +02:00
|
|
|
If you include the <password> parameter, this message must be sent
|
|
|
|
to the bot privately (not on a channel).
|
2003-09-18 09:52:34 +02:00
|
|
|
"""
|
2003-12-09 01:02:51 +01:00
|
|
|
(name,newname,password) = privmsgs.getArgs(args,required=2,optional=1)
|
|
|
|
self._checkNotChannel(irc, msg, password)
|
2003-09-18 09:52:34 +02:00
|
|
|
try:
|
|
|
|
id = ircdb.users.getUserId(name)
|
|
|
|
user = ircdb.users.getUser(id)
|
|
|
|
except KeyError:
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error('That username isn\'t registered.')
|
2003-09-18 09:52:34 +02:00
|
|
|
return
|
|
|
|
try:
|
|
|
|
id = ircdb.users.getUserId(newname)
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error('%r is already registered.' % newname)
|
2003-09-18 09:52:34 +02:00
|
|
|
return
|
|
|
|
except KeyError:
|
|
|
|
pass
|
|
|
|
if user.checkHostmask(msg.prefix) or user.checkPassword(password):
|
|
|
|
user.name = newname
|
|
|
|
ircdb.users.setUser(id, user)
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.replySuccess()
|
2003-09-18 09:52:34 +02:00
|
|
|
|
2003-03-27 08:57:27 +01:00
|
|
|
def addhostmask(self, irc, msg, args):
|
|
|
|
"""<name> <hostmask> [<password>]
|
|
|
|
|
|
|
|
Adds the hostmask <hostmask> to the user specified by <name>. The
|
2003-09-18 09:52:34 +02:00
|
|
|
<password> may only be required if the user is not recognized by
|
2003-09-25 16:21:46 +02:00
|
|
|
hostmask. If you include the <password> parameter, this message must
|
|
|
|
be sent to the bot privately (not on a channel).
|
2003-03-27 08:57:27 +01:00
|
|
|
"""
|
|
|
|
(name, hostmask, password) = privmsgs.getArgs(args, 2, 1)
|
2003-12-09 01:02:51 +01:00
|
|
|
self._checkNotChannel(irc, msg, password)
|
2003-09-07 11:50:14 +02:00
|
|
|
if not ircutils.isUserHostmask(hostmask):
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error('That\'s not a valid hostmask.')
|
2003-09-07 11:50:14 +02:00
|
|
|
return
|
2003-03-27 08:57:27 +01:00
|
|
|
s = hostmask.translate(string.ascii, '!@*?')
|
|
|
|
if len(s) < 10:
|
2003-09-07 11:50:14 +02:00
|
|
|
s = 'Hostmask must contain more than 10 non-wildcard characters.'
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error(s)
|
2003-04-20 10:54:27 +02:00
|
|
|
return
|
2003-03-27 08:57:27 +01:00
|
|
|
try:
|
2003-09-12 22:06:58 +02:00
|
|
|
id = ircdb.users.getUserId(name)
|
|
|
|
user = ircdb.users.getUser(id)
|
2003-03-27 08:57:27 +01:00
|
|
|
except KeyError:
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error(conf.replyNoUser)
|
2003-04-20 10:54:27 +02:00
|
|
|
return
|
2003-03-27 08:57:27 +01:00
|
|
|
try:
|
2003-09-14 04:45:09 +02:00
|
|
|
otherId = ircdb.users.getUserId(hostmask)
|
|
|
|
if otherId != id:
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error('That hostmask is already registered.')
|
2003-09-14 04:45:09 +02:00
|
|
|
return
|
2003-03-27 08:57:27 +01:00
|
|
|
except KeyError:
|
|
|
|
pass
|
|
|
|
if user.checkHostmask(msg.prefix) or user.checkPassword(password):
|
|
|
|
user.addHostmask(hostmask)
|
2003-09-12 22:06:58 +02:00
|
|
|
ircdb.users.setUser(id, user)
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.replySuccess()
|
2003-03-27 08:57:27 +01:00
|
|
|
else:
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error(conf.replyIncorrectAuth)
|
2003-04-20 10:54:27 +02:00
|
|
|
return
|
2003-03-27 08:57:27 +01:00
|
|
|
|
2003-09-14 04:52:40 +02:00
|
|
|
def removehostmask(self, irc, msg, args):
|
2003-03-27 08:57:27 +01:00
|
|
|
"""<name> <hostmask> [<password>]
|
|
|
|
|
2003-09-14 04:52:40 +02:00
|
|
|
Removes the hostmask <hostmask> from the record of the user specified
|
2003-03-27 08:57:27 +01:00
|
|
|
by <name>. The <password> may only be required if the user is not
|
2003-09-25 16:21:46 +02:00
|
|
|
recognized by his hostmask. If you include the <password> parameter,
|
|
|
|
this message must be sent to the bot privately (not on a channel).
|
2003-03-27 08:57:27 +01:00
|
|
|
"""
|
|
|
|
(name, hostmask, password) = privmsgs.getArgs(args, 2, 1)
|
2003-12-09 01:02:51 +01:00
|
|
|
self._checkNotChannel(irc, msg, password)
|
2003-03-27 08:57:27 +01:00
|
|
|
try:
|
2003-09-12 22:06:58 +02:00
|
|
|
id = ircdb.users.getUserId(name)
|
|
|
|
user = ircdb.users.getUser(id)
|
2003-03-27 08:57:27 +01:00
|
|
|
except KeyError:
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error(conf.replyNoUser)
|
2003-04-20 10:54:27 +02:00
|
|
|
return
|
2003-03-27 08:57:27 +01:00
|
|
|
if user.checkHostmask(msg.prefix) or user.checkPassword(password):
|
2003-09-14 04:52:40 +02:00
|
|
|
try:
|
|
|
|
user.removeHostmask(hostmask)
|
|
|
|
except ValueError:
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error('There was no such hostmask.')
|
2003-09-14 04:52:40 +02:00
|
|
|
return
|
2003-09-12 22:06:58 +02:00
|
|
|
ircdb.users.setUser(id, user)
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.replySuccess()
|
2003-03-27 08:57:27 +01:00
|
|
|
else:
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error(conf.replyIncorrectAuth)
|
2003-04-20 10:54:27 +02:00
|
|
|
return
|
2003-03-27 08:57:27 +01:00
|
|
|
|
|
|
|
def setpassword(self, irc, msg, args):
|
2003-10-28 16:13:53 +01:00
|
|
|
"""[--hashed] <name> <old password> <new password>
|
2003-03-27 08:57:27 +01:00
|
|
|
|
|
|
|
Sets the new password for the user specified by <name> to
|
2003-09-25 16:21:46 +02:00
|
|
|
<new password>. Obviously this message must be sent to the bot
|
2003-10-28 16:13:53 +01:00
|
|
|
privately (not in a channel). If --hashed is given, the password will
|
|
|
|
be hashed on disk (rather than being stored in plaintext.
|
2003-03-27 08:57:27 +01:00
|
|
|
"""
|
2003-10-28 16:13:53 +01:00
|
|
|
(optlist, rest) = getopt.getopt(args, '', ['hashed'])
|
|
|
|
(name, oldpassword, newpassword) = privmsgs.getArgs(rest, 3)
|
|
|
|
hashed = False
|
|
|
|
for (option, arg) in optlist:
|
|
|
|
if option == '--hashed':
|
|
|
|
hashed = True
|
2003-12-09 01:02:51 +01:00
|
|
|
self._checkNotChannel(irc, msg, oldpassword+newpassword)
|
2003-03-27 08:57:27 +01:00
|
|
|
try:
|
2003-09-12 22:06:58 +02:00
|
|
|
id = ircdb.users.getUserId(name)
|
|
|
|
user = ircdb.users.getUser(id)
|
2003-03-27 08:57:27 +01:00
|
|
|
except KeyError:
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error(conf.replyNoUser)
|
2003-04-20 10:54:27 +02:00
|
|
|
return
|
2003-03-27 08:57:27 +01:00
|
|
|
if user.checkPassword(oldpassword):
|
2003-10-28 16:13:53 +01:00
|
|
|
user.setPassword(newpassword, hashed=hashed)
|
2003-09-12 22:06:58 +02:00
|
|
|
ircdb.users.setUser(id, user)
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.replySuccess()
|
2003-03-27 08:57:27 +01:00
|
|
|
else:
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error(conf.replyIncorrectAuth)
|
2003-03-27 08:57:27 +01:00
|
|
|
|
|
|
|
def username(self, irc, msg, args):
|
|
|
|
"""<hostmask|nick>
|
|
|
|
|
|
|
|
Returns the username of the user specified by <hostmask> or <nick> if
|
|
|
|
the user is registered.
|
|
|
|
"""
|
|
|
|
hostmask = privmsgs.getArgs(args)
|
|
|
|
if not ircutils.isUserHostmask(hostmask):
|
|
|
|
try:
|
|
|
|
hostmask = irc.state.nickToHostmask(hostmask)
|
|
|
|
except KeyError:
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error(conf.replyNoUser)
|
2003-04-20 10:54:27 +02:00
|
|
|
return
|
2003-03-27 08:57:27 +01:00
|
|
|
try:
|
2003-09-12 22:06:58 +02:00
|
|
|
user = ircdb.users.getUser(hostmask)
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.reply(user.name)
|
2003-03-27 08:57:27 +01:00
|
|
|
except KeyError:
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error(conf.replyNoUser)
|
2003-03-27 08:57:27 +01:00
|
|
|
|
|
|
|
def hostmasks(self, irc, msg, args):
|
|
|
|
"""[<name>]
|
|
|
|
|
|
|
|
Returns the hostmasks of the user specified by <name>; if <name> isn't
|
|
|
|
specified, returns the hostmasks of the user calling the command.
|
|
|
|
"""
|
2003-12-07 02:26:51 +01:00
|
|
|
if ircutils.isChannel(msg.args[0]):
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error(conf.replyRequiresPrivacy)
|
2003-12-07 02:26:51 +01:00
|
|
|
return
|
|
|
|
name = privmsgs.getArgs(args, required=0, optional=1)
|
2003-03-27 08:57:27 +01:00
|
|
|
try:
|
2003-12-07 02:26:51 +01:00
|
|
|
user = ircdb.users.getUser(msg.prefix)
|
|
|
|
if name:
|
|
|
|
if name != user.name and not user.checkCapability('owner'):
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error('You may only retrieve your own hostmasks.')
|
2003-12-07 02:26:51 +01:00
|
|
|
else:
|
|
|
|
try:
|
|
|
|
user = ircdb.users.getUser(name)
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.reply(repr(user.hostmasks))
|
2003-12-07 02:26:51 +01:00
|
|
|
except KeyError:
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error(conf.replyNoUser)
|
2003-12-07 02:26:51 +01:00
|
|
|
else:
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.reply(repr(user.hostmasks))
|
2003-03-27 08:57:27 +01:00
|
|
|
except KeyError:
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error(conf.replyNotRegistered)
|
2003-03-27 08:57:27 +01:00
|
|
|
|
|
|
|
def capabilities(self, irc, msg, args):
|
|
|
|
"""[<name>]
|
|
|
|
|
|
|
|
Returns the capabilities of the user specified by <name>; if <name>
|
|
|
|
isn't specified, returns the hostmasks of the user calling the command.
|
|
|
|
"""
|
|
|
|
if not args:
|
2003-09-12 22:06:58 +02:00
|
|
|
name = msg.prefix
|
2003-03-27 08:57:27 +01:00
|
|
|
else:
|
|
|
|
name = privmsgs.getArgs(args)
|
|
|
|
try:
|
|
|
|
user = ircdb.users.getUser(name)
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.reply('[%s]' % ', '.join(user.capabilities))
|
2003-03-27 08:57:27 +01:00
|
|
|
except KeyError:
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error(conf.replyNoUser)
|
2003-03-27 08:57:27 +01:00
|
|
|
|
|
|
|
def identify(self, irc, msg, args):
|
|
|
|
"""<name> <password>
|
|
|
|
|
2003-11-04 23:50:22 +01:00
|
|
|
Identifies the user as <name>. This command (and all other
|
|
|
|
commands that include a password) must be sent to the bot privately,
|
|
|
|
not in a channel.
|
2003-03-27 08:57:27 +01:00
|
|
|
"""
|
|
|
|
(name, password) = privmsgs.getArgs(args, 2)
|
2003-12-09 01:02:51 +01:00
|
|
|
self._checkNotChannel(irc, msg)
|
2003-03-27 08:57:27 +01:00
|
|
|
try:
|
2003-09-12 22:06:58 +02:00
|
|
|
id = ircdb.users.getUserId(name)
|
|
|
|
user = ircdb.users.getUser(id)
|
2003-03-27 08:57:27 +01:00
|
|
|
except KeyError:
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error(conf.replyNoUser)
|
2003-03-27 08:57:27 +01:00
|
|
|
return
|
2003-09-12 22:06:58 +02:00
|
|
|
if user.checkPassword(password):
|
2003-10-09 07:09:05 +02:00
|
|
|
try:
|
|
|
|
user.setAuth(msg.prefix)
|
|
|
|
ircdb.users.setUser(id, user)
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.replySuccess()
|
2003-10-09 07:09:05 +02:00
|
|
|
except ValueError:
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error('Your secure flag is true and your hostmask '
|
2003-10-09 07:09:05 +02:00
|
|
|
'doesn\'t match any of your known hostmasks.')
|
2003-03-27 08:57:27 +01:00
|
|
|
else:
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error(conf.replyIncorrectAuth)
|
2003-03-27 08:57:27 +01:00
|
|
|
|
|
|
|
def unidentify(self, irc, msg, args):
|
|
|
|
"""takes no arguments
|
|
|
|
|
|
|
|
Un-identifies the user.
|
|
|
|
"""
|
|
|
|
try:
|
2003-09-12 22:06:58 +02:00
|
|
|
id = ircdb.users.getUserId(msg.prefix)
|
|
|
|
user = ircdb.users.getUser(id)
|
2003-03-27 08:57:27 +01:00
|
|
|
except KeyError:
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error(conf.replyNoUser)
|
2003-03-27 08:57:27 +01:00
|
|
|
return
|
2003-09-12 22:06:58 +02:00
|
|
|
user.unsetAuth()
|
|
|
|
ircdb.users.setUser(id, user)
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.replySuccess()
|
2003-03-27 08:57:27 +01:00
|
|
|
|
|
|
|
def whoami(self, irc, msg, args):
|
|
|
|
"""takes no arguments
|
|
|
|
|
|
|
|
Returns the name of the user calling the command.
|
|
|
|
"""
|
|
|
|
try:
|
2003-09-12 22:06:58 +02:00
|
|
|
user = ircdb.users.getUser(msg.prefix)
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.reply(user.name)
|
2003-03-27 08:57:27 +01:00
|
|
|
except KeyError:
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error(conf.replyNotRegistered)
|
2003-03-27 08:57:27 +01:00
|
|
|
|
2003-10-03 11:57:52 +02:00
|
|
|
def setsecure(self, irc, msg, args):
|
|
|
|
"""<password> [<True|False>]
|
|
|
|
|
|
|
|
Sets the secure flag on the user of the person sending the message.
|
|
|
|
Requires that the person's hostmask be in the list of hostmasks for
|
|
|
|
that user in addition to the password being correct. When the secure
|
|
|
|
flag is set, the user *must* identify before he can be recognized.
|
|
|
|
If a specific True/False value is not given, it inverts the current
|
|
|
|
value.
|
|
|
|
"""
|
2003-10-04 14:59:47 +02:00
|
|
|
(password, value) = privmsgs.getArgs(args, optional=1)
|
2003-12-09 01:02:51 +01:00
|
|
|
self._checkNotChannel(irc, msg, password)
|
2003-10-03 11:57:52 +02:00
|
|
|
try:
|
|
|
|
id = ircdb.users.getUserId(msg.prefix)
|
|
|
|
user = ircdb.users.getUser(id)
|
|
|
|
except KeyError:
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error(conf.replyNotRegistered)
|
2003-10-03 11:57:52 +02:00
|
|
|
if value == '':
|
|
|
|
value = not user.secure
|
|
|
|
elif value.lower() in ('true', 'false'):
|
|
|
|
value = eval(value.capitalize())
|
|
|
|
else:
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error('%s is not a valid boolean value.' % value)
|
2003-10-03 11:57:52 +02:00
|
|
|
return
|
|
|
|
if user.checkPassword(password) and \
|
|
|
|
user.checkHostmask(msg.prefix, useAuth=False):
|
|
|
|
user.secure = value
|
|
|
|
ircdb.users.setUser(id, user)
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.reply('Secure flag set to %s' % value)
|
2003-10-03 11:57:52 +02:00
|
|
|
else:
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error(conf.replyIncorrectAuth)
|
2003-10-03 11:57:52 +02:00
|
|
|
|
2003-03-27 08:57:27 +01:00
|
|
|
|
2003-10-21 08:03:57 +02:00
|
|
|
Class = User
|
2003-03-27 08:57:27 +01:00
|
|
|
|
|
|
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
2003-04-20 23:56:41 +02:00
|
|
|
|