2021-09-03 20:40:03 +02:00
|
|
|
import traceback
|
|
|
|
|
|
|
|
from discord.ext.commands import Context
|
|
|
|
from dislash import SlashInteraction
|
|
|
|
|
|
|
|
|
2021-09-03 18:53:05 +02:00
|
|
|
def title_case(string):
|
2020-10-13 21:02:40 +02:00
|
|
|
return " ".join(capitalize(word) for word in string.split(" "))
|
|
|
|
|
|
|
|
|
|
|
|
def capitalize(string):
|
|
|
|
if len(string) > 1:
|
|
|
|
return string[0].upper() + string[1:].lower()
|
|
|
|
return string[0].upper()
|
|
|
|
|
|
|
|
|
2021-09-03 18:53:05 +02:00
|
|
|
def leading_zero(string, size=2):
|
2020-10-13 21:02:40 +02:00
|
|
|
string = str(string)
|
|
|
|
while len(string) < size:
|
|
|
|
string = "0" + string
|
|
|
|
return string
|
2021-09-03 20:40:03 +02:00
|
|
|
|
|
|
|
|
|
|
|
def format_error_tb(err: Exception) -> str:
|
|
|
|
# Remove the InvokeCommandError because it's useless information
|
|
|
|
x = traceback.format_exception(type(err), err, err.__traceback__)
|
|
|
|
error_string = ""
|
|
|
|
for line in x:
|
|
|
|
if "direct cause of the following" in line:
|
|
|
|
break
|
|
|
|
error_string += line.replace("*", "") + "\n" if line.strip() != "" else ""
|
|
|
|
|
|
|
|
return error_string
|
|
|
|
|
|
|
|
|
|
|
|
def _format_error_location(src) -> str:
|
|
|
|
DM = src.guild is None
|
|
|
|
return "DM" if DM else f"{src.channel.name} ({src.guild.name})"
|
|
|
|
|
|
|
|
|
|
|
|
def format_command_usage(ctx: Context) -> str:
|
|
|
|
return f"{ctx.author.display_name} in {_format_error_location(ctx)}: {ctx.message.content}"
|
|
|
|
|
|
|
|
|
|
|
|
def format_slash_command_usage(interaction: SlashInteraction) -> str:
|
|
|
|
# Create a string with the options used
|
2021-11-29 21:37:04 +01:00
|
|
|
# TODO look into the format used by the lib because it's terrible
|
2021-09-03 20:40:03 +02:00
|
|
|
options = " ".join(list(map(
|
|
|
|
lambda option: f"{option.name}: \"{option.value}\"",
|
|
|
|
interaction.data.options.values()
|
|
|
|
)))
|
|
|
|
|
|
|
|
command = f"{interaction.slash_command.name} {options or ''}"
|
|
|
|
return f"{interaction.author.display_name} in {_format_error_location(interaction)}: /{command}"
|
2021-11-29 21:37:04 +01:00
|
|
|
|
|
|
|
|
|
|
|
def get_edu_year(index: int) -> str:
|
|
|
|
return ["1ste Bachelor", "2de Bachelor", "3de Bachelor", "1ste Master", "2de Master"][index - 1]
|