|
@@ -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:
|