Browse Source

Teamspeak status logic now relies on external service

Kirk Trombley 6 years ago
parent
commit
bdc9f2e35a
3 changed files with 4 additions and 40 deletions
  1. 0 5
      config/config.toml
  2. 1 1
      config/secrets.toml.template
  3. 3 34
      src/plugins/teamspeak.py

+ 0 - 5
config/config.toml

@@ -26,8 +26,3 @@ break = "I'm too robust for that!"
 yiff = "Sorry - I don't think I understand the command '!yiff'... I'll talk to Ivan and get back to you!"
 f = "FFFFFFFFFFFFFFFFFFFFF\nFFFFFFFFFFFFFFFFFFFFF\nFFFFFFFFFFFFFFFFFFFFF\nFFFFFFF\nFFFFFFF\nFFFFFFF\nFFFFFFFFFFFFFF\nFFFFFFFFFFFFFF\nFFFFFFFFFFFFFF\nFFFFFFF\nFFFFFFF\nFFFFFFF\nFFFFFFF\nFFFFFFF"
 rampart = "Hey guys can we please keep the topic to Rampart?"
-
-[teamspeak]
-host = "kirkleon.ddns.net"
-user = "serveradmin"
-scrolling = true

+ 1 - 1
config/secrets.toml.template

@@ -11,7 +11,7 @@ global = [ ] # List of Global Admin User IDs
     your_chat = [ ] # Per-chat Admin User IDs
 
 [teamspeak]
-pass = "your-teamspeak-serveradmin-password"
+query = "your-teamspeak-query-url"
 
 [curse]
 banlist = {}

+ 3 - 34
src/plugins/teamspeak.py

@@ -1,13 +1,10 @@
 import logging
-from telnetlib import Telnet
 
+import requests
 from command_system import RollbotResponse, RollbotFailure, RollbotPlugin
 from config import get_config, get_secret
 
-TS3_HOST = get_config("teamspeak.host")
-_TS3_USER = get_config("teamspeak.user")
-_TS3_PASS = get_secret("teamspeak.pass")
-TS3_LOGIN = ("login %s %s\n" % (_TS3_USER, _TS3_PASS)).encode("utf-8")
+TS3_QUERY = get_secret("teamspeak.query")
 
 
 class teamspeak(RollbotPlugin):
@@ -15,35 +12,7 @@ class teamspeak(RollbotPlugin):
         RollbotPlugin.__init__(self, "teamspeak", bot, logger=logger)
 
     def on_command(self, db, message):
-        try:
-            with Telnet(TS3_HOST, 10011, 5) as tn:
-                tn.write(TS3_LOGIN)
-                tn.write(b"use 1 -virtual\n")
-                tn.write(b"clientlist\n")
-                tn.write(b"whoami\n")
-                tn.write(b"quit\n")
-                response = tn.read_until(b"virtualserver_status").decode("ascii")
-        except Exception as e:
-            self.logger.error("Teamspeak failure - " + str(e))
-            return RollbotResponse(
-                message,
-                failure=RollbotFailure.SERVICE_DOWN,
-                debugging={
-                    "explain": "Encountered failure during Telnet calls.",
-                    "exception": e
-                }
-            )
-
-        if "banned" in response:
-            return RollbotResponse(
-                message,
-                failure=RollbotFailure.SERVICE_DOWN,
-                debugging={"explain": "Rate limiting issue."}
-            )
-
-        nicks = response.split()
-        nicks = [x.split("=")[1] for x in nicks if x.startswith("client_nickname")]
-        nicks = [y for y in nicks if "serveradmin" not in y]
+        nicks = requests.get(TS3_QUERY).json()["users"]
         if len(nicks) == 0:
             return RollbotResponse(message, txt="No one in teamspeak!")
         if len(nicks) == 1: