mirror of
https://github.com/neoarz/Syntrel.git
synced 2025-12-25 03:40:11 +01:00
feat(mcquote): new command :)
Introduces a new /mcquote command that generates a custom Minecraft achievement quote image using skinmc.net. Updates README and media cog to register and document the new command.
This commit is contained in:
@@ -29,7 +29,7 @@
|
|||||||
| melonx | `melonx`, `transfer`, `mods`, `gamecrash`, `requirements`, `error`, `26` |
|
| melonx | `melonx`, `transfer`, `mods`, `gamecrash`, `requirements`, `error`, `26` |
|
||||||
| miscellaneous | `keanu`, `labubu`, `piracy`, `tryitandsee`, `rickroll`, `dontasktoask`, `support`|
|
| miscellaneous | `keanu`, `labubu`, `piracy`, `tryitandsee`, `rickroll`, `dontasktoask`, `support`|
|
||||||
| utilities | `translate`, `codepreview`, `dictionary` |
|
| utilities | `translate`, `codepreview`, `dictionary` |
|
||||||
| media | `download` |
|
| media | `download`, `mcquote` |
|
||||||
|
|
||||||
## Download
|
## Download
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ from discord.ext import commands
|
|||||||
from discord.ext.commands import Context
|
from discord.ext.commands import Context
|
||||||
|
|
||||||
from .download import download_command
|
from .download import download_command
|
||||||
|
from .mcquote import mcquote_command
|
||||||
|
|
||||||
|
|
||||||
def _require_group_prefix(context: Context) -> bool:
|
def _require_group_prefix(context: Context) -> bool:
|
||||||
@@ -28,7 +29,7 @@ class Media(commands.GroupCog, name="media"):
|
|||||||
color=0x7289DA
|
color=0x7289DA
|
||||||
)
|
)
|
||||||
embed.set_author(name="Media", icon_url="https://yes.nighty.works/raw/y5SEZ9.webp")
|
embed.set_author(name="Media", icon_url="https://yes.nighty.works/raw/y5SEZ9.webp")
|
||||||
embed.add_field(name="Available", value="download", inline=False)
|
embed.add_field(name="Available", value="download, mcquote", inline=False)
|
||||||
await context.send(embed=embed)
|
await context.send(embed=embed)
|
||||||
|
|
||||||
async def _invoke_hybrid(self, context: Context, name: str):
|
async def _invoke_hybrid(self, context: Context, name: str):
|
||||||
@@ -42,6 +43,10 @@ class Media(commands.GroupCog, name="media"):
|
|||||||
async def media_group_download(self, context: Context, *, url: str):
|
async def media_group_download(self, context: Context, *, url: str):
|
||||||
await self._invoke_hybrid(context, "download", url=url)
|
await self._invoke_hybrid(context, "download", url=url)
|
||||||
|
|
||||||
|
@media_group.command(name="mcquote")
|
||||||
|
async def media_group_mcquote(self, context: Context, *, text: str):
|
||||||
|
await self._invoke_hybrid(context, "mcquote", text=text)
|
||||||
|
|
||||||
@commands.check(_require_group_prefix)
|
@commands.check(_require_group_prefix)
|
||||||
@commands.hybrid_command(
|
@commands.hybrid_command(
|
||||||
name="download",
|
name="download",
|
||||||
@@ -50,8 +55,17 @@ class Media(commands.GroupCog, name="media"):
|
|||||||
async def download(self, context, *, url: str):
|
async def download(self, context, *, url: str):
|
||||||
return await download_command()(self, context, url=url)
|
return await download_command()(self, context, url=url)
|
||||||
|
|
||||||
|
@commands.check(_require_group_prefix)
|
||||||
|
@commands.hybrid_command(
|
||||||
|
name="mcquote",
|
||||||
|
description="Generate a custom Minecraft quote image.",
|
||||||
|
)
|
||||||
|
async def mcquote(self, context, *, text: str):
|
||||||
|
return await mcquote_command()(self, context, text=text)
|
||||||
|
|
||||||
async def setup(bot) -> None:
|
async def setup(bot) -> None:
|
||||||
cog = Media(bot)
|
cog = Media(bot)
|
||||||
await bot.add_cog(cog)
|
await bot.add_cog(cog)
|
||||||
|
|
||||||
bot.logger.info("Loaded extension 'media.download'")
|
bot.logger.info("Loaded extension 'media.download'")
|
||||||
|
bot.logger.info("Loaded extension 'media.mcquote'")
|
||||||
|
|||||||
141
cogs/media/mcquote.py
Normal file
141
cogs/media/mcquote.py
Normal file
@@ -0,0 +1,141 @@
|
|||||||
|
import asyncio
|
||||||
|
import os
|
||||||
|
import tempfile
|
||||||
|
import discord
|
||||||
|
from discord.ext import commands
|
||||||
|
import requests
|
||||||
|
import random
|
||||||
|
|
||||||
|
def mcquote_command():
|
||||||
|
@commands.hybrid_command(
|
||||||
|
name="mcquote",
|
||||||
|
description="Generate a custom Minecraft quote image.",
|
||||||
|
)
|
||||||
|
@commands.cooldown(1, 10, commands.BucketType.user)
|
||||||
|
async def mcquote(self, context, *, text: str = None):
|
||||||
|
if not text:
|
||||||
|
embed = discord.Embed(
|
||||||
|
title="Error",
|
||||||
|
description="Please provide text for the Minecraft quote.",
|
||||||
|
color=0xE02B2B,
|
||||||
|
)
|
||||||
|
embed.set_author(name="Media", icon_url="https://yes.nighty.works/raw/y5SEZ9.webp")
|
||||||
|
|
||||||
|
interaction = getattr(context, "interaction", None)
|
||||||
|
if interaction is not None:
|
||||||
|
if not interaction.response.is_done():
|
||||||
|
await interaction.response.send_message(embed=embed, ephemeral=True)
|
||||||
|
else:
|
||||||
|
await interaction.followup.send(embed=embed, ephemeral=True)
|
||||||
|
else:
|
||||||
|
await context.send(embed=embed, ephemeral=True)
|
||||||
|
return
|
||||||
|
|
||||||
|
if len(text) > 25:
|
||||||
|
embed = discord.Embed(
|
||||||
|
title="Error",
|
||||||
|
description="Text must be 25 characters or less.",
|
||||||
|
color=0xE02B2B,
|
||||||
|
)
|
||||||
|
embed.set_author(name="Media", icon_url="https://yes.nighty.works/raw/y5SEZ9.webp")
|
||||||
|
|
||||||
|
interaction = getattr(context, "interaction", None)
|
||||||
|
if interaction is not None:
|
||||||
|
if not interaction.response.is_done():
|
||||||
|
await interaction.response.send_message(embed=embed, ephemeral=True)
|
||||||
|
else:
|
||||||
|
await interaction.followup.send(embed=embed, ephemeral=True)
|
||||||
|
else:
|
||||||
|
await context.send(embed=embed, ephemeral=True)
|
||||||
|
return
|
||||||
|
|
||||||
|
processing_embed = discord.Embed(
|
||||||
|
title="Minecraft Quote (Processing)",
|
||||||
|
description="<a:mariospin:1423677027013103709> Generating quote... This may take a moment.",
|
||||||
|
color=0x7289DA,
|
||||||
|
)
|
||||||
|
processing_embed.set_author(name="Media", icon_url="https://yes.nighty.works/raw/y5SEZ9.webp")
|
||||||
|
|
||||||
|
interaction = getattr(context, "interaction", None)
|
||||||
|
if interaction is not None:
|
||||||
|
if not interaction.response.is_done():
|
||||||
|
await interaction.response.send_message(embed=processing_embed, ephemeral=True)
|
||||||
|
else:
|
||||||
|
await interaction.followup.send(embed=processing_embed, ephemeral=True)
|
||||||
|
else:
|
||||||
|
processing_msg = await context.send(embed=processing_embed)
|
||||||
|
|
||||||
|
quote_text = text.replace(" ", "+")
|
||||||
|
random_number = random.randint(1, 39)
|
||||||
|
mc_quote_url = f'https://skinmc.net/achievement/{random_number}/Achievement+Unlocked!/{quote_text}'
|
||||||
|
|
||||||
|
try:
|
||||||
|
response = requests.get(mc_quote_url)
|
||||||
|
response.raise_for_status()
|
||||||
|
|
||||||
|
with tempfile.NamedTemporaryFile(delete=False, suffix=".png") as temp_file:
|
||||||
|
temp_file.write(response.content)
|
||||||
|
temp_file_path = temp_file.name
|
||||||
|
|
||||||
|
embed = discord.Embed(
|
||||||
|
title="Minecraft Quote",
|
||||||
|
color=0x7289DA,
|
||||||
|
)
|
||||||
|
embed.set_author(name="Media", icon_url="https://yes.nighty.works/raw/y5SEZ9.webp")
|
||||||
|
embed.set_footer(text=f"Requested by {context.author.name}", icon_url=context.author.display_avatar.url)
|
||||||
|
|
||||||
|
with open(temp_file_path, 'rb') as f:
|
||||||
|
file = discord.File(f, filename="mcquote.png")
|
||||||
|
|
||||||
|
interaction = getattr(context, "interaction", None)
|
||||||
|
if interaction is not None:
|
||||||
|
await context.channel.send(embed=embed)
|
||||||
|
await context.channel.send(file=file)
|
||||||
|
try:
|
||||||
|
await interaction.delete_original_response()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
await processing_msg.delete()
|
||||||
|
await context.channel.send(embed=embed)
|
||||||
|
await context.channel.send(file=file)
|
||||||
|
|
||||||
|
os.remove(temp_file_path)
|
||||||
|
except requests.exceptions.RequestException:
|
||||||
|
embed = discord.Embed(
|
||||||
|
title="Error",
|
||||||
|
description="Failed to generate Minecraft quote. Please try again later.",
|
||||||
|
color=0xE02B2B,
|
||||||
|
)
|
||||||
|
embed.set_author(name="Media", icon_url="https://yes.nighty.works/raw/y5SEZ9.webp")
|
||||||
|
|
||||||
|
interaction = getattr(context, "interaction", None)
|
||||||
|
if interaction is not None:
|
||||||
|
try:
|
||||||
|
await interaction.delete_original_response()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
await interaction.followup.send(embed=embed, ephemeral=True)
|
||||||
|
else:
|
||||||
|
await processing_msg.delete()
|
||||||
|
await context.send(embed=embed, ephemeral=True)
|
||||||
|
except Exception as e:
|
||||||
|
embed = discord.Embed(
|
||||||
|
title="Error",
|
||||||
|
description=f"An unexpected error occurred: {str(e)}",
|
||||||
|
color=0xE02B2B,
|
||||||
|
)
|
||||||
|
embed.set_author(name="Media", icon_url="https://yes.nighty.works/raw/y5SEZ9.webp")
|
||||||
|
|
||||||
|
interaction = getattr(context, "interaction", None)
|
||||||
|
if interaction is not None:
|
||||||
|
try:
|
||||||
|
await interaction.delete_original_response()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
await interaction.followup.send(embed=embed, ephemeral=True)
|
||||||
|
else:
|
||||||
|
await processing_msg.delete()
|
||||||
|
await context.send(embed=embed, ephemeral=True)
|
||||||
|
|
||||||
|
return mcquote
|
||||||
Reference in New Issue
Block a user