Добавлена баблиотека для работы в голосовых

This commit is contained in:
2025-08-22 14:45:54 +07:00
parent 99feb5e125
commit c4bdd49a66
2 changed files with 10 additions and 9 deletions

Binary file not shown.

View File

@@ -1,3 +1,6 @@
import logging
logging.basicConfig(level=logging.INFO, force=True, format="%(asctime)s %(levelname)s: %(message)s", datefmt="%d-%m-%Y %H:%M:%S")
import inspect import inspect
import disnake import disnake
from disnake.ext import commands from disnake.ext import commands
@@ -12,7 +15,6 @@ from fnmatch import fnmatch
import traceback import traceback
import json import json
import re import re
import logging
from constants.global_constants import * from constants.global_constants import *
from libs.tokens_formatter import TOKENS from libs.tokens_formatter import TOKENS
@@ -27,8 +29,7 @@ from sqlalchemy.schema import CreateTable
import tldextract import tldextract
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO, force=True, format="%(asctime)s %(name)s %(levelname)s: %(message)s", datefmt="%H:%M:%S")
class AnyBots(commands.Bot): class AnyBots(commands.Bot):
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -324,7 +325,7 @@ class MainBot(AnyBots):
try: try:
return await func(*args, **kwargs) return await func(*args, **kwargs)
except Exception: except Exception:
logging.exception(f"{datetime.datetime.now().strftime('%H:%M:%S %d-%m-%Y')}:: [ERROR] {func.__name__}:\n{traceback.format_exc()}") logger.exception(f"{datetime.datetime.now().strftime('%H:%M:%S %d-%m-%Y')}:: [ERROR] {func.__name__}:\n{traceback.format_exc()}")
return wrapper return wrapper
@tasks.loop(seconds=30) @tasks.loop(seconds=30)
@@ -645,19 +646,19 @@ async def run_bot(bot, token, stop_event):
try: try:
await bot.start(token) await bot.start(token)
except Exception as e: except Exception as e:
logging.exception(f"Бот {bot.user.name if hasattr(bot, 'user') else 'Unknown'} упал с ошибкой: {e}") logger.exception(f"Бот {bot.user.name if hasattr(bot, 'user') else 'Unknown'} упал с ошибкой: {e}")
stop_event.set() # Сигнализируем об остановке stop_event.set() # Сигнализируем об остановке
async def monitor_stop(stop_event, bots): async def monitor_stop(stop_event, bots):
await stop_event.wait() await stop_event.wait()
logging.info(f"{datetime.datetime.now().strftime('%H:%M:%S %d-%m-%Y')}:: Получен сигнал остановки, завершаю всех ботов...") logger.info(f"{datetime.datetime.now().strftime('%H:%M:%S %d-%m-%Y')}:: Получен сигнал остановки, завершаю всех ботов...")
for bot in bots: for bot in bots:
if not bot.is_closed(): if not bot.is_closed():
try: try:
await bot.close() await bot.close()
except Exception as e: except Exception as e:
logging.exception(f"Ошибка при закрытии бота: {e}") logger.exception(f"Ошибка при закрытии бота: {e}")
await asyncio.sleep(0.1) await asyncio.sleep(0.1)
@@ -689,9 +690,9 @@ async def main():
await asyncio.gather(*bot_tasks, monitor_task) await asyncio.gather(*bot_tasks, monitor_task)
except KeyboardInterrupt: except KeyboardInterrupt:
logging.info("Боты остановлены по запросу пользователя") logger.info("Боты остановлены по запросу пользователя")
except Exception as e: except Exception as e:
logging.exception(f"Произошла критическая ошибка: {e}") logger.exception(f"Произошла критическая ошибка: {e}")
finally: finally:
if bot is not None: if bot is not None:
await bot.BotOff() await bot.BotOff()