maple/commands/yuri.py

55 lines
2.1 KiB
Python
Raw Normal View History

2024-04-06 18:32:49 +02:00
from interactions import Extension, slash_command, SlashContext, EmbedAttachment, EmbedFooter, EmbedField, Embed
import requests
from random import choice
from urllib.parse import quote
from datetime import datetime, timedelta
tag_blacklist = ["loli", "shota", "gore", "guro", "scat", "3d", "futanari", "animated", "video"]
timeout = datetime.now()
class YuriExtension(Extension):
@slash_command(name="yuri", description="Pošle náhodný yuri obrázek z Gelbooru (NSFW pouze v NSFW kanálech)")
2024-04-06 18:53:24 +02:00
async def yuri(self, ctx: SlashContext):
2024-04-06 18:32:49 +02:00
global timeout
await ctx.defer()
if datetime.now() < timeout:
await ctx.respond(ephemeral="Počkej chvíli než pošleš tenhle příkaz znovu")
return
timeout = datetime.now() + timedelta(seconds=5)
p = "yuri sort:random"
for tag in tag_blacklist:
p += f" -{tag}"
if not ctx.channel.nsfw:
p += " rating:general score:>100"
else:
p += " rating:explicit score:>100"
r = requests.get("https://gelbooru.com/index.php?page=dapi&s=post&q=index&api_key=anonymous&user_id=9455&json"
f"=1&tags={quote(p)}", headers={"User-Agent": "Maplebot/1.0.0"})
if r.status_code > 399:
print("Error while requesting from Gelbooru!")
print(r.status_code)
print(r.json())
await ctx.respond(ephemeral=True, content="Chyba při zpracování požadavku")
return
posts = r.json()["post"]
pick = choice(posts)
while pick["has_children"] is True and pick["rating"] != "general":
pick = choice(posts)
tags = pick["tags"]
if len(tags) >= 4096:
tags = tags[0:4093] + "..."
await ctx.respond(embed=Embed(
title="Čáry máry!",
url=f"https://gelbooru.com/index.php?page=post&s=view&id={pick['id']}",
images=[EmbedAttachment(url=pick["file_url"])],
description=tags,
footer=EmbedFooter(text="Skrz gelbooru.com", icon_url="https://gelbooru.com/favicon.png")
)
)