Skip to content
Snippets Groups Projects
Unverified Commit 3b811251 authored by Maxime FRIESS's avatar Maxime FRIESS :blue_heart:
Browse files

[Commands] Added whoami and update

parent c03b2593
Branches
Tags
No related merge requests found
......@@ -91,6 +91,10 @@ class SebAPI {
return await this.__request("POST", "/api/people", { firstname: firstname, lastname: lastname, discord_id: discord_id });
}
async update_person(id, firstname, lastname) {
return await this.__request("PUT", `/api/people/${id}`, { firstname: firstname, lastname: lastname });
}
async stats() {
return await this.__request("GET", "/api/stats");
}
......
......@@ -97,7 +97,6 @@ class MenuCommand extends Command {
async buttonPrevious(interaction) {
let date = this.__getDateInMsg(interaction, -1);
console.log(date);
let filter = this.__getFilterInMsg(interaction);
await interaction.deferUpdate();
......
......@@ -47,12 +47,12 @@ class RegisterCommand extends Command {
return [{
type: ApplicationCommandOptionType.String,
name: "prénom",
description: "Votre prénom",
description: "Prénom",
required: true
}, {
type: ApplicationCommandOptionType.String,
name: "nom",
description: "Votre nom",
description: "Nom",
required: true
}];
}
......@@ -63,6 +63,8 @@ class RegisterCommand extends Command {
return;
}
delete this.__pending_accept[interaction.user.id];
await interaction.deferUpdate();
const { firstname, lastname } = this.__pending_accept[interaction.user.id];
......@@ -77,7 +79,7 @@ class RegisterCommand extends Command {
} else if (status == 422) {
interaction.editReply({ content: "Ce compte discord est déjà enregistré dans Seb. Merci de contacter l'amicale en cas de problème.", components: [] });
} else {
interraction.editReply({ content: "Erreur de connexion à Seb.", components: [] });
interaction.editReply({ content: "Erreur de connexion à Seb.", components: [] });
}
}
......
/**
* Copyright © 2021 Maxime Friess <M4x1me@pm.me>
*
* This file is part of Seb-BOT.
*
* Seb-BOT is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Seb-BOT is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Seb-BOT. If not, see <https://www.gnu.org/licenses/>.
*/
import { ApplicationCommandOptionType } from 'discord-api-types/v9';
import SebAPI from '../api/SebApi.js';
import Command from '../Command.js';
class UpdateCommand extends Command {
constructor() {
super();
}
getOptions() {
return [{
type: ApplicationCommandOptionType.String,
name: "prénom",
description: "Prénom",
required: true
}, {
type: ApplicationCommandOptionType.String,
name: "nom",
description: "Nom",
required: true
}];
}
getName() {
return "update";
}
getDescription() {
return "Mets à jour les informations du profil.";
}
async execute(interaction) {
await interaction.deferReply({ ephemeral: true });
let d = await SebAPI.person_bydiscordid(interaction.user.id);
if (!d.good) {
await interaction.editReply({ content: "Une erreur s'est produite." });
return;
}
if (d?.data?.data?.length <= 0) {
await interaction.editReply({ content: "Vous n'êtes pas enregistré dans Seb." });
return;
}
let firstname = interaction.options.getString('prénom');
firstname = firstname.charAt(0).toUpperCase() + firstname.slice(1).toLowerCase();
let lastname = interaction.options.getString('nom').toUpperCase();
let {good, error, status, data} = await SebAPI.update_person(d.data.data[0].id, firstname, lastname);
if (good) {
interaction.editReply({ content: "Données mises à jour!", components: [] });
} else {
interaction.editReply({ content: "Erreur de connexion à Seb.", components: [] });
}
}
}
export default UpdateCommand;
/**
* Copyright © 2021 Maxime Friess <M4x1me@pm.me>
*
* This file is part of Seb-BOT.
*
* Seb-BOT is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Seb-BOT is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Seb-BOT. If not, see <https://www.gnu.org/licenses/>.
*/
import SebAPI from '../api/SebApi.js';
import Command from '../Command.js';
class WhoamiCommand extends Command {
constructor() {
super();
}
getName() {
return "whoami";
}
getDescription() {
return "Récupère les informations du profil.";
}
async execute(interaction) {
await interaction.deferReply({ ephemeral: true });
let d = await SebAPI.person_bydiscordid(interaction.user.id);
if (!d.good) {
await interaction.editReply({ content: "Une erreur s'est produite." });
return;
}
if (d?.data?.data?.length <= 0) {
await interaction.editReply({ content: "Vous n'êtes pas enregistré dans Seb." });
return;
}
d = d.data.data[0];
interaction.editReply({ content: `Vous êtes enregistré dans Seb.\n#${d.id} - ${d.fullname}` });
}
}
export default WhoamiCommand;
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment