forked from zovos/bot_tg
Compare commits
9 commits
a5b0691a4e
...
a85ab1c639
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a85ab1c639 | ||
|
|
99946bc923 | ||
|
|
f385bedd9b | ||
|
|
1d79125500 | ||
|
|
aafb64ad4e | ||
|
|
11ad1c43c9 | ||
|
|
5072450244 | ||
|
|
e151ae5269 | ||
| 8ba3ea1e0a |
4 changed files with 105 additions and 3 deletions
Binary file not shown.
107
main.py
107
main.py
|
|
@ -2,15 +2,16 @@ import asyncio
|
|||
import logging
|
||||
import os
|
||||
import re
|
||||
import requests
|
||||
from io import BytesIO
|
||||
from pathlib import Path
|
||||
from textwrap import wrap
|
||||
import random
|
||||
|
||||
from aiogram import Bot, Dispatcher, F
|
||||
from aiogram import Bot, Dispatcher, F, types
|
||||
from aiogram.enums import ParseMode
|
||||
from aiogram.filters import Command, CommandStart
|
||||
from aiogram.types import BufferedInputFile, Message, BotCommand
|
||||
from aiogram.types import BufferedInputFile, Message, BotCommand, FSInputFile
|
||||
from aiogram.client.default import DefaultBotProperties
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
from datetime import datetime, time, timedelta
|
||||
|
|
@ -131,6 +132,8 @@ HINT_TEXT = (
|
|||
f"• /maket «id» «текст» — доступные: {templates_list_text()} (1: 737x414, точка 104,240).\n"
|
||||
"• /gen_mem Up:верх Down:низ — отправь с фото (как подпись) или ответом на фото.\n"
|
||||
"• /break — узнать, сколько минут до перекура.\n"
|
||||
"• /prices — старый способ цен.\n"
|
||||
"• /fetch — свежие цены с x-server.\n"
|
||||
"Подсказка: в группах команда должна быть слитно с ботом (/gen_mem@username)."
|
||||
)
|
||||
|
||||
|
|
@ -382,9 +385,99 @@ async def handle_size(message: Message):
|
|||
|
||||
await message.answer(
|
||||
f"📏 Твой хуек: {size} см\n"
|
||||
f"Ты {status}"
|
||||
f"Ты: {status}"
|
||||
)
|
||||
|
||||
KEYWORDS = {'крип', 'радиохэд', 'creep', 'radiohead'}
|
||||
# I'M CREEP
|
||||
async def handle_keywords(message: types.Message):
|
||||
|
||||
if message.text and message.text.startswith('/'):
|
||||
return
|
||||
|
||||
text = message.text.lower()
|
||||
|
||||
if any(re.search(rf'\b{word}\b', text) for word in KEYWORDS):
|
||||
audio_path = BASE_DIR / "maket" / "Radiohead - Creep.mp3"
|
||||
|
||||
if audio_path.exists():
|
||||
await message.answer_audio(
|
||||
audio=FSInputFile(audio_path),
|
||||
caption="I'm a creep, I'm a weirdo..."
|
||||
)
|
||||
else:
|
||||
logger.warning(f"Файл не найден по пути: {audio_path}")
|
||||
|
||||
async def handle_prices(message: Message):
|
||||
def fetch():
|
||||
return requests.get(
|
||||
"https://bebrik.xyz/magnit/products",
|
||||
headers={"X-Token": "sisi"},
|
||||
timeout=10,
|
||||
)
|
||||
|
||||
try:
|
||||
resp = await asyncio.to_thread(fetch)
|
||||
|
||||
if resp.status_code != 200:
|
||||
await message.answer("пошел нахуй")
|
||||
return
|
||||
|
||||
data = resp.json()
|
||||
|
||||
if not data:
|
||||
await message.answer("иди нахуй")
|
||||
return
|
||||
|
||||
text = "смерть в 25:\n\n"
|
||||
for item in data:
|
||||
name = item.get("name")
|
||||
price = item.get("price")
|
||||
text += f"{name} — {price} ₽\n"
|
||||
|
||||
await message.answer(text[:4000])
|
||||
|
||||
except Exception:
|
||||
await message.answer("unable to connect x-server гандон")
|
||||
|
||||
|
||||
async def handle_fetch(message: Message):
|
||||
def fetch():
|
||||
return requests.get(
|
||||
"https://mirror.porno4free.ru/magnit/magnit/prices/all",
|
||||
headers={"x-token": "secret_token"},
|
||||
timeout=10,
|
||||
)
|
||||
|
||||
try:
|
||||
resp = await asyncio.to_thread(fetch)
|
||||
if resp.status_code != 200:
|
||||
await message.reply("пошел нахуй")
|
||||
return
|
||||
|
||||
data = resp.json()
|
||||
if not isinstance(data, dict) or not data:
|
||||
await message.reply("иди нахуй")
|
||||
return
|
||||
|
||||
lines = ["смерть в 25:"]
|
||||
# сортируем категории для стабильного вывода
|
||||
for group in sorted(data.keys()):
|
||||
items = data.get(group)
|
||||
lines.append(f"\n{group}:")
|
||||
if not isinstance(items, list):
|
||||
continue
|
||||
for item in items:
|
||||
name = item.get("name")
|
||||
price = item.get("price")
|
||||
if not name or price is None:
|
||||
continue
|
||||
lines.append(f"{name} — {price} ₽")
|
||||
text = "\n".join(lines)
|
||||
await message.answer(text[:4000])
|
||||
except Exception:
|
||||
await message.answer("unable to connect x-server гандон")
|
||||
|
||||
|
||||
def main():
|
||||
token = os.getenv("BOT_TOKEN")
|
||||
|
|
@ -404,6 +497,8 @@ def main():
|
|||
BotCommand(command="gen_mem", description="Мем из фото (ответом)"),
|
||||
BotCommand(command="break", description="Сколько минут до перекура"),
|
||||
BotCommand(command="size", description="хуй"),
|
||||
BotCommand(command="prices", description="цены x-server"),
|
||||
BotCommand(command="fetch", description="цены (новый источник)"),
|
||||
]
|
||||
)
|
||||
except Exception: # noqa: WPS440
|
||||
|
|
@ -416,12 +511,18 @@ def main():
|
|||
dp.message.register(handle_break, Command("break"))
|
||||
dp.message.register(handle_maket, Command("maket"))
|
||||
dp.message.register(handle_size, Command("size"))
|
||||
dp.message.register(handle_prices, Command("prices"))
|
||||
dp.message.register(handle_fetch, Command("fetch"))
|
||||
|
||||
|
||||
|
||||
async def handle_gen_mem_cmd(message: Message, bot: Bot):
|
||||
await handle_gen_mem(message, bot)
|
||||
|
||||
dp.message.register(handle_gen_mem_cmd, Command("gen_mem"))
|
||||
|
||||
dp.message.register(handle_keywords, F.text)
|
||||
|
||||
logger.info("Bot is starting...")
|
||||
asyncio.run(dp.start_polling(bot, allowed_updates=dp.resolve_used_update_types()))
|
||||
|
||||
|
|
|
|||
BIN
maket/Radiohead - Creep.mp3
Normal file
BIN
maket/Radiohead - Creep.mp3
Normal file
Binary file not shown.
|
|
@ -1,2 +1,3 @@
|
|||
aiogram==3.4.1
|
||||
pillow==10.3.0
|
||||
requests==2.31.0
|
||||
|
|
|
|||
Loading…
Reference in a new issue