diff --git a/plugins/admin.py b/plugins/admin.py new file mode 100644 index 0000000..e7c2b7e --- /dev/null +++ b/plugins/admin.py @@ -0,0 +1,67 @@ +# admin.py: PyLink administrative commands +import sys, os +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +import proto +import utils + +class NotAuthenticatedError(Exception): + pass + +def checkauthenticated(irc, source): + if not irc.users[source].identified: + raise NotAuthenticatedError("You are not authenticated!") + +@utils.add_cmd +def eval(irc, source, args): + checkauthenticated(irc, source) + args = ' '.join(args) + if not args.strip(): + utils.msg(irc, source, 'No code entered!') + return + exec(args) + +@utils.add_cmd +def spawnclient(irc, source, args): + checkauthenticated(irc, source) + try: + nick, ident, host = args[:3] + except ValueError: + utils.msg(irc, source, "Error: not enough arguments. Needs 3: nick, user, host.") + return + proto.spawnClient(irc, nick, ident, host) + +@utils.add_cmd +def removeclient(irc, source, args): + checkauthenticated(irc, source) + try: + nick = args[0].lower() + except IndexError: + utils.msg(irc, source, "Error: not enough arguments. Needs 1: nick.") + return + u = _nicktoUid(nick) + if u is None or u not in irc.server[irc.sid].users: + utils.msg(irc, source, "Error: user %r not found." % nick) + return + _sendFromUser(irc, u, "QUIT :Client Quit") + proto.removeClient(irc, nick, ident, host) + +@utils.add_cmd +def joinclient(irc, source, args): + checkauthenticated(irc, source) + try: + nick = args[0] + clist = args[1].split(',') + if not clist: + raise IndexError + except IndexError: + utils.msg(irc, source, "Error: not enough arguments. Needs 2: nick, comma separated list of channels.") + return + u = _nicktoUid(nick) + if u is None or u not in irc.server[irc.sid].users: + utils.msg(irc, source, "Error: user %r not found." % nick) + return + for channel in clist: + if not channel.startswith('#'): + utils.msg(irc, source, "Error: channel names must start with #.") + return + joinClient(irc, ','.join(clist)) diff --git a/plugins/commands.py b/plugins/commands.py index d65eeaf..c7227f0 100644 --- a/plugins/commands.py +++ b/plugins/commands.py @@ -55,14 +55,3 @@ def listcommands(irc, source, args): cmds.sort() utils.msg(irc, source, 'Available commands include: %s' % ', '.join(cmds)) utils.add_cmd(listcommands, 'list') - -@utils.add_cmd -def eval(irc, source, args): - if not irc.users[source].identified: - utils.msg(irc, source, 'You are not authenticated!') - return - args = ' '.join(args) - if not args.strip(): - utils.msg(irc, source, 'No code entered!') - return - exec(args)