This commit is contained in:
2024-11-16 18:45:05 +03:00
parent ee9eafa09f
commit 502c07a2c9
11 changed files with 206 additions and 66 deletions

View File

@@ -9,7 +9,9 @@ from aiogram.fsm.context import FSMContext
from aiogram.types import FSInputFile
from helper_bot.filters.main import ChatTypeFilter
from helper_bot.middlewares.blacklist_middleware import BlacklistMiddleware
from helper_bot.utils.base_dependency_factory import BaseDependencyFactory
from helper_bot.utils.helper_func import update_user_info, check_user_emoji
from logs.custom_logger import logger
from voice_bot.keyboards.keyboards import get_main_keyboard
from voice_bot.utils.helper_func import last_message
@@ -25,6 +27,7 @@ LOGS = bdf.settings['Settings']['logs']
TEST = bdf.settings['Settings']['test']
BotDB = bdf.get_db()
voice_router.message.middleware(BlacklistMiddleware())
@voice_router.message(
@@ -33,6 +36,8 @@ BotDB = bdf.get_db()
)
async def restart_function(message: types.Message, state: FSMContext):
await message.forward(chat_id=GROUP_FOR_LOGS)
await update_user_info('voice', message)
check_user_emoji(message.from_user.id)
markup = get_main_keyboard()
await message.answer(text='Я перезапущен!',
reply_markup=markup)
@@ -45,9 +50,11 @@ async def restart_function(message: types.Message, state: FSMContext):
)
async def help_function(message: types.Message, state: FSMContext):
await message.forward(chat_id=GROUP_FOR_LOGS)
await update_user_info('voice', message)
check_user_emoji(message.from_user.id)
await message.answer(
text='Скорее всего ответы на твои вопросы есть здесь, ознакомься: https://telegra.ph/Instrukciya-k-botu-Golosa-Bijsk-10-11-2'
'\nЕсли это не поможет, пиши в тг: @Kerrad1', disable_web_page_preview=not PREVIEW_LINK)
'\nЕсли это не поможет, пиши в личку: @Kerrad1', disable_web_page_preview=not PREVIEW_LINK)
await state.set_state('START')
@@ -58,6 +65,8 @@ async def help_function(message: types.Message, state: FSMContext):
async def start(message: types.Message, state: FSMContext):
await state.set_state("START")
await message.forward(chat_id=GROUP_FOR_LOGS)
await update_user_info('voice', message)
check_user_emoji(message.from_user.id)
try:
name_stick_hello = list(Path('Stick').rglob('Hello_*'))
random_stick_hello = random.choice(name_stick_hello)
@@ -153,12 +162,6 @@ async def save_voice_message(message: types.Message, state: FSMContext):
# Сохраняем в базку
BotDB.add_audio_record(file_name, author_id, date_added, 0, file_id)
# Сохраняем файл на сервер
# file_info = message.bot.get_file(file_id=message.voice.file_id)
# downloaded_file = message.bot.download_file(file_path=file_info.file_path)
# with open(f'voice_users/{file_name}.ogg', 'wb') as new_file:
# new_file.write(downloaded_file)
file_info = await message.bot.get_file(file_id=message.voice.file_id)
downloaded_file = await message.bot.download_file(file_path=file_info.file_path)
with open(f'voice_users/{file_name}.ogg', 'wb') as new_file:
@@ -181,12 +184,11 @@ async def standup_listen_audio(message: types.Message, state: FSMContext):
check_audio = BotDB.check_listen_audio(user_id=message.from_user.id)
list_audio = list(check_audio)
markup = get_main_keyboard()
await message.forward(chat_id=GROUP_FOR_LOGS)
if not list_audio:
await message.answer(text='Прости, ты прослушал все аудио😔. Возвращайся позже, возможно наша база пополнится',
reply_markup=markup)
message_with_date = last_message()
message.send_message(chat_id=message.chat.id, text=message_with_date, parse_mode="html")
await message.answer(text=message_with_date, parse_mode="html")
else:
number_element = random.randint(0, len(list_audio) - 1)
audio_for_user = check_audio[number_element]
@@ -196,5 +198,5 @@ async def standup_listen_audio(message: types.Message, state: FSMContext):
# Маркируем сообщение как прослушанное
BotDB.mark_listened_audio(audio_for_user, user_id=message.from_user.id)
await message.bot.send_voice(message.chat.id, voice=voice, reply_markup=markup)
await message.forward(chat_id=GROUP_FOR_LOGS)
await message.answer(text=f'Осталось непрослушанных: <b>{len(check_audio)}</b>', reply_markup=markup)
await state.set_state('START')

View File

@@ -3,7 +3,7 @@ from aiogram.client.default import DefaultBotProperties
from aiogram.fsm.storage.memory import MemoryStorage
from aiogram.fsm.strategy import FSMStrategy
from voice_bot.voice_handler.voice_handler import voice_router
from voice_bot.handlers.voice_handler import voice_router
async def start_bot(bdf):