2003-03-27 08:57:27 +01:00
|
|
|
###
|
2004-08-23 15:14:06 +02:00
|
|
|
# Copyright (c) 2002-2004, Jeremiah Fincher
|
2003-03-27 08:57:27 +01:00
|
|
|
# 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
|
|
|
"""
|
|
|
|
|
2004-09-01 08:06:54 +02:00
|
|
|
import supybot
|
|
|
|
|
2003-11-25 18:33:58 +01:00
|
|
|
__revision__ = "$Id$"
|
2004-09-01 08:06:54 +02:00
|
|
|
__author__ = supybot.authors.jemfinch
|
2003-11-25 18:33:58 +01:00
|
|
|
|
2004-07-24 07:18:26 +02:00
|
|
|
import supybot.fix as fix
|
2003-11-25 18:33:58 +01:00
|
|
|
|
2003-12-01 22:27:26 +01:00
|
|
|
import re
|
2003-10-28 16:13:53 +01:00
|
|
|
import getopt
|
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
|
|
|
|
2004-07-24 07:18:26 +02:00
|
|
|
import supybot.conf as conf
|
|
|
|
import supybot.utils as utils
|
|
|
|
import supybot.ircdb as ircdb
|
2004-10-26 00:59:03 +02:00
|
|
|
from supybot.commands import *
|
2004-07-24 07:18:26 +02:00
|
|
|
import supybot.ircutils as ircutils
|
|
|
|
import supybot.privmsgs as privmsgs
|
|
|
|
import supybot.callbacks as callbacks
|
2003-03-27 08:57:27 +01:00
|
|
|
|
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]):
|
2004-01-18 08:58:26 +01:00
|
|
|
raise callbacks.Error, conf.supybot.replies.requiresPrivacy()
|
2003-03-27 08:57:27 +01:00
|
|
|
|
2004-10-26 00:59:03 +02:00
|
|
|
def list(self, irc, msg, args, optlist, glob):
|
|
|
|
"""[--capability=<capability>] [<glob>]
|
2003-12-01 21:57:00 +01:00
|
|
|
|
|
|
|
Returns the valid registered usernames matching <glob>. If <glob> is
|
|
|
|
not given, returns all registered usernames.
|
|
|
|
"""
|
2004-04-16 23:05:41 +02:00
|
|
|
predicates = []
|
|
|
|
for (option, arg) in optlist:
|
2004-10-26 00:59:03 +02:00
|
|
|
if option == 'capability':
|
2004-04-16 23:05:41 +02:00
|
|
|
def p(u, cap=arg):
|
|
|
|
try:
|
|
|
|
return u.checkCapability(cap)
|
|
|
|
except KeyError:
|
|
|
|
return False
|
|
|
|
predicates.append(p)
|
2003-12-01 21:57:00 +01:00
|
|
|
if glob:
|
2003-12-01 22:27:26 +01:00
|
|
|
r = re.compile(fnmatch.translate(glob), re.I)
|
2004-04-17 18:40:32 +02:00
|
|
|
def p(u):
|
|
|
|
return r.match(u.name) is not None
|
2004-04-16 23:05:41 +02:00
|
|
|
predicates.append(p)
|
|
|
|
users = []
|
|
|
|
for u in ircdb.users.itervalues():
|
|
|
|
for predicate in predicates:
|
|
|
|
if not predicate(u):
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
users.append(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:
|
2004-04-16 23:05:41 +02:00
|
|
|
if predicates:
|
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.')
|
2004-10-26 00:59:03 +02:00
|
|
|
list = wrap(list, [getopts({'capability':'capability'}),
|
|
|
|
additional('glob')])
|
2003-12-01 21:57:00 +01:00
|
|
|
|
2004-10-26 00:59:03 +02:00
|
|
|
def register(self, irc, msg, args, optlist, name, password):
|
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
|
2004-08-29 17:59:16 +02:00
|
|
|
on disk, rather than being stored in the default configured format.
|
2003-03-27 08:57:27 +01:00
|
|
|
"""
|
2004-04-30 07:45:05 +02:00
|
|
|
addHostmask = True
|
|
|
|
hashed = conf.supybot.databases.users.hash()
|
2003-10-28 16:13:53 +01:00
|
|
|
for (option, arg) in optlist:
|
2004-10-26 00:59:03 +02:00
|
|
|
if option == 'hashed':
|
2003-10-28 16:13:53 +01:00
|
|
|
hashed = True
|
2003-09-12 22:06:58 +02:00
|
|
|
try:
|
|
|
|
ircdb.users.getUserId(name)
|
2004-09-09 01:34:48 +02:00
|
|
|
irc.error('That name is already assigned to someone.', Raise=True)
|
2003-09-12 22:06:58 +02:00
|
|
|
except KeyError:
|
|
|
|
pass
|
2003-03-27 08:57:27 +01:00
|
|
|
if ircutils.isUserHostmask(name):
|
2004-09-09 01:34:48 +02:00
|
|
|
irc.errorInvalid('username', name,
|
|
|
|
'Hostmasks are not valid usernames.', Raise=True)
|
2003-10-04 00:21:48 +02:00
|
|
|
try:
|
|
|
|
u = ircdb.users.getUser(msg.prefix)
|
2004-04-30 07:45:05 +02:00
|
|
|
if u.checkCapability('owner'):
|
|
|
|
addHostmask = False
|
|
|
|
else:
|
|
|
|
irc.error('Your hostmask is already registered to %s' % u.name)
|
|
|
|
return
|
2003-10-04 00:21:48 +02:00
|
|
|
except KeyError:
|
|
|
|
pass
|
2004-10-22 08:21:34 +02:00
|
|
|
user = ircdb.users.newUser()
|
2003-09-12 22:06:58 +02:00
|
|
|
user.name = name
|
2003-10-28 16:13:53 +01:00
|
|
|
user.setPassword(password, hashed=hashed)
|
2004-04-30 07:45:05 +02:00
|
|
|
if addHostmask:
|
|
|
|
user.addHostmask(msg.prefix)
|
2004-10-22 08:21:34 +02:00
|
|
|
ircdb.users.setUser(user)
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.replySuccess()
|
2004-10-26 00:59:03 +02:00
|
|
|
register = wrap(register, ['private', getopts({'hashed':''}), 'something',
|
|
|
|
'something'])
|
2003-03-27 08:57:27 +01:00
|
|
|
|
2004-10-26 00:59:03 +02:00
|
|
|
def unregister(self, irc, msg, args, user, password):
|
2004-04-30 07:45:05 +02:00
|
|
|
"""<name> [<password>]
|
2003-09-13 15:44:13 +02:00
|
|
|
|
2004-04-30 07:45:05 +02:00
|
|
|
Unregisters <name> from the user database. If the user giving this
|
|
|
|
command is an owner user, the password is not necessary.
|
2003-09-13 15:44:13 +02:00
|
|
|
"""
|
2004-11-04 07:06:18 +01:00
|
|
|
if conf.supybot.databases.users.allowUnregistration():
|
|
|
|
if not user.checkPassword(password):
|
|
|
|
try:
|
|
|
|
user = ircdb.users.getUser(msg.prefix)
|
|
|
|
except KeyError:
|
|
|
|
user = None
|
|
|
|
if not user or not user.checkCapability('owner'):
|
|
|
|
irc.error(conf.supybot.replies.incorrectAuthentication())
|
|
|
|
ircdb.users.delUser(user.id)
|
|
|
|
irc.replySuccess()
|
|
|
|
else:
|
|
|
|
irc.error('This command has been disabled. You\'ll have to ask '
|
|
|
|
'the owner of this bot to unregister your user.')
|
2004-10-26 00:59:03 +02:00
|
|
|
unregister = wrap(unregister, ['private', 'otherUser',
|
2004-10-26 17:43:58 +02:00
|
|
|
additional('something', '')])
|
2003-09-13 15:44:13 +02:00
|
|
|
|
2004-10-26 00:59:03 +02:00
|
|
|
def changename(self, irc, msg, args, user, newname, password):
|
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
|
|
|
"""
|
|
|
|
try:
|
|
|
|
id = ircdb.users.getUserId(newname)
|
2004-10-26 00:59:03 +02:00
|
|
|
irc.error('%s is already registered.' % utils.quoted(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
|
2004-10-22 08:21:34 +02:00
|
|
|
ircdb.users.setUser(user)
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.replySuccess()
|
2004-10-26 00:59:03 +02:00
|
|
|
changename = wrap(changename, ['private', 'otherUser', 'something',
|
2004-10-26 17:43:58 +02:00
|
|
|
additional('something', '')])
|
2004-07-21 21:36:35 +02:00
|
|
|
|
2004-10-26 00:59:03 +02:00
|
|
|
def addhostmask(self, irc, msg, args, user, hostmask, password):
|
2004-08-03 09:39:05 +02:00
|
|
|
"""[<name>] [<hostmask>] [<password>]
|
2003-03-27 08:57:27 +01:00
|
|
|
|
|
|
|
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
|
2004-04-30 07:45:05 +02:00
|
|
|
be sent to the bot privately (not on a channel). <password> is also
|
|
|
|
not required if an owner user is giving the command on behalf of some
|
2004-08-03 09:39:05 +02:00
|
|
|
other user. If <hostmask> is not given, it defaults to your current
|
|
|
|
hostmask. If <name> is not given, it defaults to your currently
|
|
|
|
identified name.
|
2003-03-27 08:57:27 +01:00
|
|
|
"""
|
2004-08-03 09:39:05 +02:00
|
|
|
if not hostmask:
|
|
|
|
hostmask = msg.prefix
|
2003-09-07 11:50:14 +02:00
|
|
|
if not ircutils.isUserHostmask(hostmask):
|
2004-09-09 01:34:48 +02:00
|
|
|
irc.errorInvalid('hostmask', hostmask, 'Make sure your hostmask '
|
2004-04-12 01:37:58 +02:00
|
|
|
'includes a nick, then an exclamation point (!), then '
|
|
|
|
'a user, then an at symbol (@), then a host. Feel '
|
|
|
|
'free to use wildcards (* and ?, which work just like '
|
2004-10-08 16:12:03 +02:00
|
|
|
'they do on the command line) in any of these parts.',
|
|
|
|
Raise=True)
|
2003-03-27 08:57:27 +01:00
|
|
|
try:
|
2003-09-14 04:45:09 +02:00
|
|
|
otherId = ircdb.users.getUserId(hostmask)
|
2004-10-26 17:43:58 +02:00
|
|
|
if otherId != user.id:
|
2004-10-08 16:12:03 +02:00
|
|
|
irc.error('That hostmask is already registered.', Raise=True)
|
2003-03-27 08:57:27 +01:00
|
|
|
except KeyError:
|
|
|
|
pass
|
2004-04-30 07:45:05 +02:00
|
|
|
if not user.checkPassword(password) and \
|
|
|
|
not user.checkHostmask(msg.prefix):
|
2004-06-10 01:44:49 +02:00
|
|
|
try:
|
|
|
|
u = ircdb.users.getUser(msg.prefix)
|
|
|
|
except KeyError:
|
2004-10-08 16:12:03 +02:00
|
|
|
irc.error(conf.supybot.replies.incorrectAuthentication(),
|
|
|
|
Raise=True)
|
2004-04-30 07:45:05 +02:00
|
|
|
if not u.checkCapability('owner'):
|
2004-10-08 16:12:03 +02:00
|
|
|
irc.error(conf.supybot.replies.incorrectAuthentication(),
|
|
|
|
Raise=True)
|
2004-04-30 07:45:05 +02:00
|
|
|
try:
|
|
|
|
user.addHostmask(hostmask)
|
|
|
|
except ValueError, e:
|
2004-10-08 16:12:03 +02:00
|
|
|
irc.error(str(e), Raise=True)
|
2004-10-08 15:59:45 +02:00
|
|
|
try:
|
2004-10-22 08:21:34 +02:00
|
|
|
ircdb.users.setUser(user)
|
2004-10-08 15:59:45 +02:00
|
|
|
except ValueError, e:
|
2004-10-08 16:12:03 +02:00
|
|
|
irc.error(str(e), Raise=True)
|
2004-04-30 07:45:05 +02:00
|
|
|
irc.replySuccess()
|
2004-10-26 00:59:03 +02:00
|
|
|
addhostmask = wrap(addhostmask, [first('otherUser', 'user'),
|
|
|
|
optional('something'),
|
2004-10-26 17:43:58 +02:00
|
|
|
additional('something', '')])
|
2003-03-27 08:57:27 +01:00
|
|
|
|
2004-10-26 00:59:03 +02:00
|
|
|
def removehostmask(self, irc, msg, args, user, hostmask, password):
|
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
|
2004-04-30 04:13:42 +02:00
|
|
|
by <name>. If the hostmask is 'all' then all hostmasks will be
|
|
|
|
removed. 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
|
|
|
"""
|
2004-04-30 07:45:05 +02:00
|
|
|
if not user.checkPassword(password) and \
|
|
|
|
not user.checkHostmask(msg.prefix):
|
|
|
|
u = ircdb.users.getUser(msg.prefix)
|
|
|
|
if not u.checkCapability('owner'):
|
|
|
|
irc.error(conf.supybot.replies.incorrectAuthentication())
|
2003-09-14 04:52:40 +02:00
|
|
|
return
|
2004-04-30 07:45:05 +02:00
|
|
|
try:
|
|
|
|
s = ''
|
|
|
|
if hostmask == 'all':
|
2004-10-26 19:37:44 +02:00
|
|
|
user.hostmasks.clear()
|
2004-04-30 07:45:05 +02:00
|
|
|
s = 'All hostmasks removed.'
|
|
|
|
else:
|
|
|
|
user.removeHostmask(hostmask)
|
2004-10-26 19:37:44 +02:00
|
|
|
except KeyError:
|
2004-04-30 07:45:05 +02:00
|
|
|
irc.error('There was no such hostmask.')
|
2003-04-20 10:54:27 +02:00
|
|
|
return
|
2004-10-22 08:21:34 +02:00
|
|
|
ircdb.users.setUser(user)
|
2004-04-30 07:45:05 +02:00
|
|
|
irc.replySuccess(s)
|
2004-10-26 00:59:03 +02:00
|
|
|
removehostmask = wrap(removehostmask, ['private', 'otherUser', 'something',
|
2004-10-26 17:43:58 +02:00
|
|
|
additional('something', '')])
|
2003-03-27 08:57:27 +01:00
|
|
|
|
2004-10-26 00:59:03 +02:00
|
|
|
def setpassword(self, irc, msg, args, optlist, user, password,newpassword):
|
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
|
2004-04-12 01:37:58 +02:00
|
|
|
be hashed on disk (rather than being stored in plaintext. If the
|
2004-04-30 07:45:05 +02:00
|
|
|
requesting user is an owner user (and the user whose password is being
|
|
|
|
changed isn't that same owner user), then <old password> needn't be
|
2004-04-12 01:37:58 +02:00
|
|
|
correct.
|
2003-03-27 08:57:27 +01:00
|
|
|
"""
|
2004-04-30 07:45:05 +02:00
|
|
|
hashed = conf.supybot.databases.users.hash()
|
2003-10-28 16:13:53 +01:00
|
|
|
for (option, arg) in optlist:
|
2004-10-26 00:59:03 +02:00
|
|
|
if option == 'hashed':
|
2003-10-28 16:13:53 +01:00
|
|
|
hashed = True
|
2004-04-30 07:45:05 +02:00
|
|
|
u = ircdb.users.getUser(msg.prefix)
|
2004-10-26 00:59:03 +02:00
|
|
|
if user.checkPassword(password) or \
|
2004-04-30 07:45:05 +02:00
|
|
|
(u.checkCapability('owner') and not u == user):
|
2003-10-28 16:13:53 +01:00
|
|
|
user.setPassword(newpassword, hashed=hashed)
|
2004-10-22 08:21:34 +02:00
|
|
|
ircdb.users.setUser(user)
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.replySuccess()
|
2003-03-27 08:57:27 +01:00
|
|
|
else:
|
2004-01-18 08:58:26 +01:00
|
|
|
irc.error(conf.supybot.replies.incorrectAuthentication())
|
2004-10-26 00:59:03 +02:00
|
|
|
setpassword = wrap(setpassword, [getopts({'hashed':''}), 'otherUser',
|
|
|
|
'something', 'something'])
|
2003-03-27 08:57:27 +01:00
|
|
|
|
2004-10-26 00:59:03 +02:00
|
|
|
def username(self, irc, msg, args, user):
|
2003-03-27 08:57:27 +01:00
|
|
|
"""<hostmask|nick>
|
|
|
|
|
|
|
|
Returns the username of the user specified by <hostmask> or <nick> if
|
|
|
|
the user is registered.
|
|
|
|
"""
|
2004-10-26 00:59:03 +02:00
|
|
|
irc.reply(user.name)
|
|
|
|
username = wrap(username, ['otherUser'])
|
2003-03-27 08:57:27 +01:00
|
|
|
|
2004-10-26 00:59:03 +02:00
|
|
|
def hostmasks(self, irc, msg, args, name):
|
2003-03-27 08:57:27 +01:00
|
|
|
"""[<name>]
|
|
|
|
|
|
|
|
Returns the hostmasks of the user specified by <name>; if <name> isn't
|
|
|
|
specified, returns the hostmasks of the user calling the command.
|
|
|
|
"""
|
|
|
|
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 16:47:38 +01:00
|
|
|
irc.errorNoUser()
|
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 22:49:10 +01:00
|
|
|
irc.errorNotRegistered()
|
2004-10-26 00:59:03 +02:00
|
|
|
hostmasks = wrap(hostmasks, ['private', additional('something')])
|
2003-03-27 08:57:27 +01:00
|
|
|
|
2004-10-26 00:59:03 +02:00
|
|
|
def capabilities(self, irc, msg, args, user):
|
2003-03-27 08:57:27 +01:00
|
|
|
"""[<name>]
|
|
|
|
|
|
|
|
Returns the capabilities of the user specified by <name>; if <name>
|
|
|
|
isn't specified, returns the hostmasks of the user calling the command.
|
|
|
|
"""
|
2004-10-26 00:59:03 +02:00
|
|
|
irc.reply('[%s]' % '; '.join(user.capabilities))
|
|
|
|
capabilities = wrap(capabilities, [first('otherUser', 'user')])
|
2003-03-27 08:57:27 +01:00
|
|
|
|
2004-10-26 00:59:03 +02:00
|
|
|
def identify(self, irc, msg, args, user, password):
|
2003-03-27 08:57:27 +01:00
|
|
|
"""<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
|
|
|
"""
|
2003-09-12 22:06:58 +02:00
|
|
|
if user.checkPassword(password):
|
2003-10-09 07:09:05 +02:00
|
|
|
try:
|
2004-09-13 04:05:22 +02:00
|
|
|
user.addAuth(msg.prefix)
|
2004-10-22 08:21:34 +02:00
|
|
|
ircdb.users.setUser(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 '
|
2004-08-05 06:36:10 +02:00
|
|
|
'doesn\'t match any of your known hostmasks.')
|
2003-03-27 08:57:27 +01:00
|
|
|
else:
|
2004-01-18 08:58:26 +01:00
|
|
|
irc.error(conf.supybot.replies.incorrectAuthentication())
|
2004-10-26 00:59:03 +02:00
|
|
|
identify = wrap(identify, ['private', 'otherUser', 'something'])
|
2003-03-27 08:57:27 +01:00
|
|
|
|
2004-10-26 00:59:03 +02:00
|
|
|
def unidentify(self, irc, msg, args, user):
|
2003-03-27 08:57:27 +01:00
|
|
|
"""takes no arguments
|
|
|
|
|
2004-09-09 01:34:48 +02:00
|
|
|
Un-identifies you. Note that this may not result in the desired
|
|
|
|
effect of causing the bot not to recognize you anymore, since you may
|
|
|
|
have added hostmasks to your user that can cause the bot to continue to
|
|
|
|
recognize you.
|
2003-03-27 08:57:27 +01:00
|
|
|
"""
|
2004-09-13 04:05:22 +02:00
|
|
|
user.clearAuth()
|
2004-10-22 08:21:34 +02:00
|
|
|
ircdb.users.setUser(user)
|
2004-08-05 06:36:10 +02:00
|
|
|
irc.replySuccess('If you remain recognized after giving this command, '
|
|
|
|
'you\'re being recognized by hostmask, rather than '
|
2004-04-08 12:53:12 +02:00
|
|
|
'by password. You must remove whatever hostmask is '
|
|
|
|
'causing you to be recognized in order not to be '
|
|
|
|
'recognized.')
|
2004-10-26 00:59:03 +02:00
|
|
|
unidentify = wrap(unidentify, ['user'])
|
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-08-06 08:57:11 +02:00
|
|
|
irc.reply('I don\'t recognize you.')
|
2004-10-26 00:59:03 +02:00
|
|
|
whoami = wrap(whoami)
|
2003-03-27 08:57:27 +01:00
|
|
|
|
2004-10-26 00:59:03 +02:00
|
|
|
def setsecure(self, irc, msg, args, user, password, value):
|
2003-10-03 11:57:52 +02:00
|
|
|
"""<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.
|
|
|
|
"""
|
2004-10-26 00:59:03 +02:00
|
|
|
if value is None:
|
2003-10-03 11:57:52 +02:00
|
|
|
value = not user.secure
|
|
|
|
if user.checkPassword(password) and \
|
|
|
|
user.checkHostmask(msg.prefix, useAuth=False):
|
|
|
|
user.secure = value
|
2004-10-22 08:21:34 +02:00
|
|
|
ircdb.users.setUser(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-18 08:58:26 +01:00
|
|
|
irc.error(conf.supybot.replies.incorrectAuthentication())
|
2004-10-26 00:59:03 +02:00
|
|
|
setsecure = wrap(setsecure, ['private', 'user', 'something',
|
|
|
|
additional('boolean')])
|
2003-10-03 11:57:52 +02:00
|
|
|
|
2004-08-16 22:04:15 +02:00
|
|
|
def stats(self, irc, msg, args):
|
|
|
|
"""takes no arguments
|
|
|
|
|
|
|
|
Returns some statistics on the user database.
|
|
|
|
"""
|
|
|
|
users = 0
|
|
|
|
owners = 0
|
|
|
|
admins = 0
|
|
|
|
hostmasks = 0
|
|
|
|
for user in ircdb.users.itervalues():
|
|
|
|
users += 1
|
|
|
|
hostmasks += len(user.hostmasks)
|
|
|
|
try:
|
|
|
|
if user.checkCapability('owner'):
|
|
|
|
owners += 1
|
|
|
|
elif user.checkCapability('admin'):
|
|
|
|
admins += 1
|
|
|
|
except KeyError:
|
|
|
|
pass
|
|
|
|
irc.reply('I have %s registered users '
|
|
|
|
'with %s registered hostmasks; '
|
|
|
|
'%s and %s.' % (users, hostmasks,
|
|
|
|
utils.nItems('owner', owners),
|
|
|
|
utils.nItems('admin', admins)))
|
2004-10-26 00:59:03 +02:00
|
|
|
stats = wrap(stats)
|
|
|
|
|
2004-08-16 22:04:15 +02:00
|
|
|
|
2004-08-03 08:03:16 +02:00
|
|
|
## def config(self, irc, msg, args):
|
|
|
|
## """[--list] <name> [<value>]
|
|
|
|
|
|
|
|
## Sets the user configuration variable <name> to <value>, if given. If
|
|
|
|
## <value> is not given, returns the current value of <name> for the user
|
|
|
|
## giving the command. If --list is given, lists the values in <name>.
|
|
|
|
## """
|
|
|
|
## try:
|
|
|
|
## id = ircdb.users.getUserId(msg.prefix)
|
|
|
|
## except KeyError:
|
|
|
|
## irc.errorNoUser()
|
|
|
|
## return
|
|
|
|
## list = False
|
|
|
|
## (optlist, args) = getopt.getopt(args, '', ['list'])
|
|
|
|
## for (option, arg) in optlist:
|
|
|
|
## if option == '--list':
|
|
|
|
## list = True
|
|
|
|
## if len(args) >= 2:
|
|
|
|
## # We're setting.
|
|
|
|
## pass
|
|
|
|
## else:
|
|
|
|
## # We're getting.
|
|
|
|
## name = privmsgs.getArgs(args)
|
|
|
|
## if not name.startswith('users.'):
|
|
|
|
## name = 'users.' + name
|
|
|
|
## try:
|
|
|
|
## wrapper = Config.getWrapper(name)
|
|
|
|
## wrapper = wrapper.get(str(id))
|
|
|
|
## except InvalidRegistryValue, e:
|
2004-09-09 01:34:48 +02:00
|
|
|
## irc.errorInvalid('configuration variable', name, Raise=True)
|
2004-08-03 08:03:16 +02:00
|
|
|
## if list:
|
|
|
|
## pass
|
|
|
|
## else:
|
|
|
|
## irc.reply(str(wrapper))
|
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
|
|
|
|