2021-09-03 20:40:03 +02:00
|
|
|
import traceback
|
|
|
|
|
2022-02-05 21:24:08 +01:00
|
|
|
from discord import Interaction
|
2021-09-03 20:40:03 +02:00
|
|
|
from discord.ext.commands import Context
|
|
|
|
|
|
|
|
|
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}"
|
|
|
|
|
|
|
|
|
2022-02-05 21:24:08 +01:00
|
|
|
def format_slash_command_usage(interaction: Interaction) -> str:
|
2021-09-03 20:40:03 +02:00
|
|
|
# Create a string with the options used
|
|
|
|
options = " ".join(list(map(
|
2022-03-11 14:11:59 +01:00
|
|
|
lambda o: f"{o['name']}: \"{o['value']}\"" if "value" in o else o["name"],
|
2022-02-05 21:24:08 +01:00
|
|
|
interaction.data.get("options", [])
|
2021-09-03 20:40:03 +02:00
|
|
|
)))
|
|
|
|
|
2022-02-05 21:24:08 +01:00
|
|
|
command = f"{interaction.data['name']} {options or ''}"
|
|
|
|
return f"{interaction.user.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]
|