2015-06-07 22:40:18 +02:00
|
|
|
# admin.py: PyLink administrative commands
|
|
|
|
import sys, os
|
|
|
|
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
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
|
2015-06-17 05:05:41 +02:00
|
|
|
irc.proto.spawnClient(irc, nick, ident, host)
|
2015-06-07 22:40:18 +02:00
|
|
|
|
|
|
|
@utils.add_cmd
|
2015-06-08 04:31:56 +02:00
|
|
|
def quitclient(irc, source, args):
|
2015-06-07 22:40:18 +02:00
|
|
|
checkauthenticated(irc, source)
|
|
|
|
try:
|
2015-06-08 04:31:56 +02:00
|
|
|
nick = args[0]
|
2015-06-07 22:40:18 +02:00
|
|
|
except IndexError:
|
|
|
|
utils.msg(irc, source, "Error: not enough arguments. Needs 1: nick.")
|
|
|
|
return
|
2015-06-08 04:36:21 +02:00
|
|
|
if irc.pseudoclient.uid == utils.nickToUid(irc, nick):
|
2015-06-08 04:31:56 +02:00
|
|
|
utils.msg(irc, source, "Error: cannot quit the main PyLink PseudoClient!")
|
2015-06-07 22:40:18 +02:00
|
|
|
return
|
2015-06-08 04:36:21 +02:00
|
|
|
u = utils.nickToUid(irc, nick)
|
2015-06-08 04:31:56 +02:00
|
|
|
quitmsg = ' '.join(args[1:]) or 'Client quit'
|
2015-06-17 05:05:41 +02:00
|
|
|
irc.proto.quitClient(irc, u, quitmsg)
|
2015-06-07 22:40:18 +02:00
|
|
|
|
|
|
|
@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
|
2015-06-08 04:36:21 +02:00
|
|
|
u = utils.nickToUid(irc, nick)
|
2015-06-08 04:31:56 +02:00
|
|
|
for channel in clist:
|
|
|
|
if not channel.startswith('#'):
|
|
|
|
utils.msg(irc, source, "Error: channel names must start with #.")
|
|
|
|
return
|
2015-06-17 05:05:41 +02:00
|
|
|
irc.proto.joinClient(irc, u, channel)
|
2015-06-08 04:31:56 +02:00
|
|
|
|
|
|
|
@utils.add_cmd
|
|
|
|
def nickclient(irc, source, args):
|
|
|
|
checkauthenticated(irc, source)
|
|
|
|
try:
|
|
|
|
nick = args[0]
|
|
|
|
newnick = args[1]
|
|
|
|
except IndexError:
|
|
|
|
utils.msg(irc, source, "Error: not enough arguments. Needs 2: nick, newnick.")
|
|
|
|
return
|
2015-06-08 04:36:21 +02:00
|
|
|
u = utils.nickToUid(irc, nick)
|
2015-06-17 05:05:41 +02:00
|
|
|
irc.proto.nickClient(irc, u, newnick)
|
2015-06-08 04:31:56 +02:00
|
|
|
|
|
|
|
@utils.add_cmd
|
|
|
|
def partclient(irc, source, args):
|
|
|
|
checkauthenticated(irc, source)
|
|
|
|
try:
|
|
|
|
nick = args[0]
|
|
|
|
clist = args[1].split(',')
|
|
|
|
reason = ' '.join(args[2:])
|
|
|
|
except IndexError:
|
|
|
|
utils.msg(irc, source, "Error: not enough arguments. Needs 2: nick, comma separated list of channels.")
|
2015-06-07 22:40:18 +02:00
|
|
|
return
|
2015-06-08 04:36:21 +02:00
|
|
|
u = utils.nickToUid(irc, nick)
|
2015-06-07 22:40:18 +02:00
|
|
|
for channel in clist:
|
|
|
|
if not channel.startswith('#'):
|
|
|
|
utils.msg(irc, source, "Error: channel names must start with #.")
|
|
|
|
return
|
2015-06-17 05:05:41 +02:00
|
|
|
irc.proto.partClient(irc, u, channel, reason)
|
2015-06-08 04:31:56 +02:00
|
|
|
|
|
|
|
@utils.add_cmd
|
|
|
|
def kickclient(irc, source, args):
|
|
|
|
checkauthenticated(irc, source)
|
|
|
|
try:
|
|
|
|
nick = args[0]
|
|
|
|
channel = args[1]
|
|
|
|
target = args[2]
|
|
|
|
reason = ' '.join(args[3:])
|
|
|
|
except IndexError:
|
|
|
|
utils.msg(irc, source, "Error: not enough arguments. Needs 3-4: nick, channel, target, reason (optional).")
|
|
|
|
return
|
2015-06-08 04:36:21 +02:00
|
|
|
u = utils.nickToUid(irc, nick)
|
|
|
|
targetu = utils.nickToUid(irc, target)
|
2015-06-08 04:31:56 +02:00
|
|
|
if not channel.startswith('#'):
|
|
|
|
utils.msg(irc, source, "Error: channel names must start with #.")
|
|
|
|
return
|
2015-06-17 05:05:41 +02:00
|
|
|
irc.proto.kickClient(irc, u, channel, targetu, reason)
|
|
|
|
|
|
|
|
@utils.add_cmd
|
|
|
|
def tell(irc, source, args):
|
|
|
|
checkauthenticated(irc, source)
|
|
|
|
try:
|
|
|
|
source, target, text = args[0], args[1], ' '.join(args[2:])
|
|
|
|
except IndexError:
|
|
|
|
utils.msg(irc, source, 'Error: not enough arguments.')
|
|
|
|
return
|
|
|
|
targetuid = utils.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)
|