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

[Commands] Added GDPR Export and GDPR Policy commands

parent 62a6a987
Branches
Tags
No related merge requests found
......@@ -99,6 +99,14 @@ class SebAPI {
return await this.__request("GET", "/api/people");
}
async person_export(id) {
return await this.__request("GET", `/api/people/${id}/export`);
}
async person_bydiscordid(discord_id) {
return await this.__request("GET", `/api/people?filter[discord_id]=${discord_id}`);
}
async members() {
return await this.__request("GET", "/api/members");
}
......
/**
* 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 { MessageAttachment } from 'discord.js';
import { Readable } from 'stream';
import SebAPI from '../api/SebApi.js';
import Command from '../Command.js';
import SoftConfig from '../config/SoftConfig.js';
class GDPRCommand extends Command {
constructor() {
super();
this.sub = {
"export": this.exec_export,
"policy": this.exec_policy
}
}
getName() {
return "gdpr";
}
getOptions() {
return [{
type: ApplicationCommandOptionType.Subcommand,
name: "export",
description: "Exporter vos données au format JSON"
}, {
type: ApplicationCommandOptionType.Subcommand,
name: "policy",
description: "Lire la politique de confidentialité de Seb"
}];
}
getDescription() {
return "Gestion des données personelles, vie privée, ...";
}
async exec_policy(interaction) {
const file = new MessageAttachment(SoftConfig.get("seb.url") + "doc/privacy-policy.pdf");
await interaction.reply({ files: [file], ephemeral: true });
}
async exec_export(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." });
}
if (d?.data?.data?.length <= 0) {
await interaction.editReply({ content: "Vous n'êtes pas enregistré dans Seb." });
}
d = await SebAPI.person_export(d?.data?.data[0]?.id);
if (!d.good) {
await interaction.editReply({ content: "Une erreur s'est produite." });
}
d = JSON.stringify(d?.data);
const stream = new Readable();
stream.push(d);
stream.push(null);
const file = new MessageAttachment(stream, "export.json");
await interaction.editReply({ content: "Voici vos données, exportés au format JSON:", files: [file] });
}
async execute(interaction) {
await this.sub[interaction.options.getSubcommand()](interaction);
}
}
export default GDPRCommand;
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