add .help command

This commit is contained in:
Lukas 2021-10-13 21:56:25 +02:00
parent 890d2c47a4
commit c53d0ce4ed
3 changed files with 28 additions and 10 deletions

View File

@ -4,14 +4,13 @@ TBD
__author__ = "Lukas Mahler"
__version__ = "0.0.0"
__date__ = "07.10.2021"
__date__ = "13.10.2021"
__email__ = "m@hler.eu"
__status__ = "Development"
# Default
import sys
import time
import json
import os.path
# Custom
@ -107,7 +106,7 @@ class TSbot:
time.sleep(5)
# Notify connected admins
self.notifyAdmin()
commands.notifyAdmin(self)
# ----------- LOOP HERE -------------
while self.running:
@ -176,7 +175,7 @@ class TSbot:
# New text message
elif event_type == "notifytextmessage":
msg = event[0]["msg"]
msg = event[0]["msg"].replace("\n", " ")
invkr = event[0]["invokername"]
invkr_id = event[0]["invokerid"]
self.pipeOut(f'Message | From: "{invkr}" | Content: "{msg}"')
@ -347,6 +346,7 @@ class TSbot:
.btc / .eth
.dot / .ada
.follow target
.help / .h
.info clid
.kickall message
.list channel/clients
@ -394,6 +394,9 @@ class TSbot:
elif command == ".follow":
commands.follow(self, invkr_id, parameter)
elif command == ".help" or command == ".h":
commands.help(self, invkr_id)
elif command == ".info":
commands.info(self, invkr_id)

View File

@ -4,20 +4,22 @@ TBD
__author__ = "Lukas Mahler"
__version__ = "0.0.0"
__date__ = "07.10.2021"
__date__ = "13.10.2021"
__email__ = "m@hler.eu"
__status__ = "Development"
# Default
import sys
import json
import time
import inspect
# Custom
import ts3
# Self
import util
from src import util
def follow(self, invkr_id, parameter):
@ -25,7 +27,7 @@ def follow(self, invkr_id, parameter):
"""
if not parameter[0]:
if not parameter:
err = "Please use the command like this: .follow TARGET"
self.bot.sendtextmessage(targetmode=1, target=invkr_id, msg=err)
return
@ -35,7 +37,7 @@ def follow(self, invkr_id, parameter):
clients = self.bot.clientfind(pattern=target)
clids = [client["clid"] for client in clients]
if len(clids) == 1:
cid = self.bot.clientinfo(clids[0])["cid"]
cid = self.bot.clientinfo(clid=int(clids[0]))[0]["cid"]
self.bot.clientmove(clid=self.myid, cid=cid)
else:
self.pipeOut(f"Found multiple matching clients using pattern {target}:{clids}")
@ -47,7 +49,20 @@ def follow(self, invkr_id, parameter):
return
def help(self, invkr_id):
"""
"""
# Find all functions in this submodule
cmds = [f[0] for f in inspect.getmembers(sys.modules[__name__], inspect.isfunction)]
msg = f"List of commands:\n{f'{chr(10)}.'.join(cmds)}"
self.bot.sendtextmessage(targetmode=1, target=invkr_id, msg=msg)
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)

View File

@ -4,7 +4,7 @@ TBD
__author__ = "Lukas Mahler"
__version__ = "0.0.0"
__date__ = "30.09.2021"
__date__ = "13.10.2021"
__email__ = "m@hler.eu"
__status__ = "Development"
@ -64,7 +64,7 @@ def getRuntime(started):
"""
elapsed = time.time() - started
runtime = str(timedelta(seconds=elapsed))
runtime = str(timedelta(seconds=elapsed)).split(".")[0] # ignore Microseconds
return runtime