From c105e3594dad01c3c5f7751f4541763a0f86e246 Mon Sep 17 00:00:00 2001 From: Andrew Williams Date: Mon, 6 Jun 2011 09:08:31 +0100 Subject: [PATCH] Added clientkick command to TS3Server --- ts3/__init__.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/ts3/__init__.py b/ts3/__init__.py index 5a1128e..3db4497 100644 --- a/ts3/__init__.py +++ b/ts3/__init__.py @@ -48,6 +48,11 @@ class NoConnection(Exception): def __str__(): return 'No connection established.' % (self.ip, self.port,) +class InvalidArguments(ValueError): + """ + Raised when a abstracted function has received invalid arguments + """ + ts3_escape = { "\\": r'\\', '/': r"\/", ' ': r'\s', @@ -249,6 +254,12 @@ class TS3Server(TS3Proto): if self.connect(ip, port) and id > 0: self.use(id) + @property + def logger(self): + if not hasattr(self, _logger): + self._logger = logging.getLogger(__name__) + return self._logger + def login(self, username, password): """ Login to the TS3 Server @@ -287,3 +298,36 @@ class TS3Server(TS3Proto): """ response = self.send_command('use', keys={'sid': id}) return response.is_successful + + def clientkick(self, clid=None, cldbid=None, type=REASON_KICK_SERVER, message=None): + """ + Kicks a user identified by either clid or cldbid + """ + + client = None + if cldbid: + response = self.send_command('clientlist') + for cl in response.data: + if int(cl['keys']['client_database_id']) == cldbid: + client = cl['keys']['clid'] + self.logger.debug("clientkick - identified user from clid (%s = %s)" % (cldbid, client)) + break + client = 0 + elif clid: + client = clid + else: + raise InvalidArguments('No clid or cldbid provided') + + if type == REASON_KICK_CHANNEL: + if not message: + message = '' + else: + # Kick message can only be 40 characters + message = message[:40] + + if client: + self.logger.debug("clientkick - Kicking clid %s" % client) + response = self.send_command('clientkick', keys={'clid': client, 'reasonid': type, 'reasonmsg': message}) + return response.is_successful + + return false