split handling
This commit is contained in:
parent
09e264a3fa
commit
b759f96dde
1 changed files with 66 additions and 46 deletions
|
@ -3,7 +3,6 @@ import {
|
||||||
ChatInputCommandInteraction,
|
ChatInputCommandInteraction,
|
||||||
EmbedBuilder,
|
EmbedBuilder,
|
||||||
SlashCommandBuilder,
|
SlashCommandBuilder,
|
||||||
SlashCommandSubcommandBuilder,
|
|
||||||
TextChannel,
|
TextChannel,
|
||||||
} from "npm:discord.js";
|
} from "npm:discord.js";
|
||||||
|
|
||||||
|
@ -101,51 +100,7 @@ export async function handle_command(
|
||||||
update_display: Channel,
|
update_display: Channel,
|
||||||
) {
|
) {
|
||||||
log("Received command", interaction.commandName);
|
log("Received command", interaction.commandName);
|
||||||
if (interaction.commandName === "devoir") {
|
if (interaction.commandName === "devoir") return await handle_command_devoir(interaction, storage, update_display);
|
||||||
const subcommand = interaction.options.getSubcommand(true);
|
|
||||||
if (subcommand === "ajouter") {
|
|
||||||
const subject = interaction.options.getString("matière", true);
|
|
||||||
const days = interaction.options.getNumber("jours", true);
|
|
||||||
const description = interaction.options.getString("description", true);
|
|
||||||
const date = Date.now() + days_to_ms(days);
|
|
||||||
const { id } = await storage.devoirs.add({ date, description, subject });
|
|
||||||
const embed = new EmbedBuilder()
|
|
||||||
.setTitle("`🌟` Ajouté")
|
|
||||||
.setDescription(`Nouveau devoir ajouté avec succès.`)
|
|
||||||
.setFooter({ text: `(devoir id:${id})` });
|
|
||||||
await interaction.reply({ embeds: [embed], ephemeral: true });
|
|
||||||
update_display.send();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (subcommand === "retirer") {
|
|
||||||
const id = interaction.options.getString("devoir", true);
|
|
||||||
await storage.devoirs.delete({ id });
|
|
||||||
const embed = new EmbedBuilder()
|
|
||||||
.setTitle("`🗑️` Retiré")
|
|
||||||
.setDescription(`Devoir supprimé avec succès.`)
|
|
||||||
.setFooter({ text: `(devoir id:${id})` });
|
|
||||||
await interaction.reply({ embeds: [embed], ephemeral: true });
|
|
||||||
update_display.send();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (subcommand === "éditer") {
|
|
||||||
const id = interaction.options.getString("devoir", true);
|
|
||||||
const subject = interaction.options.getString("matière", false);
|
|
||||||
if (subject !== null) storage.devoirs.update({ id }, (d) => d.subject = subject);
|
|
||||||
const description = interaction.options.getString("description", false);
|
|
||||||
if (description !== null) storage.devoirs.update({ id }, (d) => d.description = description);
|
|
||||||
const days = interaction.options.getNumber("jours", false);
|
|
||||||
if (days !== null) storage.devoirs.update({ id }, (d) => d.date = Date.now() + days_to_ms(days));
|
|
||||||
const embed = new EmbedBuilder()
|
|
||||||
.setTitle("`🔧` Édité")
|
|
||||||
.setDescription(`Devoir mis à jour avec succès.`)
|
|
||||||
.setFooter({ text: `(devoir id:${id})` });
|
|
||||||
await interaction.reply({ embeds: [embed], ephemeral: true });
|
|
||||||
update_display.send();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
return log("Unknown devoir sub command", subcommand);
|
|
||||||
}
|
|
||||||
if (interaction.commandName === "adm") {
|
if (interaction.commandName === "adm") {
|
||||||
const subcommand = interaction.options.getSubcommand(true);
|
const subcommand = interaction.options.getSubcommand(true);
|
||||||
if (subcommand === "ajouter-feed") {
|
if (subcommand === "ajouter-feed") {
|
||||||
|
@ -168,6 +123,71 @@ export async function handle_command(
|
||||||
log("Unknown command", interaction.commandName);
|
log("Unknown command", interaction.commandName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function handle_command_devoir(
|
||||||
|
interaction: ChatInputCommandInteraction,
|
||||||
|
storage: Storage,
|
||||||
|
update_display: Channel,
|
||||||
|
) {
|
||||||
|
const subcommand = interaction.options.getSubcommand(true);
|
||||||
|
if (subcommand === "ajouter") return await handle_command_devoir_ajouter(interaction, storage, update_display);
|
||||||
|
if (subcommand === "retirer") return await handle_command_devoir_retirer(interaction, storage, update_display);
|
||||||
|
if (subcommand === "éditer") return await handle_command_devoir_editer(interaction, storage, update_display);
|
||||||
|
return log("Unknown devoir sub command", subcommand);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handle_command_devoir_editer(
|
||||||
|
interaction: ChatInputCommandInteraction,
|
||||||
|
storage: Storage,
|
||||||
|
update_display: Channel,
|
||||||
|
) {
|
||||||
|
const id = interaction.options.getString("devoir", true);
|
||||||
|
const subject = interaction.options.getString("matière", false);
|
||||||
|
if (subject !== null) storage.devoirs.update({ id }, (d) => d.subject = subject);
|
||||||
|
const description = interaction.options.getString("description", false);
|
||||||
|
if (description !== null) storage.devoirs.update({ id }, (d) => d.description = description);
|
||||||
|
const days = interaction.options.getNumber("jours", false);
|
||||||
|
if (days !== null) storage.devoirs.update({ id }, (d) => d.date = Date.now() + days_to_ms(days));
|
||||||
|
const embed = new EmbedBuilder()
|
||||||
|
.setTitle("`🔧` Édité")
|
||||||
|
.setDescription(`Devoir mis à jour avec succès.`)
|
||||||
|
.setFooter({ text: `(devoir id:${id})` });
|
||||||
|
await interaction.reply({ embeds: [embed], ephemeral: true });
|
||||||
|
update_display.send();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handle_command_devoir_retirer(
|
||||||
|
interaction: ChatInputCommandInteraction,
|
||||||
|
storage: Storage,
|
||||||
|
update_display: Channel,
|
||||||
|
) {
|
||||||
|
const id = interaction.options.getString("devoir", true);
|
||||||
|
await storage.devoirs.delete({ id });
|
||||||
|
const embed = new EmbedBuilder()
|
||||||
|
.setTitle("`🗑️` Retiré")
|
||||||
|
.setDescription(`Devoir supprimé avec succès.`)
|
||||||
|
.setFooter({ text: `(devoir id:${id})` });
|
||||||
|
await interaction.reply({ embeds: [embed], ephemeral: true });
|
||||||
|
update_display.send();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handle_command_devoir_ajouter(
|
||||||
|
interaction: ChatInputCommandInteraction,
|
||||||
|
storage: Storage,
|
||||||
|
update_display: Channel,
|
||||||
|
) {
|
||||||
|
const subject = interaction.options.getString("matière", true);
|
||||||
|
const days = interaction.options.getNumber("jours", true);
|
||||||
|
const description = interaction.options.getString("description", true);
|
||||||
|
const date = Date.now() + days_to_ms(days);
|
||||||
|
const { id } = await storage.devoirs.add({ date, description, subject });
|
||||||
|
const embed = new EmbedBuilder()
|
||||||
|
.setTitle("`🌟` Ajouté")
|
||||||
|
.setDescription(`Nouveau devoir ajouté avec succès.`)
|
||||||
|
.setFooter({ text: `(devoir id:${id})` });
|
||||||
|
await interaction.reply({ embeds: [embed], ephemeral: true });
|
||||||
|
update_display.send();
|
||||||
|
}
|
||||||
|
|
||||||
// autocompletion
|
// autocompletion
|
||||||
|
|
||||||
export async function handle_autocomplete(interaction: AutocompleteInteraction, storage: Storage) {
|
export async function handle_autocomplete(interaction: AutocompleteInteraction, storage: Storage) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue