2015-04-25 08:00:01 +02:00
|
|
|
# commands.py: base PyLink commands
|
2015-05-31 07:35:00 +02:00
|
|
|
import sys
|
|
|
|
import os
|
2015-08-30 04:29:05 +02:00
|
|
|
from time import ctime
|
2015-05-31 07:35:00 +02:00
|
|
|
|
2015-04-25 08:00:01 +02:00
|
|
|
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
2015-05-31 08:00:39 +02:00
|
|
|
import utils
|
2015-05-31 21:20:09 +02:00
|
|
|
from conf import conf
|
2015-07-05 22:44:48 +02:00
|
|
|
from log import log
|
2015-08-29 18:39:33 +02:00
|
|
|
import world
|
2015-04-25 08:00:01 +02:00
|
|
|
|
2015-05-31 21:20:09 +02:00
|
|
|
@utils.add_cmd
|
|
|
|
def status(irc, source, args):
|
2015-07-18 07:21:16 +02:00
|
|
|
"""takes no arguments.
|
|
|
|
|
|
|
|
Returns your current PyLink login status."""
|
2015-05-31 21:20:09 +02:00
|
|
|
identified = irc.users[source].identified
|
|
|
|
if identified:
|
2015-08-03 04:41:40 +02:00
|
|
|
utils.msg(irc, source, 'You are identified as \x02%s\x02.' % identified)
|
2015-05-31 21:20:09 +02:00
|
|
|
else:
|
|
|
|
utils.msg(irc, source, 'You are not identified as anyone.')
|
2015-08-03 04:41:40 +02:00
|
|
|
utils.msg(irc, source, 'Operator access: \x02%s\x02' % bool(utils.isOper(irc, source)))
|
2015-05-31 07:35:00 +02:00
|
|
|
|
2015-05-31 21:20:09 +02:00
|
|
|
@utils.add_cmd
|
|
|
|
def identify(irc, source, args):
|
2015-07-18 07:21:16 +02:00
|
|
|
"""<username> <password>
|
|
|
|
|
|
|
|
Logs in to PyLink using the configured administrator account."""
|
2015-04-25 08:00:01 +02:00
|
|
|
try:
|
2015-05-31 21:20:09 +02:00
|
|
|
username, password = args[0], args[1]
|
2015-04-25 08:00:01 +02:00
|
|
|
except IndexError:
|
2015-08-26 05:51:13 +02:00
|
|
|
utils.msg(irc, source, 'Error: Not enough arguments.')
|
2015-04-25 08:00:01 +02:00
|
|
|
return
|
2015-07-18 07:21:16 +02:00
|
|
|
# Usernames are case-insensitive, passwords are NOT.
|
2015-05-31 21:20:09 +02:00
|
|
|
if username.lower() == conf['login']['user'].lower() and password == conf['login']['password']:
|
|
|
|
realuser = conf['login']['user']
|
|
|
|
irc.users[source].identified = realuser
|
|
|
|
utils.msg(irc, source, 'Successfully logged in as %s.' % realuser)
|
2015-07-19 23:59:51 +02:00
|
|
|
log.info("(%s) Successful login to %r by %s.",
|
2015-08-26 05:51:13 +02:00
|
|
|
irc.name, username, utils.getHostmask(irc, source))
|
2015-05-31 21:20:09 +02:00
|
|
|
else:
|
2015-08-26 05:55:39 +02:00
|
|
|
utils.msg(irc, source, 'Error: Incorrect credentials.')
|
2015-07-09 08:21:01 +02:00
|
|
|
u = irc.users[source]
|
2015-07-19 23:59:51 +02:00
|
|
|
log.warning("(%s) Failed login to %r from %s.",
|
|
|
|
irc.name, username, utils.getHostmask(irc, source))
|
2015-04-25 08:04:33 +02:00
|
|
|
|
2015-05-31 21:20:09 +02:00
|
|
|
def listcommands(irc, source, args):
|
2015-07-18 07:21:16 +02:00
|
|
|
"""takes no arguments.
|
|
|
|
|
|
|
|
Returns a list of available commands PyLink has to offer."""
|
2015-08-29 18:39:33 +02:00
|
|
|
cmds = list(world.bot_commands.keys())
|
2015-05-31 21:20:09 +02:00
|
|
|
cmds.sort()
|
2015-08-30 04:29:49 +02:00
|
|
|
for idx, cmd in enumerate(cmds):
|
|
|
|
nfuncs = len(world.bot_commands[cmd])
|
|
|
|
if nfuncs > 1:
|
|
|
|
cmds[idx] = '%s(x%s)' % (cmd, nfuncs)
|
2015-05-31 21:20:09 +02:00
|
|
|
utils.msg(irc, source, 'Available commands include: %s' % ', '.join(cmds))
|
2015-07-18 07:21:16 +02:00
|
|
|
utils.msg(irc, source, 'To see help on a specific command, type \x02help <command>\x02.')
|
2015-05-31 21:20:09 +02:00
|
|
|
utils.add_cmd(listcommands, 'list')
|
2015-07-18 07:21:16 +02:00
|
|
|
|
|
|
|
@utils.add_cmd
|
|
|
|
def help(irc, source, args):
|
|
|
|
"""<command>
|
|
|
|
|
|
|
|
Gives help for <command>, if it is available."""
|
|
|
|
try:
|
|
|
|
command = args[0].lower()
|
|
|
|
except IndexError: # No argument given, just return 'list' output
|
|
|
|
listcommands(irc, source, args)
|
|
|
|
return
|
2015-08-30 04:24:32 +02:00
|
|
|
if command not in world.bot_commands:
|
2015-08-26 05:51:13 +02:00
|
|
|
utils.msg(irc, source, 'Error: Unknown command %r.' % command)
|
2015-07-18 07:21:16 +02:00
|
|
|
return
|
|
|
|
else:
|
2015-08-30 04:24:32 +02:00
|
|
|
funcs = world.bot_commands[command]
|
|
|
|
if len(funcs) > 1:
|
|
|
|
utils.msg(irc, source, 'The following \x02%s\x02 plugins bind to the \x02%s\x02 command: %s'
|
|
|
|
% (len(funcs), command, ', '.join([func.__module__ for func in funcs])))
|
|
|
|
for func in funcs:
|
|
|
|
doc = func.__doc__
|
|
|
|
mod = func.__module__
|
|
|
|
if doc:
|
|
|
|
lines = doc.split('\n')
|
|
|
|
# Bold the first line, which usually just tells you what
|
|
|
|
# arguments the command takes.
|
|
|
|
lines[0] = '\x02%s %s\x02 (plugin: %r)' % (command, lines[0], mod)
|
|
|
|
for line in lines:
|
|
|
|
utils.msg(irc, source, line.strip())
|
|
|
|
else:
|
|
|
|
utils.msg(irc, source, "Error: Command %r (from plugin %r) "
|
|
|
|
"doesn't offer any help." % (command, mod))
|
|
|
|
return
|
|
|
|
|
2015-08-30 04:29:05 +02:00
|
|
|
@utils.add_cmd
|
|
|
|
def showuser(irc, source, args):
|
|
|
|
"""<user>
|
|
|
|
|
|
|
|
Shows information about <user>."""
|
|
|
|
try:
|
|
|
|
target = args[0]
|
|
|
|
except IndexError:
|
|
|
|
utils.msg(irc, source, "Error: Not enough arguments. Needs 1: nick.")
|
|
|
|
return
|
|
|
|
u = utils.nickToUid(irc, target) or target
|
|
|
|
# Only show private info if the person is calling 'showuser' on themselves,
|
|
|
|
# or is an oper.
|
|
|
|
verbose = utils.isOper(irc, source) or u == source
|
|
|
|
if u not in irc.users:
|
|
|
|
utils.msg(irc, source, 'Error: Unknown user %r.' % target)
|
|
|
|
return
|
|
|
|
|
|
|
|
f = lambda s: utils.msg(irc, source, s)
|
|
|
|
userobj = irc.users[u]
|
|
|
|
f('Information on user \x02%s\x02 (%s@%s): %s' % (userobj.nick, userobj.ident,
|
|
|
|
userobj.host, userobj.realname))
|
|
|
|
sid = utils.clientToServer(irc, u)
|
|
|
|
serverobj = irc.servers[sid]
|
|
|
|
ts = userobj.ts
|
|
|
|
f('\x02Home server\x02: %s (%s); \x02Signon time:\x02 %s (%s)' % \
|
|
|
|
(serverobj.name, sid, ctime(float(ts)), ts))
|
|
|
|
if verbose:
|
|
|
|
f('\x02Protocol UID\x02: %s; \x02PyLink identification\x02: %s' % \
|
|
|
|
(u, userobj.identified))
|
|
|
|
f('\x02User modes\x02: %s' % utils.joinModes(userobj.modes))
|
|
|
|
f('\x02Real host\x02: %s; \x02IP\x02: %s; \x02Away status\x02: %s' % \
|
|
|
|
(userobj.realhost, userobj.ip, userobj.away or '\x1D(not set)\x1D'))
|
|
|
|
f('\x02Channels\x02: %s' % (' '.join(userobj.channels).strip() or '\x1D(none)\x1D'))
|