enabling/disabling logging with chat commands

Signed-off-by: klux2 <k.lux.gm@gmail.com>
This commit is contained in:
klux2 2019-06-25 10:53:30 +02:00
parent 687dc8296b
commit 0e9cc463c1

View file

@ -48,7 +48,7 @@ datum = None
class HSMensaW(telepot.aio.helper.ChatHandler):
@staticmethod
async def on_chat_message(msg: dict) -> None:
global config, essen, status, var
global config, essen, status, var, logging_enabled
content_type, chat_type, chat_id = telepot.glance(msg)
if content_type == "text":
@ -102,6 +102,21 @@ class HSMensaW(telepot.aio.helper.ChatHandler):
elif text.startswith("/info"):
await send_message(bot_obj=bot, chat_id=chat_id, msg=info_str, parse_mode="markdown")
elif text.startswith("/logging") and chat_id in config_ids:
if text.endswith("on") or text.endswith("1") or text.lower().endswith("true"):
logging_enabled = True
config["logging_enabled"] = True
write_config()
await send_message(bot_obj=bot, chat_id=chat_id, msg="logging enabled", parse_mode="markdown")
elif text.endswith("off") or text.endswith("0") or text.lower().endswith("false"):
logging_enabled = False
config["logging_enabled"] = False
write_config()
await send_message(bot_obj=bot, chat_id=chat_id, msg="logging disabled", parse_mode="markdown")
else:
message = "logging enabled: %s (change with on/off or true/false or 1/0)" % logging_enabled
await send_message(bot_obj=bot, chat_id=chat_id, msg=message, parse_mode="markdown")
elif content_type == "new_chat_member":
if msg["new_chat_participant"]["id"] == get_bot_id():
await send_message(bot_obj=bot, chat_id=chat_id, msg=info_str, parse_mode="markdown")
@ -125,8 +140,9 @@ async def send_essen(chat_id: int) -> None:
async def send_status(text: str) -> None:
global config_ids
for chat_id in config_ids:
await send_message(bot_obj=bot, chat_id=chat_id, msg=text)
if logging_enabled:
for chat_id in config_ids:
await send_message(bot_obj=bot, chat_id=chat_id, msg=text)
async def send_message(bot_obj: DelegatorBot, chat_id: int, msg: str, parse_mode: Any = None,
@ -275,6 +291,7 @@ telegram_bot_token = config.get("telegram_bot_token")
url = config.get("url")
ids = config.get("ids")
config_ids = config.get("config_ids")
logging_enabled = config.get("logging_enabled")
bot = telepot.aio.DelegatorBot(telegram_bot_token, [
pave_event_space()(