Translate to english

pull/125/head
stijndcl 2022-07-24 17:09:42 +02:00
parent edc6343e12
commit 424399b88a
9 changed files with 52 additions and 32 deletions

View File

@ -23,6 +23,8 @@ extend-ignore =
D401, D401,
# Whitespace before ":" # Whitespace before ":"
E203, E203,
# Standard pseudo-random generators are not suitable for security/cryptographic purposes.
S311,
# Don't require docstrings when overriding a method, # Don't require docstrings when overriding a method,
# the base method should have a docstring but the rest not # the base method should have a docstring but the rest not
ignore-decorators=overrides ignore-decorators=overrides

View File

@ -15,7 +15,7 @@ class Other(commands.Cog):
def __init__(self, client: Didier): def __init__(self, client: Didier):
self.client = client self.client = client
@commands.hybrid_command(name="define", description="Urban Dictionary", aliases=["Ud", "Urban"], usage="[Woord]") @commands.hybrid_command(name="define", description="Urban Dictionary", aliases=["Ud", "Urban"], usage="[Term]")
async def define(self, ctx: commands.Context, *, query: str): async def define(self, ctx: commands.Context, *, query: str):
"""Look up the definition of a word on the Urban Dictionary""" """Look up the definition of a word on the Urban Dictionary"""
async with ctx.typing(): async with ctx.typing():

View File

@ -75,7 +75,7 @@ class Owner(commands.Cog):
await custom_commands.create_command(session, name, response) await custom_commands.create_command(session, name, response)
await self.client.confirm_message(ctx.message) await self.client.confirm_message(ctx.message)
except DuplicateInsertException: except DuplicateInsertException:
await ctx.reply("Er bestaat al een commando met deze naam.") await ctx.reply("There is already a command with this name.")
await self.client.reject_message(ctx.message) await self.client.reject_message(ctx.message)
@add_msg.command(name="Alias") @add_msg.command(name="Alias")
@ -86,19 +86,17 @@ class Owner(commands.Cog):
await custom_commands.create_alias(session, command, alias) await custom_commands.create_alias(session, command, alias)
await self.client.confirm_message(ctx.message) await self.client.confirm_message(ctx.message)
except NoResultFoundException: except NoResultFoundException:
await ctx.reply(f'Geen commando gevonden voor "{command}".') await ctx.reply(f"No command found matching `{command}`.")
await self.client.reject_message(ctx.message) await self.client.reject_message(ctx.message)
except DuplicateInsertException: except DuplicateInsertException:
await ctx.reply("Er bestaat al een commando met deze naam.") await ctx.reply("There is already a command with this name.")
await self.client.reject_message(ctx.message) await self.client.reject_message(ctx.message)
@add_slash.command(name="custom", description="Add a custom command") @add_slash.command(name="custom", description="Add a custom command")
async def add_custom_slash(self, interaction: discord.Interaction): async def add_custom_slash(self, interaction: discord.Interaction):
"""Slash command to add a custom command""" """Slash command to add a custom command"""
if not await self.client.is_owner(interaction.user): if not await self.client.is_owner(interaction.user):
return interaction.response.send_message( return interaction.response.send_message("You don't have permission to run this command.", ephemeral=True)
"Je hebt geen toestemming om dit commando uit te voeren.", ephemeral=True
)
modal = CreateCustomCommand(self.client) modal = CreateCustomCommand(self.client)
await interaction.response.send_modal(modal) await interaction.response.send_modal(modal)
@ -107,9 +105,7 @@ class Owner(commands.Cog):
async def add_dad_joke_slash(self, interaction: discord.Interaction): async def add_dad_joke_slash(self, interaction: discord.Interaction):
"""Slash command to add a dad joke""" """Slash command to add a dad joke"""
if not await self.client.is_owner(interaction.user): if not await self.client.is_owner(interaction.user):
return interaction.response.send_message( return interaction.response.send_message("You don't have permission to run this command.", ephemeral=True)
"Je hebt geen toestemming om dit commando uit te voeren.", ephemeral=True
)
modal = AddDadJoke(self.client) modal = AddDadJoke(self.client)
await interaction.response.send_modal(modal) await interaction.response.send_modal(modal)
@ -126,7 +122,7 @@ class Owner(commands.Cog):
await custom_commands.edit_command(session, command, flags.name, flags.response) await custom_commands.edit_command(session, command, flags.name, flags.response)
return await self.client.confirm_message(ctx.message) return await self.client.confirm_message(ctx.message)
except NoResultFoundException: except NoResultFoundException:
await ctx.reply(f"Geen commando gevonden voor ``{command}``.") await ctx.reply(f"No command found matching ``{command}``.")
return await self.client.reject_message(ctx.message) return await self.client.reject_message(ctx.message)
@edit_slash.command(name="custom", description="Edit a custom command") @edit_slash.command(name="custom", description="Edit a custom command")

View File

@ -6,7 +6,7 @@ from discord.ext import commands
from database.crud import ufora_courses from database.crud import ufora_courses
from didier import Didier from didier import Didier
from didier.data import constants from didier.utils.discord.flags.school import StudyGuideFlags
class School(commands.Cog): class School(commands.Cog):
@ -36,43 +36,46 @@ class School(commands.Cog):
# Didn't fix it, sad # Didn't fix it, sad
if message is None: if message is None:
return await ctx.reply("Er is geen bericht om te pinnen.", delete_after=10) return await ctx.reply("Found no message to pin.", delete_after=10)
if message.pinned:
return await ctx.reply("This message is already pinned.", delete_after=10)
if message.is_system(): if message.is_system():
return await ctx.reply("Dus jij wil system messages pinnen?\nMag niet.") return await ctx.reply("Dus jij wil system messages pinnen?\nMag niet.")
await message.pin(reason=f"Didier Pin door {ctx.author.display_name}") await message.pin(reason=f"Didier Pin by {ctx.author.display_name}")
await message.add_reaction("📌") await message.add_reaction("📌")
async def pin_ctx(self, interaction: discord.Interaction, message: discord.Message): async def pin_ctx(self, interaction: discord.Interaction, message: discord.Message):
"""Pin a message in the current channel""" """Pin a message in the current channel"""
# Is already pinned # Is already pinned
if message.pinned: if message.pinned:
return await interaction.response.send_message("Dit bericht staat al gepind.", ephemeral=True) return await interaction.response.send_message("This message is already pinned.", ephemeral=True)
if message.is_system(): if message.is_system():
return await interaction.response.send_message( return await interaction.response.send_message(
"Dus jij wil system messages pinnen?\nMag niet.", ephemeral=True "Dus jij wil system messages pinnen?\nMag niet.", ephemeral=True
) )
await message.pin(reason=f"Didier Pin door {interaction.user.display_name}") await message.pin(reason=f"Didier Pin by {interaction.user.display_name}")
await message.add_reaction("📌") await message.add_reaction("📌")
return await interaction.response.send_message("📌", ephemeral=True) return await interaction.response.send_message("📌", ephemeral=True)
@commands.hybrid_command( @commands.hybrid_command(
name="fiche", description="Stuurt de link naar de studiefiche voor [Vak]", aliases=["guide", "studiefiche"] name="fiche", description="Sends the link to the study guide for [Course]", aliases=["guide", "studiefiche"]
) )
@app_commands.describe(course="vak") @app_commands.describe(course="vak")
async def study_guide(self, ctx: commands.Context, course: str): async def study_guide(self, ctx: commands.Context, course: str, *, flags: StudyGuideFlags):
"""Create links to study guides""" """Create links to study guides"""
async with self.client.db_session as session: async with self.client.db_session as session:
ufora_course = await ufora_courses.get_course_by_name(session, course) ufora_course = await ufora_courses.get_course_by_name(session, course)
if ufora_course is None: if ufora_course is None:
return await ctx.reply(f"Geen vak gevonden voor ``{course}``", ephemeral=True) return await ctx.reply(f"Found no course matching ``{course}``", ephemeral=True)
return await ctx.reply( return await ctx.reply(
f"https://studiekiezer.ugent.be/studiefiche/nl/{ufora_course.code}/{constants.CURRENT_YEAR}", f"https://studiekiezer.ugent.be/studiefiche/nl/{ufora_course.code}/{flags.year}",
mention_author=False, mention_author=False,
) )

View File

@ -1,4 +1,5 @@
import datetime import datetime
import random
import traceback import traceback
from discord.ext import commands, tasks # type: ignore # Strange & incorrect Mypy error from discord.ext import commands, tasks # type: ignore # Strange & incorrect Mypy error
@ -18,6 +19,10 @@ DAILY_RESET_TIME = datetime.time(hour=0, minute=0, tzinfo=LOCAL_TIMEZONE)
SOCIALLY_ACCEPTABLE_TIME = datetime.time(hour=7, minute=0, tzinfo=LOCAL_TIMEZONE) SOCIALLY_ACCEPTABLE_TIME = datetime.time(hour=7, minute=0, tzinfo=LOCAL_TIMEZONE)
# TODO more messages?
BIRTHDAY_MESSAGES = ["Gelukkige verjaardag {mention}!", "Happy birthday {mention}!"]
class Tasks(commands.Cog): class Tasks(commands.Cog):
"""Task loops that run periodically """Task loops that run periodically
@ -52,12 +57,12 @@ class Tasks(commands.Cog):
""" """
raise NotImplementedError() raise NotImplementedError()
@tasks_group.command(name="Force", case_insensitive=True) @tasks_group.command(name="Force", case_insensitive=True, usage="[Task]")
async def force_task(self, ctx: commands.Context, name: str): async def force_task(self, ctx: commands.Context, name: str):
"""Command to force-run a task without waiting for the run time""" """Command to force-run a task without waiting for the specified run time"""
name = name.lower() name = name.lower()
if name not in self._tasks: if name not in self._tasks:
return await ctx.reply(f"Geen task gevonden voor `{name}`.", mention_author=False) return await ctx.reply(f"Found no tasks matching `{name}`.", mention_author=False)
task = self._tasks[name] task = self._tasks[name]
await task() await task()
@ -76,8 +81,8 @@ class Tasks(commands.Cog):
for birthday in birthdays: for birthday in birthdays:
user = self.client.get_user(birthday.user_id) user = self.client.get_user(birthday.user_id)
# TODO more messages?
await channel.send(f"Gelukkig verjaardag {user.mention}!") await channel.send(random.choice(BIRTHDAY_MESSAGES).format(mention=user.mention))
@check_birthdays.before_loop @check_birthdays.before_loop
async def _before_check_birthdays(self): async def _before_check_birthdays(self):
@ -114,6 +119,7 @@ class Tasks(commands.Cog):
async def _on_tasks_error(self, error: BaseException): async def _on_tasks_error(self, error: BaseException):
"""Error handler for all tasks""" """Error handler for all tasks"""
print("".join(traceback.format_exception(type(error), error, error.__traceback__))) print("".join(traceback.format_exception(type(error), error, error.__traceback__)))
self.client.dispatch("task_error")
async def setup(client: Didier): async def setup(client: Didier):

View File

@ -24,11 +24,11 @@ class GoogleSearch(EmbedBaseModel):
# Empty embed # Empty embed
if not self.data.results: if not self.data.results:
embed.description = "Geen resultaten gevonden" embed.description = "Found no results"
return embed return embed
# Error embed # Error embed
embed.description = f"Status {self.data.status_code}" embed.description = f"Something went wrong (status {self.data.status_code})"
return embed return embed

View File

@ -50,10 +50,10 @@ class Definition(EmbedPydantic):
embed = discord.Embed(colour=colours.urban_dictionary_green()) embed = discord.Embed(colour=colours.urban_dictionary_green())
embed.set_author(name="Urban Dictionary") embed.set_author(name="Urban Dictionary")
embed.add_field(name="Woord", value=self.word, inline=True) embed.add_field(name="Term", value=self.word, inline=True)
embed.add_field(name="Auteur", value=self.author, inline=True) embed.add_field(name="Author", value=self.author, inline=True)
embed.add_field(name="Definitie", value=self.definition, inline=False) embed.add_field(name="Definition", value=self.definition, inline=False)
embed.add_field(name="Voorbeeld", value=self.example or "\u200B", inline=False) embed.add_field(name="Example", value=self.example or "\u200B", inline=False)
embed.add_field( embed.add_field(
name="Rating", value=f"{self.ratio}% ({self.thumbs_up}/{self.thumbs_up + self.thumbs_down})", inline=True name="Rating", value=f"{self.ratio}% ({self.thumbs_up}/{self.thumbs_up + self.thumbs_down})", inline=True
) )

View File

@ -0,0 +1,12 @@
from typing import Optional
from didier.data import constants
from didier.utils.discord.flags import PosixFlags
__all__ = ["StudyGuideFlags"]
class StudyGuideFlags(PosixFlags):
"""Flags for the study guide command"""
year: Optional[int] = constants.CURRENT_YEAR

View File

@ -18,7 +18,8 @@ omit = [
"./didier/data/embeds/*", "./didier/data/embeds/*",
"./didier/data/flags/*", "./didier/data/flags/*",
"./didier/utils/discord/colours.py", "./didier/utils/discord/colours.py",
"./didier/utils/discord/constants.py" "./didier/utils/discord/constants.py",
"./didier/utils/discord/flags/*",
] ]
[tool.isort] [tool.isort]