Translate slash command

This commit is contained in:
Stijn De Clercq 2021-09-03 18:53:05 +02:00
parent 358f8693dd
commit ef547a7090
10 changed files with 96 additions and 16 deletions

View file

@ -163,8 +163,8 @@ class Birthdays(commands.Cog):
# Create a datetime object for this birthday
timeString = "{}/{}/{}".format(
stringFormatters.leadingZero(str(day)),
stringFormatters.leadingZero(str(month)),
stringFormatters.leading_zero(str(day)),
stringFormatters.leading_zero(str(month)),
year
)

View file

@ -37,7 +37,7 @@ class Faq(commands.Cog):
return await self.faqCategory(ctx, (constants.faq_channels[ctx.channel.id],))
# List of all categories with the first letter capitalized
resp = [stringFormatters.titleCase(cat[0]) for cat in faq.getCategories()]
resp = [stringFormatters.title_case(cat[0]) for cat in faq.getCategories()]
# Sort alphabetically
resp.sort()
@ -146,7 +146,7 @@ class Faq(commands.Cog):
resp.sort(key=lambda x: int(x[0]))
embed = discord.Embed(colour=discord.Colour.blue())
embed.set_author(name="FAQ {}".format(stringFormatters.titleCase(category)))
embed.set_author(name="FAQ {}".format(stringFormatters.title_case(category)))
# Add everything into the embed
for i, pair in enumerate(resp):

View file

@ -120,7 +120,7 @@ class Fun(commands.Cog):
memeList = memes.getAllMemes()
# Turn the list into a list of [Name: fields]
memeList = [": ".join([stringFormatters.titleCase(meme[1]),
memeList = [": ".join([stringFormatters.title_case(meme[1]),
str(meme[2])]) for meme in sorted(memeList, key=lambda x: x[1])]
pages = paginatedLeaderboard.Pages(source=paginatedLeaderboard.Source(memeList, "Memes", discord.Colour.blue()),

View file

@ -0,0 +1,26 @@
from discord.ext import commands
from dislash import SlashInteraction, slash_command, Option, OptionType
from data.embeds.translate import Translation
from startup.didier import Didier
class TranslateSlash(commands.Cog):
def __init__(self, client: Didier):
self.client: Didier = client
@slash_command(
name="translate",
description="Google Translate",
options=[
Option("text", "Tekst om te vertalen", OptionType.STRING, required=True),
Option("to", "Taal om naar te vertalen (default NL)", OptionType.STRING)
]
)
async def _translate_slash(self, interaction: SlashInteraction, text: str, to: str = "nl"):
translation = Translation(text=text, to=to.lower())
await interaction.reply(embed=translation.to_embed())
def setup(client: Didier):
client.add_cog(TranslateSlash(client))

View file

@ -2,7 +2,7 @@ from decorators import help
import discord
from discord.ext import commands
from enums.help_categories import Category
from functions.stringFormatters import titleCase as tc
from functions.stringFormatters import title_case as tc
from googletrans import Translator, LANGUAGES
import re