From cfdc4fe33a05e5d0c736b26acb8a1a9b45cf71bb Mon Sep 17 00:00:00 2001 From: Ali Aljishi Date: Mon, 1 Apr 2024 16:37:43 +0100 Subject: [PATCH] supports translate reply, added help text --- cogs/commands/misc.py | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/cogs/commands/misc.py b/cogs/commands/misc.py index 9b8c9b5..9962669 100644 --- a/cogs/commands/misc.py +++ b/cogs/commands/misc.py @@ -3,7 +3,7 @@ import markovify from deep_translator import GoogleTranslator from discord.ext import commands -from discord.ext.commands import Bot, Context, clean_content +from discord.ext.commands import Bot, Context class Misc(commands.Cog): @@ -143,17 +143,31 @@ async def chat(self, ctx: Context, message: str = None, gpt4: bool = False): async def gpt4(self, ctx: Context, message: str): await self.chat(ctx, message, True) - @commands.hybrid_command() + translateHelp = """ + Translate a message from one language (source) to another (target) + + To reply translate, ignore the message parameter + + """ + + @commands.hybrid_command( + help=translateHelp, brief="translate text from one language to another" + ) async def translate( - self, ctx: Context, source: str, target: str, message: clean_content + self, + ctx: Context, + source: str = "auto", + target: str = "en", + *, + message: str = "", ): + repliedMessage = ctx.message.reference + if repliedMessage is not None: + message = await ctx.channel.fetch_message(repliedMessage.message_id) + message = message.content translated = GoogleTranslator(source=source, target=target).translate(message) await ctx.send(translated) - @commands.hybrid_command() - async def joeltech(self, ctx: Context): - await ctx.send("<:joel_tech:1217584610029076480>") - async def setup(bot: Bot): await bot.add_cog(Misc(bot))