forked from zovos/bot_tg
Fix api domain
This commit is contained in:
parent
99946bc923
commit
a85ab1c639
1 changed files with 42 additions and 1 deletions
43
main.py
43
main.py
|
|
@ -132,7 +132,8 @@ HINT_TEXT = (
|
|||
f"• /maket «id» «текст» — доступные: {templates_list_text()} (1: 737x414, точка 104,240).\n"
|
||||
"• /gen_mem Up:верх Down:низ — отправь с фото (как подпись) или ответом на фото.\n"
|
||||
"• /break — узнать, сколько минут до перекура.\n"
|
||||
"• /prices — цены с x-server.\n"
|
||||
"• /prices — старый способ цен.\n"
|
||||
"• /fetch — свежие цены с x-server.\n"
|
||||
"Подсказка: в группах команда должна быть слитно с ботом (/gen_mem@username)."
|
||||
)
|
||||
|
||||
|
|
@ -440,6 +441,44 @@ async def handle_prices(message: Message):
|
|||
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")
|
||||
if not token:
|
||||
|
|
@ -459,6 +498,7 @@ def main():
|
|||
BotCommand(command="break", description="Сколько минут до перекура"),
|
||||
BotCommand(command="size", description="хуй"),
|
||||
BotCommand(command="prices", description="цены x-server"),
|
||||
BotCommand(command="fetch", description="цены (новый источник)"),
|
||||
]
|
||||
)
|
||||
except Exception: # noqa: WPS440
|
||||
|
|
@ -472,6 +512,7 @@ def main():
|
|||
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"))
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue