3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-24 03:29:28 +01:00
PyLink/plugins/commands.py
James Lu d9db7e1b9e It's almost June! Updates:
- Move config handling into separate module
- Implement identify and status commands, currently only supporting the admin account defined in the config. Closes #1.
- Move proto.add_cmd to utils.py, rename _msg() to msg()
- Allow sending the command name as an optional argument in add_cmd
- Add catch-all exception handling in plugins to prevent them from crashing the program!
2015-05-31 12:20:09 -07:00

57 lines
1.8 KiB
Python

# commands.py: base PyLink commands
import sys, os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import proto
import utils
from conf import conf
@utils.add_cmd
def tell(irc, source, args):
try:
target, text = args[0], ' '.join(args[1:])
except IndexError:
utils.msg(irc, source, 'Error: not enough arguments.')
return
targetuid = proto._nicktoUid(irc, target)
if targetuid is None:
utils.msg(irc, source, 'Error: unknown user %r' % target)
return
if not text:
utils.msg(irc, source, "Error: can't send an empty message!")
return
utils.msg(irc, target, text, notice=True)
@utils.add_cmd
def debug(irc, source, args):
utils.msg(irc, source, 'Debug info printed to console.')
print(irc.users)
print(irc.servers)
@utils.add_cmd
def status(irc, source, args):
identified = irc.users[source].identified
if identified:
utils.msg(irc, source, 'You are identified as %s.' % identified)
else:
utils.msg(irc, source, 'You are not identified as anyone.')
@utils.add_cmd
def identify(irc, source, args):
try:
username, password = args[0], args[1]
except IndexError:
utils.msg(irc, source, 'Error: not enough arguments.')
return
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)
else:
utils.msg(irc, source, 'Incorrect credentials.')
def listcommands(irc, source, args):
cmds = list(utils.bot_commands.keys())
cmds.sort()
utils.msg(irc, source, 'Available commands include: %s' % ', '.join(cmds))
utils.add_cmd(listcommands, 'list')