diff --git a/examples/automover.py b/examples/automover.py index 3a93b74..96ad145 100644 --- a/examples/automover.py +++ b/examples/automover.py @@ -20,9 +20,9 @@ server = TS3Server('127.0.0.1', 10011, 1) server.login('serveradmin', 'supersecretpassword') while True: - resp = server.send_command('clientlist') + clientlist = server.clientlist() - for client in resp.data: + 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: diff --git a/ts3/__init__.py b/ts3/__init__.py index c065b80..556e492 100644 --- a/ts3/__init__.py +++ b/ts3/__init__.py @@ -330,6 +330,23 @@ class TS3Server(TS3Proto): response = self.send_command('use', keys={'sid': id}) return response.is_successful + def clientlist(self): + """ + Returns a clientlist of the current connected server/vhost + """ + + response = self.send_command('clientlist') + + if response.is_successful: + clientlist = {} + for client in response.data: + clientlist[client['clid']] = client + return clientlist + else: + # TODO: Raise a exception? + self.logger.debug("clientlist - error retrieving client list") + return {} + def clientkick(self, clid=None, cldbid=None, type=REASON_KICK_SERVER, message=None): """ Kicks a user identified by either clid or cldbid @@ -345,7 +362,7 @@ class TS3Server(TS3Proto): break if not client: - # we should throw an exception here actually + # TODO: we should throw an exception here actually self.logger.debug("clientkick - no client with specified cldbid (%s) was found" % cldbid) return False elif clid: