start outsourcing commands

This commit is contained in:
lm
2021-10-07 14:39:05 +02:00
parent 78f82d64e5
commit 890d2c47a4
2 changed files with 109 additions and 69 deletions
+104
View File
@@ -0,0 +1,104 @@
"""
TBD
"""
__author__ = "Lukas Mahler"
__version__ = "0.0.0"
__date__ = "07.10.2021"
__email__ = "m@hler.eu"
__status__ = "Development"
# Default
import json
import time
# Custom
import ts3
# Self
import util
def follow(self, invkr_id, parameter):
"""
"""
if not parameter[0]:
err = "Please use the command like this: .follow TARGET"
self.bot.sendtextmessage(targetmode=1, target=invkr_id, msg=err)
return
target = parameter[0]
try:
clients = self.bot.clientfind(pattern=target)
clids = [client["clid"] for client in clients]
if len(clids) == 1:
cid = self.bot.clientinfo(clids[0])["cid"]
self.bot.clientmove(clid=self.myid, cid=cid)
else:
self.pipeOut(f"Found multiple matching clients using pattern {target}:{clids}")
return
except ts3.query.TS3QueryError as e:
self.pipeOut(f"No client found using pattern {target},"
f"returned error:\n{e}", lvl="ERROR")
return
def info(self, invkr_id):
# TODO implement more then just the runtime
msg = f"Runtime: {util.getRuntime(self.started)}"
self.bot.sendtextmessage(targetmode=1, target=invkr_id, msg=msg)
def msglist(self, invkr_id, parameter):
"""
Message the invoker of the function either a list of channels or a list of clients.
"""
what = parameter[0]
mydict = {}
if what == "channel":
channels = self.bot.channellist()
for channel in channels:
order = channel["channel_order"]
mydict[order] = [channel["channel_name"], channel["cid"]]
mydict = dict(sorted(mydict.items()))
msg = json.dumps(mydict)
elif what == "clients":
clients = self.bot.clientlist()
for client in clients:
mydict[client["client_nickname"]] = {"clid": client["clid"], "cldbid": client["client_database_id"]}
mydict = dict(sorted(mydict.items()))
msg = json.dumps(mydict)
else:
msg = None
self.bot.sendtextmessage(targetmode=1, target=invkr_id, msg=msg)
def notifyAdmin(self):
"""
Ping every available admin.
"""
clients = self.bot.clientlist()
clients = [client for client in clients if client["client_type"] != "1"]
for client in clients:
cldbid = client["client_database_id"]
clid = client["clid"]
if self.isadmin(cldbid):
msg = "<Keep this chat open to use commands>"
self.bot.sendtextmessage(targetmode=1, target=clid, msg=msg)
if not self.whitelisted:
time.sleep(1)
if __name__ == "__main__":
exit()