Teamspeak 3 Updates (#741)

* Correct duplicate error and success messages to user

* Read out all buffer bytes before sending command

* Convert ts3 manager to use a single connection

Each instance of the class will now use a single connection and should
be cleanly disconnected when finished.

Compatible with `with` clauses and will automatically disconnect from
the TS3 server when it exits the `with` block.

* Update TS3 manager consumers to use new style

* Update unit tests to use new style manager
This commit is contained in:
Basraah
2017-02-28 11:28:51 +10:00
committed by GitHub
parent e6e1339d71
commit c6118beddf
6 changed files with 169 additions and 149 deletions

View File

@@ -50,13 +50,24 @@ class TS3Proto:
return True
def disconnect(self):
self.send_command("quit")
self._conn.close()
self._connected = False
self._log.info('Disconnected')
if self._connected:
try:
self.send("quit")
self._conn.close()
except:
self._log.exception('Error while disconnecting')
self._connected = False
self._log.info('Disconnected')
else:
self._log.info("Not connected")
def send_command(self, command, keys=None, opts=None):
cmd = self.construct_command(command, keys=keys, opts=opts)
# Clear read buffer of any stray bytes
self._conn.read_very_eager()
# Send command
self.send('%s\n' % cmd)
data = []