Reformatted and cleaned up everything
This commit is contained in:
parent
e90694f0aa
commit
a100324265
@ -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.")
|
||||
|
7
main.py
7
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:
|
||||
|
@ -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"])
|
||||
|
@ -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)
|
||||
return logging.getLogger(name)
|
||||
|
@ -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"))
|
||||
|
@ -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))
|
||||
|
@ -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))
|
||||
|
@ -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)
|
||||
|
||||
|
25
pyproject.toml
Normal file
25
pyproject.toml
Normal 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
|
Loading…
x
Reference in New Issue
Block a user