From ed772ab21f12fd92a0986d70bd12f56c6d56a8cd Mon Sep 17 00:00:00 2001 From: Andrew Williams Date: Tue, 28 Jun 2011 11:50:48 +0100 Subject: [PATCH] Updated automover example --- examples/automover.py | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/examples/automover.py b/examples/automover.py index 96ad145..c9fb9d7 100644 --- a/examples/automover.py +++ b/examples/automover.py @@ -8,23 +8,47 @@ Automatically moves a list of Client DB IDs to a specified room, and checks for them every 5 seconds """ -# List of cldbids to move -moveids = [1111] - -# Destination channel -destination = 5 +# List of people to move +# +# name: defines a fixed name for that user, will kick them after warning +# destination: forces a user into a particular channel. +moveids = { + 4306: {'name': 'daley', 'destination': 405} +} #### server = TS3Server('127.0.0.1', 10011, 1) server.login('serveradmin', 'supersecretpassword') +print "Logged In" + +poke = [] + while True: clientlist = server.clientlist() for client in clientlist.values(): - if client['client_database_id'] in moveids and not int(client['cid']) == destination: - print "Found ID %s: %s" (client['client_database_id'], client['client_nickname']) - if server.send_client('clientmove', keys={'clid': client['clid'], 'cid': channel}).is_successful: - print "Moved %s to Channel %s" % (client['client_nickname'], channel) + # Check if the client is in the Move IDs + if int(client['client_database_id']) in moveids: + clinfo = moveids[int(client['client_database_id'])] + print "Found ID %s: %s" % (client['client_database_id'], client['client_nickname']) + + # If we have a channel defined and they're not in it, move them + if 'destination' in clinfo and not int(client['cid']) == clinfo['destination']: + if server.send_command('clientmove', keys={'clid': client['clid'], 'cid': clinfo['destination']}).is_successful: + print "Moved %s to Channel %s" % (client['client_nickname'], clinfo['destination']) + + # If we have a fixed name defined, tell them to change it or kick them + if 'name' in clinfo and not client['client_nickname'] == clinfo['name']: + if not client['clid'] in poke: + poke[client['clid']] = 0 + poke[client['clid']] += 1 + print "Warning %s out of 3" % poke[client['clid']] + server.send_command('clientpoke', keys={'clid': client['clid'], 'msg': 'Change your name to "%s"! Warning %s of 3' % (clinfo['name'], poke[client['clid']])}) + if poke > 3: + server.send_command('clientkick', keys={'clid': client['clid'], 'reasonid': 5}) + else: + poke[client['clid']] = 0 + sleep(5)