[refactor]: Moved demotivators to fun
This commit is contained in:
parent
4b5e8b2880
commit
1bcce19153
@ -1,29 +0,0 @@
|
|||||||
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")
|
|
||||||
filename = join("tmp", f"{inter.id}_{image.filename}")
|
|
||||||
logger.debug(filename)
|
|
||||||
await image.save(filename)
|
|
||||||
Dem(title, text).create(filename, font_name="FreeSans.ttf")
|
|
||||||
with open('demresult.jpg', 'rb') as f:
|
|
||||||
await inter.response.send_message(file=discord.File(f))
|
|
||||||
remove(filename)
|
|
||||||
remove('demresult.jpg')
|
|
||||||
|
|
||||||
async def setup(bot):
|
|
||||||
await bot.add_cog(Demotivator())
|
|
20
cogs/fun.py
20
cogs/fun.py
@ -58,5 +58,25 @@ class Fun(commands.Cog):
|
|||||||
|
|
||||||
remove(join(tmp_dir, filename))
|
remove(join(tmp_dir, filename))
|
||||||
|
|
||||||
|
|
||||||
|
@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")
|
||||||
|
filename = join("tmp", f"{inter.id}_{image.filename}")
|
||||||
|
logger.debug(filename)
|
||||||
|
await image.save(filename)
|
||||||
|
Dem(title, text).create(filename, font_name="FreeSans.ttf")
|
||||||
|
with open('demresult.jpg', 'rb') as f:
|
||||||
|
await inter.response.send_message(file=discord.File(f))
|
||||||
|
remove(filename)
|
||||||
|
remove('demresult.jpg')
|
||||||
|
|
||||||
|
|
||||||
async def setup(bot):
|
async def setup(bot):
|
||||||
await bot.add_cog(Fun())
|
await bot.add_cog(Fun())
|
||||||
|
Reference in New Issue
Block a user