Fixed cross-import issue

This commit is contained in:
Profitroll 2022-09-15 12:55:33 +02:00
parent 02d945aef5
commit e9d083c156
3 changed files with 15 additions and 18 deletions

16
bot.py
View File

@ -13,14 +13,14 @@ if configGet("bot_token") != "12345678:asdfghjklzxcvbnm":
pid = getpid() pid = getpid()
app = Client("auto_zoom_public_bot", api_id=configGet("api_id"), api_hash=configGet("api_hash"), bot_token=configGet("bot_token")) app = Client("auto_zoom_public_bot", api_id=configGet("api_id"), api_hash=configGet("api_hash"), bot_token=configGet("bot_token"))
else: else:
logWrite("Could not start the bot. Please, configure token in config.json") logWrite("Could not start the bot. Please, configure token in config.json", logs_folder=configGet("logs"))
exit() exit()
@app.on_message(~ filters.scheduled & filters.command(["link", "start"], prefixes="/")) @app.on_message(~ filters.scheduled & filters.command(["link", "start"], prefixes="/"))
async def start(app, msg): async def start(app, msg):
logWrite(f'Got command start/link from {msg.from_user.id}') logWrite(f'Got command start/link from {msg.from_user.id}', logs_folder=configGet("logs"))
await app.send_chat_action(chat_id=msg.chat.id, action=ChatAction.TYPING) await app.send_chat_action(chat_id=msg.chat.id, action=ChatAction.TYPING)
@ -28,7 +28,7 @@ async def start(app, msg):
data = configGet("data") data = configGet("data")
if f"{msg.from_user.id}.json" not in listdir(f"{data}{sep}users{sep}"): if f"{msg.from_user.id}.json" not in listdir(f"{data}{sep}users{sep}"):
logWrite(f'Creating blank data file for {msg.from_user.id}') logWrite(f'Creating blank data file for {msg.from_user.id}', logs_folder=configGet("logs"))
jsonSave( f"{data}{sep}users{sep}{msg.from_user.id}.json", {"api_key": None, "linked": False, "context": {"action": None, "data": None}} ) jsonSave( f"{data}{sep}users{sep}{msg.from_user.id}.json", {"api_key": None, "linked": False, "context": {"action": None, "data": None}} )
if not userGet(msg.from_user.id, "linked"): if not userGet(msg.from_user.id, "linked"):
@ -40,7 +40,7 @@ async def start(app, msg):
@app.on_message(~ filters.scheduled & filters.command(["unlink"], prefixes="/")) @app.on_message(~ filters.scheduled & filters.command(["unlink"], prefixes="/"))
async def unlink(app, msg): async def unlink(app, msg):
logWrite(f'Got command ulink from {msg.from_user.id}') logWrite(f'Got command ulink from {msg.from_user.id}', logs_folder=configGet("logs"))
await app.send_chat_action(chat_id=msg.chat.id, action=ChatAction.TYPING) await app.send_chat_action(chat_id=msg.chat.id, action=ChatAction.TYPING)
@ -98,9 +98,9 @@ async def any_message_handler(app, msg):
keys_storage = jsonLoad(f"{data}{sep}keys_storage.json") keys_storage = jsonLoad(f"{data}{sep}keys_storage.json")
keys_storage[msg.text] = msg.from_user.id keys_storage[msg.text] = msg.from_user.id
jsonSave(f"{data}{sep}keys_storage.json", keys_storage) jsonSave(f"{data}{sep}keys_storage.json", keys_storage)
logWrite(f"Added apikey {msg.text} for user {msg.from_user.id}") logWrite(f"Added apikey {msg.text} for user {msg.from_user.id}", logs_folder=configGet("logs"))
else: else:
logWrite(f"User {msg.from_user.id} tried to pair with invalid apikey {msg.text}") logWrite(f"User {msg.from_user.id} tried to pair with invalid apikey {msg.text}", logs_folder=configGet("logs"))
await msg.reply_text(locale("key_wrong", "msg", locale=user_locale)) await msg.reply_text(locale("key_wrong", "msg", locale=user_locale))
userClear(msg.from_user.id, "context") userClear(msg.from_user.id, "context")
@ -109,7 +109,7 @@ async def any_message_handler(app, msg):
if __name__ == "__main__": if __name__ == "__main__":
logWrite(f'Starting with PID {str(pid)}') logWrite(f'Starting with PID {str(pid)}', logs_folder=configGet("logs"))
app.start() app.start()
app.send_message(configGet("admin"), f"Starting bot with pid `{pid}`") app.send_message(configGet("admin"), f"Starting bot with pid `{pid}`")
@ -139,6 +139,6 @@ if __name__ == "__main__":
idle() idle()
app.send_message(configGet("admin"), f"Shutting down bot with pid `{pid}`") app.send_message(configGet("admin"), f"Shutting down bot with pid `{pid}`")
logWrite(f'Shutting down with PID {pid}') logWrite(f'Shutting down with PID {pid}', logs_folder=configGet("logs"))
killProc(pid) killProc(pid)

View File

@ -10,8 +10,6 @@ from shutil import copyfileobj
from gzip import open as gzipopen from gzip import open as gzipopen
from psutil import Process from psutil import Process
from modules.functions_bot import configGet
def nowtimeGet(format="%H:%M:%S | %d.%m.%Y") -> str: def nowtimeGet(format="%H:%M:%S | %d.%m.%Y") -> str:
"""Return current local time formatted as arg. """Return current local time formatted as arg.
@ -25,7 +23,7 @@ def nowtimeGet(format="%H:%M:%S | %d.%m.%Y") -> str:
return datetime.now().strftime(format) return datetime.now().strftime(format)
def checkSize(logs_folder=f"{configGet('logs')}{sep}", log_size=1024) -> None: def checkSize(logs_folder=f"logs{sep}", log_size=1024) -> None:
"""Checks latest log file size and rotates it if needed. """Checks latest log file size and rotates it if needed.
### Args: ### Args:
@ -56,7 +54,7 @@ def checkSize(logs_folder=f"{configGet('logs')}{sep}", log_size=1024) -> None:
i += 1 i += 1
def logWrite(message: str, logs_folder=f"{configGet('logs')}{sep}", level="INFO") -> None: def logWrite(message: str, logs_folder=f"logs{sep}", level="INFO") -> None:
"""Append some message to latest log file. """Append some message to latest log file.
### Args: ### Args:

View File

@ -1,7 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
"""Essential set of functions needed for discord/telegram bots and other types of apps""" """Essential set of functions needed for discord/telegram bots and other types of apps"""
from types import NoneType
from typing import Union from typing import Union
from modules.functions import jsonLoad, jsonSave from modules.functions import jsonLoad, jsonSave
from os import sep, listdir from os import sep, listdir
@ -22,7 +21,7 @@ def configGet(key: str, *args: str) -> any:
return this_key[key] return this_key[key]
def configAppend(key: str, value: Union[str, float, int, bool, dict, list, NoneType], *args: str) -> None: def configAppend(key: str, value: Union[str, float, int, bool, dict, list, None], *args: str) -> None:
"""Set key to a value """Set key to a value
### Args: ### Args:
* key (str): The last key of the keys path. * key (str): The last key of the keys path.
@ -42,7 +41,7 @@ def configAppend(key: str, value: Union[str, float, int, bool, dict, list, NoneT
return return
def configRemove(key: str, value: Union[str, float, int, bool, dict, list, NoneType]) -> None: def configRemove(key: str, value: Union[str, float, int, bool, dict, list, None]) -> None:
"""Remove value from config's list key """Remove value from config's list key
### Args: ### Args:
@ -86,7 +85,7 @@ def locale(key: str, *args: str, locale=configGet("locale")) -> str:
return f'⚠ Locale in config is invalid: could not get "{key}" in {str(args)} from locale "{locale}"' return f'⚠ Locale in config is invalid: could not get "{key}" in {str(args)} from locale "{locale}"'
def userSet(userid: Union[str, int], key: str, value: Union[str, float, int, bool, dict, list, NoneType]) -> None: def userSet(userid: Union[str, int], key: str, value: Union[str, float, int, bool, dict, list, None]) -> None:
"""Set user's variable """Set user's variable
### Args: ### Args:
@ -135,7 +134,7 @@ def userClear(userid: Union[str, int], key: str) -> None:
pass pass
def localeName(command: str, option: Union[str, NoneType]): def localeName(command: str, option: Union[str, None]):
"""Get name of a command or command's option """Get name of a command or command's option
### Args: ### Args:
@ -158,7 +157,7 @@ def localeName(command: str, option: Union[str, NoneType]):
return output return output
def localeDescription(command: str, option: Union[str, NoneType]): def localeDescription(command: str, option: Union[str, None]):
"""Get description of a command or command's option """Get description of a command or command's option
### Args: ### Args: