This repository has been archived on 2025-01-28. You can view files and clone it, but cannot push or open issues or pull requests.
natsuko/cogs/demotivator.py

30 lines
1022 B
Python
Raw Normal View History

2023-05-03 19:53:01 +03:00
import discord
from discord import app_commands
from discord.ext import commands
from simpledemotivators import Demotivator as Dem
from os import remove
from os.path import join
from loguru import logger
class Demotivator(commands.Cog):
@app_commands.command()
async def demotivator(self, inter: discord.Interaction, title: str, text: str, image: discord.Attachment):
logger.debug((title, text))
if not "image" in image.content_type:
await inter.response.send_message("Это не изображение")
return
logger.debug("Meow")
2023-05-04 16:19:06 +03:00
filename = join("tmp", f"{inter.id}_{image.filename}")
2023-05-03 19:53:01 +03:00
logger.debug(filename)
await image.save(filename)
Dem(title, text).create(filename, font_name="FreeSans.ttf")
2023-05-04 16:19:06 +03:00
with open('demresult.jpg', 'rb') as f:
2023-05-03 19:53:01 +03:00
await inter.response.send_message(file=discord.File(f))
remove(filename)
2023-05-04 16:19:06 +03:00
remove('demresult.jpg')
2023-05-03 19:53:01 +03:00
async def setup(bot):
await bot.add_cog(Demotivator())