mirror of
https://gitflic.ru/project/alt-gnome/karkas.git
synced 2024-12-23 16:23:02 +03:00
feat: make save_messages optional in statistics
This commit is contained in:
parent
750b6be3a5
commit
b1d95a1496
@ -1,3 +1,5 @@
|
|||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from karkas_core.modules_system.public_api import (
|
from karkas_core.modules_system.public_api import (
|
||||||
get_module,
|
get_module,
|
||||||
register_outer_message_middleware,
|
register_outer_message_middleware,
|
||||||
@ -5,8 +7,15 @@ from karkas_core.modules_system.public_api import (
|
|||||||
|
|
||||||
from .main import StatisticsMiddleware
|
from .main import StatisticsMiddleware
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from karkas_blocks.standard.config import IConfig
|
||||||
|
|
||||||
|
config: "IConfig" = get_module("standard.config", "config")
|
||||||
|
|
||||||
|
|
||||||
def module_init():
|
def module_init():
|
||||||
|
config.register("statistics::save_messages", "boolean", default_value=False)
|
||||||
|
|
||||||
register_app_config = get_module("standard.database", "register_app_config")
|
register_app_config = get_module("standard.database", "register_app_config")
|
||||||
from .db import APP_CONFIG
|
from .db import APP_CONFIG
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
"privileged": true,
|
"privileged": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"required": {
|
"required": {
|
||||||
|
"standard.config": "^1.0.0",
|
||||||
"standard.database": "^1.0.0"
|
"standard.database": "^1.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -7,6 +7,12 @@ from .db.tables import ChatStats, Messages, UserStats
|
|||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from aiogram.types import Message, TelegramObject
|
from aiogram.types import Message, TelegramObject
|
||||||
|
|
||||||
|
from karkas_blocks.standard.config import IConfig
|
||||||
|
|
||||||
|
from karkas_core.modules_system.public_api import get_module
|
||||||
|
|
||||||
|
config: "IConfig" = get_module("standard.config", "config")
|
||||||
|
|
||||||
|
|
||||||
async def update_chat_stats(event: "Message"):
|
async def update_chat_stats(event: "Message"):
|
||||||
await ChatStats.insert(
|
await ChatStats.insert(
|
||||||
@ -53,6 +59,12 @@ async def save_messages(event: "Message"):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def get_user_stats(chat_id: int, user_id: int):
|
||||||
|
return (
|
||||||
|
await UserStats.select().where(UserStats.key == f"{chat_id}-{user_id}").first()
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class StatisticsMiddleware(BaseMiddleware):
|
class StatisticsMiddleware(BaseMiddleware):
|
||||||
async def __call__(
|
async def __call__(
|
||||||
self,
|
self,
|
||||||
@ -63,7 +75,9 @@ class StatisticsMiddleware(BaseMiddleware):
|
|||||||
|
|
||||||
await update_chat_stats(event)
|
await update_chat_stats(event)
|
||||||
await update_user_stats(event)
|
await update_user_stats(event)
|
||||||
await save_messages(event)
|
|
||||||
|
if config.get("statistics::save_messages"):
|
||||||
|
await save_messages(event)
|
||||||
|
|
||||||
result = await handler(event, data)
|
result = await handler(event, data)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user