Compare commits

..

No commits in common. "fad86295999201d39c44ffd9421a138cbf963db2" and "06b910cf657876cde583cef11cf6a89d7e03f9e1" have entirely different histories.

3 changed files with 2 additions and 59 deletions

View file

@ -93,30 +93,3 @@ async def handle_talk(message: Message):
# При любых ошибках не падаем, а отдаём понятный fallback. # При любых ошибках не падаем, а отдаём понятный fallback.
logger.exception("Talk generation failed") logger.exception("Talk generation failed")
await message.reply("Бля, кент, чёт движок заглох. Попробуй позже.") await message.reply("Бля, кент, чёт движок заглох. Попробуй позже.")
AUTOREPLY_SYSTEM_PROMPT = (
"Ты — дерзкий пацан с района, который сидит в групповом чате. "
"Ты НЕ отвечаешь на вопрос — ты сам влез в разговор. "
"Прокомментируй сообщение коротко (1-2 предложения), дерзко, на фене. "
"Можешь пошутить, подколоть, согласиться или послать. "
"НЕ начинай с обращения. Не используй формальный язык."
)
async def generate_autoreply(text: str) -> str:
url = f"{LLAMA_API_URL.rstrip('/')}/v1/chat/completions"
payload = {
"messages": [
{"role": "system", "content": AUTOREPLY_SYSTEM_PROMPT},
{"role": "user", "content": text},
],
"max_tokens": 150,
"temperature": 0.9,
"top_p": 0.9,
}
async with aiohttp.ClientSession() as session:
async with session.post(url, json=payload, timeout=aiohttp.ClientTimeout(total=120)) as resp:
data = await resp.json()
return data["choices"][0]["message"]["content"].strip()

View file

@ -76,11 +76,6 @@ SCHEDULE = {
# --- Остальное --- # --- Остальное ---
KEYWORDS = {'крип', 'радиохэд', 'creep', 'radiohead'} KEYWORDS = {'крип', 'радиохэд', 'creep', 'radiohead'}
# --- Авто-ответы ИИ ---
AUTOREPLY_CHANCE = 0.10
AUTOREPLY_COOLDOWN = 120
AUTOREPLY_TRIGGERS = {'бот', 'фраер', 'кент', 'братуха', 'пацаны', 'чё как', 'базар'}
def get_hint_text(templates_str: str) -> str: def get_hint_text(templates_str: str) -> str:
return ( return (
"Команды:\n" "Команды:\n"

29
main.py
View file

@ -18,7 +18,7 @@ from aiogram.types import (
from aiogram.client.default import DefaultBotProperties from aiogram.client.default import DefaultBotProperties
# Локальные импорты # Локальные импорты
from AI.talk_handler import handle_talk, generate_autoreply from AI.talk_handler import handle_talk
from zparser import get_military_data from zparser import get_military_data
import config import config
@ -562,41 +562,16 @@ async def handle_gen_mem(message: Message, bot: Bot):
return return
await message.reply_photo(BufferedInputFile(output.getvalue(), filename="meme.jpg")) await message.reply_photo(BufferedInputFile(output.getvalue(), filename="meme.jpg"))
_last_autoreply_ts = 0
async def handle_keywords(message: Message): async def handle_keywords(message: Message):
global _last_autoreply_ts
if not message.text or message.text.startswith('/'): if not message.text or message.text.startswith('/'):
return return
text_lower = message.text.lower() if any(re.search(rf'\b{word}\b', message.text.lower()) for word in config.KEYWORDS):
if any(re.search(rf'\b{word}\b', text_lower) for word in config.KEYWORDS):
audio_path = config.BASE_DIR / "maket" / "Radiohead - Creep.mp3" audio_path = config.BASE_DIR / "maket" / "Radiohead - Creep.mp3"
if audio_path.exists(): if audio_path.exists():
await message.answer_audio( await message.answer_audio(
audio=FSInputFile(audio_path), audio=FSInputFile(audio_path),
caption="I'm a creep, I'm a weirdo...", caption="I'm a creep, I'm a weirdo...",
) )
return
import time as _time
now = _time.time()
triggered = any(trigger in text_lower for trigger in config.AUTOREPLY_TRIGGERS)
should_reply = triggered or (
random.random() < config.AUTOREPLY_CHANCE
and (now - _last_autoreply_ts) > config.AUTOREPLY_COOLDOWN
)
if should_reply:
try:
await message.bot.send_chat_action(chat_id=message.chat.id, action="typing")
response = await generate_autoreply(message.text)
if response:
await message.reply(response, parse_mode=None)
_last_autoreply_ts = now
except Exception:
logger.exception("Autoreply failed")
# --- Запуск --- # --- Запуск ---