From a10032426575ab3562f9d1c10f6c54eabb26eb07 Mon Sep 17 00:00:00 2001 From: Profitroll Date: Wed, 16 Apr 2025 18:05:07 +0200 Subject: [PATCH] Reformatted and cleaned up everything --- classes/pyrouser_sqlite.py | 8 ++------ main.py | 7 +++---- modules/database_mongo.py | 4 +--- modules/logging_utils.py | 12 +++++------- modules/migrator_sqlite.py | 4 +--- plugins/callbacks/callback.py | 4 +--- plugins/commands/command.py | 4 +--- plugins/language.py | 4 +--- pyproject.toml | 25 +++++++++++++++++++++++++ 9 files changed, 40 insertions(+), 32 deletions(-) create mode 100644 pyproject.toml diff --git a/classes/pyrouser_sqlite.py b/classes/pyrouser_sqlite.py index 5929026..522ce81 100644 --- a/classes/pyrouser_sqlite.py +++ b/classes/pyrouser_sqlite.py @@ -31,16 +31,12 @@ class PyroUser: ### Returns: * `PyroUser`: User with its database data. """ - db_entry = cursor.execute( - "SELECT id, locale FROM users WHERE id = ?", (id,) - ).fetchone() + db_entry = cursor.execute("SELECT id, locale FROM users WHERE id = ?", (id,)).fetchone() if db_entry is None: cursor.execute("INSERT INTO users VALUES (?, ?)", (id, locale)) cursor.connection.commit() - db_entry = cursor.execute( - "SELECT id, locale FROM users WHERE id = ?", (id,) - ).fetchone() + db_entry = cursor.execute("SELECT id, locale FROM users WHERE id = ?", (id,)).fetchone() if db_entry is None: raise RuntimeError("Could not find inserted user entry.") diff --git a/main.py b/main.py index 7e6e498..bb200bb 100644 --- a/main.py +++ b/main.py @@ -9,7 +9,8 @@ from sys import exit from libbot.utils import json_read from classes.pyroclient import PyroClient -from modules.logging_utils import get_logging_config, get_logger +from modules.logging_utils import get_logger, get_logging_config + # Main uses MongoDB implementation of DB, # but you can also select SQLite one below # from modules.migrator_sqlite import migrate_database @@ -52,9 +53,7 @@ def main(): logger.info("Migration finished. Exiting...") exit() - client = PyroClient( - scheduler=scheduler, commands_source=json_read(Path("commands.json")) - ) + client = PyroClient(scheduler=scheduler, commands_source=json_read(Path("commands.json"))) # Conversation(client) try: diff --git a/modules/database_mongo.py b/modules/database_mongo.py index ae5694a..ce56ff2 100644 --- a/modules/database_mongo.py +++ b/modules/database_mongo.py @@ -16,9 +16,7 @@ if db_config["user"] is not None and db_config["password"] is not None: db_config["name"], ) else: - con_string = "mongodb://{0}:{1}/{2}".format( - db_config["host"], db_config["port"], db_config["name"] - ) + con_string = "mongodb://{0}:{1}/{2}".format(db_config["host"], db_config["port"], db_config["name"]) db_client = AsyncClient(con_string) db: AsyncDatabase = db_client.get_database(name=db_config["name"]) diff --git a/modules/logging_utils.py b/modules/logging_utils.py index dd73b3a..2aaf953 100644 --- a/modules/logging_utils.py +++ b/modules/logging_utils.py @@ -1,11 +1,10 @@ +import logging +from logging import Logger from pathlib import Path from typing import Any, Dict from libbot.utils import config_get -import logging -from logging import Logger - def get_logging_config() -> Dict[str, Any]: return { @@ -22,9 +21,7 @@ def get_logging_config() -> Dict[str, Any]: "console": {"class": "logging.StreamHandler", "formatter": "systemd"}, }, "formatters": { - "simple": { - "format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s" - }, + "simple": {"format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s"}, "systemd": {"format": "%(name)s - %(levelname)s - %(message)s"}, }, "root": { @@ -33,5 +30,6 @@ def get_logging_config() -> Dict[str, Any]: }, } + def get_logger(name: str) -> Logger: - return logging.getLogger(name) \ No newline at end of file + return logging.getLogger(name) diff --git a/modules/migrator_sqlite.py b/modules/migrator_sqlite.py index 550235f..e6c036d 100644 --- a/modules/migrator_sqlite.py +++ b/modules/migrator_sqlite.py @@ -18,9 +18,7 @@ def migrate_database() -> None: user_locale = None if "locale" not in keys else keys["locale"] user_card = None if "card" not in keys else keys["card"] - cursor.execute( - "INSERT INTO users VALUES (?, ?)", (int(user), user_card, user_locale) - ) + cursor.execute("INSERT INTO users VALUES (?, ?)", (int(user), user_card, user_locale)) cursor.connection.commit() rename(Path("data/database.json"), Path("data/database.migrated.json")) diff --git a/plugins/callbacks/callback.py b/plugins/callbacks/callback.py index 56c73f6..1643ad9 100644 --- a/plugins/callbacks/callback.py +++ b/plugins/callbacks/callback.py @@ -6,6 +6,4 @@ from classes.pyroclient import PyroClient @PyroClient.on_callback_query(filters.regex("nothing")) # type: ignore async def callback_nothing(app: PyroClient, callback: CallbackQuery): - await callback.answer( - text=app._("nothing", "callbacks", locale=callback.from_user.language_code) - ) + await callback.answer(text=app._("nothing", "callbacks", locale=callback.from_user.language_code)) diff --git a/plugins/commands/command.py b/plugins/commands/command.py index c9bf0b4..3b69211 100644 --- a/plugins/commands/command.py +++ b/plugins/commands/command.py @@ -8,6 +8,4 @@ from classes.pyroclient import PyroClient ~filters.scheduled & filters.private & filters.command(["start"], prefixes=["/"]) # type: ignore ) async def command_start(app: PyroClient, message: Message): - await message.reply_text( - app._("start", "messages", locale=message.from_user.language_code) - ) + await message.reply_text(app._("start", "messages", locale=message.from_user.language_code)) diff --git a/plugins/language.py b/plugins/language.py index 673b72b..14e2cfa 100644 --- a/plugins/language.py +++ b/plugins/language.py @@ -18,9 +18,7 @@ async def command_language(app: PyroClient, message: Message): buttons: List[InlineButton] = [] for locale, data in app.in_every_locale("metadata").items(): - buttons.append( - InlineButton(f"{data['flag']} {data['name']}", f"language:{locale}") - ) + buttons.append(InlineButton(f"{data['flag']} {data['name']}", f"language:{locale}")) keyboard.add(*buttons) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..1581686 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,25 @@ +[project] +name = "PyrogramBotBase" +authors = [{ name = "Profitroll" }] +readme = "README.md" +requires-python = ">=3.11" + +[tool.black] +line-length = 108 +target-version = ["py311", "py312", "py313"] + +[tool.isort] +profile = "black" + +[tool.mypy] +namespace_packages = true +install_types = true +strict = true +show_error_codes = true + +[tool.pylint] +disable = ["line-too-long"] + +[tool.pylint.main] +extension-pkg-whitelist = ["ujson"] +py-version = 3.11 \ No newline at end of file