Reformatted and cleaned up everything

This commit is contained in:
2025-04-16 18:05:07 +02:00
parent e90694f0aa
commit a100324265
9 changed files with 40 additions and 32 deletions

View File

@@ -31,16 +31,12 @@ class PyroUser:
### Returns: ### Returns:
* `PyroUser`: User with its database data. * `PyroUser`: User with its database data.
""" """
db_entry = cursor.execute( db_entry = cursor.execute("SELECT id, locale FROM users WHERE id = ?", (id,)).fetchone()
"SELECT id, locale FROM users WHERE id = ?", (id,)
).fetchone()
if db_entry is None: if db_entry is None:
cursor.execute("INSERT INTO users VALUES (?, ?)", (id, locale)) cursor.execute("INSERT INTO users VALUES (?, ?)", (id, locale))
cursor.connection.commit() cursor.connection.commit()
db_entry = cursor.execute( db_entry = cursor.execute("SELECT id, locale FROM users WHERE id = ?", (id,)).fetchone()
"SELECT id, locale FROM users WHERE id = ?", (id,)
).fetchone()
if db_entry is None: if db_entry is None:
raise RuntimeError("Could not find inserted user entry.") raise RuntimeError("Could not find inserted user entry.")

View File

@@ -9,7 +9,8 @@ from sys import exit
from libbot.utils import json_read from libbot.utils import json_read
from classes.pyroclient import PyroClient 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, # Main uses MongoDB implementation of DB,
# but you can also select SQLite one below # but you can also select SQLite one below
# from modules.migrator_sqlite import migrate_database # from modules.migrator_sqlite import migrate_database
@@ -52,9 +53,7 @@ def main():
logger.info("Migration finished. Exiting...") logger.info("Migration finished. Exiting...")
exit() exit()
client = PyroClient( client = PyroClient(scheduler=scheduler, commands_source=json_read(Path("commands.json")))
scheduler=scheduler, commands_source=json_read(Path("commands.json"))
)
# Conversation(client) # Conversation(client)
try: try:

View File

@@ -16,9 +16,7 @@ if db_config["user"] is not None and db_config["password"] is not None:
db_config["name"], db_config["name"],
) )
else: else:
con_string = "mongodb://{0}:{1}/{2}".format( con_string = "mongodb://{0}:{1}/{2}".format(db_config["host"], db_config["port"], db_config["name"])
db_config["host"], db_config["port"], db_config["name"]
)
db_client = AsyncClient(con_string) db_client = AsyncClient(con_string)
db: AsyncDatabase = db_client.get_database(name=db_config["name"]) db: AsyncDatabase = db_client.get_database(name=db_config["name"])

View File

@@ -1,11 +1,10 @@
import logging
from logging import Logger
from pathlib import Path from pathlib import Path
from typing import Any, Dict from typing import Any, Dict
from libbot.utils import config_get from libbot.utils import config_get
import logging
from logging import Logger
def get_logging_config() -> Dict[str, Any]: def get_logging_config() -> Dict[str, Any]:
return { return {
@@ -22,9 +21,7 @@ def get_logging_config() -> Dict[str, Any]:
"console": {"class": "logging.StreamHandler", "formatter": "systemd"}, "console": {"class": "logging.StreamHandler", "formatter": "systemd"},
}, },
"formatters": { "formatters": {
"simple": { "simple": {"format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s"},
"format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
},
"systemd": {"format": "%(name)s - %(levelname)s - %(message)s"}, "systemd": {"format": "%(name)s - %(levelname)s - %(message)s"},
}, },
"root": { "root": {
@@ -33,5 +30,6 @@ def get_logging_config() -> Dict[str, Any]:
}, },
} }
def get_logger(name: str) -> Logger: def get_logger(name: str) -> Logger:
return logging.getLogger(name) return logging.getLogger(name)

View File

@@ -18,9 +18,7 @@ def migrate_database() -> None:
user_locale = None if "locale" not in keys else keys["locale"] user_locale = None if "locale" not in keys else keys["locale"]
user_card = None if "card" not in keys else keys["card"] user_card = None if "card" not in keys else keys["card"]
cursor.execute( cursor.execute("INSERT INTO users VALUES (?, ?)", (int(user), user_card, user_locale))
"INSERT INTO users VALUES (?, ?)", (int(user), user_card, user_locale)
)
cursor.connection.commit() cursor.connection.commit()
rename(Path("data/database.json"), Path("data/database.migrated.json")) rename(Path("data/database.json"), Path("data/database.migrated.json"))

View File

@@ -6,6 +6,4 @@ from classes.pyroclient import PyroClient
@PyroClient.on_callback_query(filters.regex("nothing")) # type: ignore @PyroClient.on_callback_query(filters.regex("nothing")) # type: ignore
async def callback_nothing(app: PyroClient, callback: CallbackQuery): async def callback_nothing(app: PyroClient, callback: CallbackQuery):
await callback.answer( await callback.answer(text=app._("nothing", "callbacks", locale=callback.from_user.language_code))
text=app._("nothing", "callbacks", locale=callback.from_user.language_code)
)

View File

@@ -8,6 +8,4 @@ from classes.pyroclient import PyroClient
~filters.scheduled & filters.private & filters.command(["start"], prefixes=["/"]) # type: ignore ~filters.scheduled & filters.private & filters.command(["start"], prefixes=["/"]) # type: ignore
) )
async def command_start(app: PyroClient, message: Message): async def command_start(app: PyroClient, message: Message):
await message.reply_text( await message.reply_text(app._("start", "messages", locale=message.from_user.language_code))
app._("start", "messages", locale=message.from_user.language_code)
)

View File

@@ -18,9 +18,7 @@ async def command_language(app: PyroClient, message: Message):
buttons: List[InlineButton] = [] buttons: List[InlineButton] = []
for locale, data in app.in_every_locale("metadata").items(): for locale, data in app.in_every_locale("metadata").items():
buttons.append( buttons.append(InlineButton(f"{data['flag']} {data['name']}", f"language:{locale}"))
InlineButton(f"{data['flag']} {data['name']}", f"language:{locale}")
)
keyboard.add(*buttons) keyboard.add(*buttons)

25
pyproject.toml Normal file
View File

@@ -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