Skip to content

Commit

Permalink
supports translate reply, added help text
Browse files Browse the repository at this point in the history
  • Loading branch information
aaj2005 committed Apr 1, 2024
1 parent e024662 commit cfdc4fe
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions cogs/commands/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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 = "<Empty Message>",
):
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))

0 comments on commit cfdc4fe

Please sign in to comment.