From e0246620123c6b5191a024df72e803c3224a3927 Mon Sep 17 00:00:00 2001 From: Ali Aljishi Date: Mon, 1 Apr 2024 16:03:50 +0100 Subject: [PATCH 1/2] added a translate command --- apollo.py | 1 - cogs/commands/joeltech.py | 22 ---------------------- cogs/commands/misc.py | 13 ++++++++++++- 3 files changed, 12 insertions(+), 24 deletions(-) delete mode 100644 cogs/commands/joeltech.py diff --git a/apollo.py b/apollo.py index 0eb6cbc..0e01c98 100644 --- a/apollo.py +++ b/apollo.py @@ -27,7 +27,6 @@ "cogs.commands.date", "cogs.commands.event_sync", "cogs.commands.flip", - "cogs.commands.joeltech", "cogs.commands.karma_admin", "cogs.commands.karma_blacklist", "cogs.commands.karma", diff --git a/cogs/commands/joeltech.py b/cogs/commands/joeltech.py deleted file mode 100644 index 4847a20..0000000 --- a/cogs/commands/joeltech.py +++ /dev/null @@ -1,22 +0,0 @@ -from discord.ext import commands -from discord.ext.commands import Bot, Context, clean_content - -LONG_HELP_TEXT = """ -Summon the Joel of the Tech. -""" - - -SHORT_HELP_TEXT = """Joel Tech is here to help""" - - -class JoelTech(commands.Cog): - def __init__(self, bot: Bot): - self.bot = bot - - @commands.hybrid_command(help=LONG_HELP_TEXT, brief=SHORT_HELP_TEXT) - async def joeltech(self, ctx: Context, *, message: clean_content): - await ctx.send("<:joel_tech:1217584610029076480>") - - -async def setup(bot: Bot): - await bot.add_cog(JoelTech(bot)) diff --git a/cogs/commands/misc.py b/cogs/commands/misc.py index 7c04587..9b8c9b5 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 +from discord.ext.commands import Bot, Context, clean_content class Misc(commands.Cog): @@ -143,6 +143,17 @@ 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() + async def translate( + self, ctx: Context, source: str, target: str, message: clean_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)) From cfdc4fe33a05e5d0c736b26acb8a1a9b45cf71bb Mon Sep 17 00:00:00 2001 From: Ali Aljishi Date: Mon, 1 Apr 2024 16:37:43 +0100 Subject: [PATCH 2/2] 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))