It's version 0.4

This commit is contained in:
Niken
2025-10-19 14:28:41 +03:00
parent 772d3d5b83
commit 7b653d4dcc
32 changed files with 775 additions and 326 deletions
+57 -16
View File
@@ -1,16 +1,22 @@
from config import Config
import aiohttp
import ssl
import certifi
from aiogram.types import BufferedInputFile
from utils.antispam import admin_required
from storage.message_storage import save_message
from utils.antispam import admin_required, saving
from aiogram import Dispatcher, Bot
from aiogram.types import Message
from models.state import BotState
from aiogram.filters import Command
from logging import getLogger
logger = getLogger(__name__)
API_URL = "http://127.0.0.1:7700/speak"
ssl_context = ssl.create_default_context(cafile=certifi.where())
def register_handlers(dp: Dispatcher, state: BotState, bot: Bot):
@dp.message(Command("vadmin"))
@admin_required(0)
@@ -21,11 +27,26 @@ def register_handlers(dp: Dispatcher, state: BotState, bot: Bot):
return
phrase = parts[1]
# Запрос к TTS API
# URL с параметрами модели и голоса
url = f"{Config.DEEPGRAM_TTS_URL}model=aura-2-andromeda-en"
headers = {
"Authorization": f"Token {Config.DEEPGRAM_API_KEY}",
"Content-Type": "application/json",
}
# В JSON только text
payload = {"text": phrase}
async with aiohttp.ClientSession() as session:
async with session.post(API_URL, json={"text": phrase}) as resp:
async with session.post(
url, headers=headers, json=payload, ssl=ssl_context
) as resp:
if resp.status != 200:
await message.reply("Ошибка генерации аудио")
error_text = await resp.text()
await message.reply(
f"Ошибка генерации аудио: {resp.status} {error_text}"
)
return
audio_bytes = await resp.read()
audio_file = BufferedInputFile(audio_bytes, filename="speech.wav")
@@ -43,8 +64,12 @@ def register_handlers(dp: Dispatcher, state: BotState, bot: Bot):
@admin_required(0)
async def admin(message: Message):
raw_text = message.text or message.caption
if not raw_text and not (message.photo or message.document or message.audio or message.video):
await message.reply("❌ Укажи текст или прикрепи файл/медиа: /admin <сообщение>")
if not raw_text and not (
message.photo or message.document or message.audio or message.video
):
await message.reply(
"❌ Укажи текст или прикрепи файл/медиа: /admin <сообщение>"
)
return
# Отрезаем саму команду (/admin)
@@ -60,15 +85,21 @@ def register_handlers(dp: Dispatcher, state: BotState, bot: Bot):
elif message.document:
# Документ
await bot.send_document(chat_id, message.document.file_id, caption=text_to_send)
await bot.send_document(
chat_id, message.document.file_id, caption=text_to_send
)
elif message.audio:
# Аудио (музыка)
await bot.send_audio(chat_id, message.audio.file_id, caption=text_to_send)
await bot.send_audio(
chat_id, message.audio.file_id, caption=text_to_send
)
elif message.video:
# Видео
await bot.send_video(chat_id, message.video.file_id, caption=text_to_send)
await bot.send_video(
chat_id, message.video.file_id, caption=text_to_send
)
else:
# Только текст
@@ -85,8 +116,12 @@ def register_handlers(dp: Dispatcher, state: BotState, bot: Bot):
@admin_required(0)
async def id_admin(message: Message):
raw_text = message.text or message.caption
if not raw_text and not (message.photo or message.document or message.audio or message.video):
await message.reply("❌ Укажи ID чата и текст или прикрепи файл/медиа: /iadmin <chat_id> <сообщение>")
if not raw_text and not (
message.photo or message.document or message.audio or message.video
):
await message.reply(
"❌ Укажи ID чата и текст или прикрепи файл/медиа: /iadmin <chat_id> <сообщение>"
)
return
# Отрезаем саму команду (/iadmin)
@@ -111,19 +146,25 @@ def register_handlers(dp: Dispatcher, state: BotState, bot: Bot):
elif message.document:
# Документ
await bot.send_document(chat_id, message.document.file_id, caption=text_to_send)
await bot.send_document(
chat_id, message.document.file_id, caption=text_to_send
)
elif message.audio:
# Аудио (музыка)
await bot.send_audio(chat_id, message.audio.file_id, caption=text_to_send)
await bot.send_audio(
chat_id, message.audio.file_id, caption=text_to_send
)
elif message.video:
# Видео
await bot.send_video(chat_id, message.video.file_id, caption=text_to_send)
await bot.send_video(
chat_id, message.video.file_id, caption=text_to_send
)
else:
# Только текст
await bot.send_message(chat_id, text_to_send)
await bot.send_message(chat_id, text_to_send, parse_mode="Markdown")
logger.info(f"Сообщение отправлено в чат {chat_id}")
await message.answer("✅ Сообщение отправлено.")