Compare commits
2 commits
06b910cf65
...
fad8629599
| Author | SHA1 | Date | |
|---|---|---|---|
| fad8629599 | |||
|
|
126ae083cb |
3 changed files with 59 additions and 2 deletions
|
|
@ -93,3 +93,30 @@ 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()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,11 @@ 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
29
main.py
|
|
@ -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
|
from AI.talk_handler import handle_talk, generate_autoreply
|
||||||
from zparser import get_military_data
|
from zparser import get_military_data
|
||||||
import config
|
import config
|
||||||
|
|
||||||
|
|
@ -562,16 +562,41 @@ 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
|
||||||
if any(re.search(rf'\b{word}\b', message.text.lower()) for word in config.KEYWORDS):
|
text_lower = message.text.lower()
|
||||||
|
|
||||||
|
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")
|
||||||
|
|
||||||
# --- Запуск ---
|
# --- Запуск ---
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue