Третья часть: сделаны обработчики команд

This commit is contained in:
Verum
2025-02-22 11:10:16 +07:00
parent 3dcd49a3cc
commit 3bb01751c3
20 changed files with 280 additions and 28 deletions

View File

@@ -3,6 +3,11 @@
from aiogram.types import ContentType
# Настройка экспорта из модуля
__all__ = ("types_message",)
# Функция определения типа сообщения
def types_message(message):
# Словарь для соответствия типов сообщений
content_types = {

View File

@@ -3,4 +3,5 @@
# Экспортирование модулей во внешние слои проекта
from .logs import *
from .msg_logger import *
from .start_info_out import *

View File

@@ -3,7 +3,7 @@
import sys
from loguru import logger
from ProjectsFiles.configs.config import BotLogs
from ProjectsFiles import BotLogs
# Создание обычного логгера + логгер в файл
async def setup_logger():
@@ -36,18 +36,3 @@ async def setup_logger():
diagnose=True,
level="ERROR",
filter=lambda record: record["level"].name == "ERROR")"""
# Создание функции логирования на обычные сообщения
async def common_msg_logginger(message,
name : str = "Пользователь",
message_type : str = "Медиа",
log_type : str = "Message"):
if BotLogs.permission_msg:
# Проверка на наличие текста и его типа
if message.text is None:
logger.bind(log_type=log_type, user=f"@{message.from_user.username}").info(
f"Получено сообщение из ({name}) : {message_type}")
else:
logger.bind(log_type=log_type, user=f"@{message.from_user.username}").info(
f"Получено сообщение из ({name}) : {message.text}")

View File

@@ -0,0 +1,19 @@
# BotLibrary/loggers/msg_logger.py
# Логгер для всех не обработанных сообщений
from .logs import logger
from ProjectsFiles import BotLogs
from ..analytics.type_msg import types_message
# Настройка экспорта из модуля
__all__ = ("logger_msg",)
# Создание функции логирования на обычные сообщения
async def logger_msg(message, log_type : str = "Message"):
user = f"@{message.from_user.username or message.from_user.id}"
if BotLogs.permission:
# Проверка на наличие текста и его типа
if message.text is None:
logger.bind(log_type=log_type, user=user).info(f"Получено сообщение из ({message.chat.id}) : {types_message(message)}")
else:
logger.bind(log_type=log_type, user=user).info(f"Получено сообщение из ({message.chat.id}) : {message.text}")

View File

@@ -4,3 +4,4 @@
# Экспортирование модулей во внешние слои проекта
from .bots import *
from .bot_edit import *
from .directory import *

View File

@@ -0,0 +1,26 @@
# BotLibrary/system/directory.py
# Создание пустых директорий при первом запуске
import os
from ProjectsFiles import ProjectPath, TypeDirectory
# Настройка экспорта из модуля
__all__ = ("create_directories", "setup_directories")
# Функция создания пустых директорий
async def create_directories(base_directory, subdirectories):
# Создание директорий и файлов в каждой из них
for subdirectory in subdirectories:
directory_path = os.path.join(base_directory, subdirectory)
# Проверка, существует ли директория, если нет - создаём
if not os.path.exists(directory_path):
os.makedirs(directory_path)
# Начальная установка пустых директорий
async def setup_directories():
await create_directories(ProjectPath.personal_media, TypeDirectory.media_directories)
# await create_directories(ProjectPath.received_media, TypeDirectory.media_directories)
# await create_directories(ProjectPath.bot_files, TypeDirectory.avatar_directories)
# await create_directories(ProjectPath.msg, TypeDirectory.msg_directories)

View File

@@ -3,9 +3,14 @@
import pytz
from datetime import datetime
from tzlocal import get_localzone
from apscheduler.schedulers.asyncio import AsyncIOScheduler
from ProjectsFiles import BotVar
# Создание планировщика
scheduler = AsyncIOScheduler(timezone=get_localzone().key)
# Функция получение времени по Московскому времени
def get_moscow_time():
moscow_tz = pytz.timezone('Europe/Moscow')
@@ -17,7 +22,3 @@ def get_moscow_time():
def get_host_time():
host_time = datetime.now()
return host_time.strftime(BotVar.time_format)
# Создание планировщика
scheduler = AsyncIOScheduler(timezone=get_moscow_time())