Skip to content

Commit

Permalink
add delete account command
Browse files Browse the repository at this point in the history
  • Loading branch information
cursorweb committed Sep 29, 2023
1 parent 030a175 commit 37afd9d
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 15 deletions.
90 changes: 90 additions & 0 deletions src/cmd/meta/delete-acc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import * as Discord from "discord.js";
import { ButtonBuilder, ActionRowBuilder, ButtonStyle } from "discord.js";
import { Command, Colors, Database } from "../../global.js";

class C extends Command {
names = ["delete-account"];
help = "Deletes your account data from the database (privacy policy)";
examples = ["delete-account"];

exec(msg: Discord.Message, _: string[], client: Discord.Client) {
msg.channel.send({
embeds: [{
color: Colors.WARNING,
title: "Confirm Account Deletion",
description: "Are you sure you want to delete your account?\n**ALL** your progress and data will be deleted!"
}],
components: [
new ActionRowBuilder<ButtonBuilder>()
.addComponents([
new ButtonBuilder()
.setCustomId("next")
.setEmoji("✔️")
.setStyle(ButtonStyle.Success),
new ButtonBuilder()
.setCustomId("cancel")
.setEmoji("✖️")
.setStyle(ButtonStyle.Danger)
])
]
}).then(async mesg => {
const collector = mesg.createMessageComponentCollector({
filter: (inter) => inter.user.id == msg.author.id,
max: 1,
time: 60000
});

collector.on("collect", async choice => {
if (choice.customId == "cancel") {
collector.stop();
await mesg.edit({
embeds: [{
color: Colors.PRIMARY,
title: "Cancelled",
description: "Happy coding!"
}]
});
return;
}

const user = Database.pdb[msg.author.id];
const channel = await client.channels.fetch("899518500576579615") as Discord.TextChannel;
channel.send({
embeds: [{
color: Colors.PRIMARY,
title: "Deleted Account",
description: `User: \`${user.name}\`
ID: \`${msg.author.id}\``
}]
});

delete Database.pdb[msg.author.id];
msg.channel.send({
embeds: [{
color: Colors.PRIMARY,
title: "Deleted account",
description: "Goodbye! Come back soon!"
}]
});
});

collector.on("end", collected => {
if (collected.size == 0) {
mesg.edit({
embeds: [{
color: Colors.WARNING,
title: "Cancelled",
description: "You didn't make a response in time!"
}]
});
}

mesg.edit({
components: []
});
});
});
}
}

export const c = new C();
2 changes: 1 addition & 1 deletion src/cmd/minigame/trivia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ ${username} thanks you!
.catch(() => {
msg.reply({
embeds: [{
title: "Times up!",
title: "Time's up!",
color: Colors.ERROR,
description: `You ran out of time!
Expand Down
27 changes: 18 additions & 9 deletions src/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ export class Command {
names: string[] = [];
help = "*no help provided*";
examples: string[] = [];
/**
* its either:
* 'y' (yes, auto-initiate)
* 'n' (don't initiate)
* 'p' (don't initiate, and error if player does not have profile)
*/
isGame: "y" | "n" | "p" = "p"; // if we should initiate player or not
/* its either:
'y' (yes, auto-initiate)
'n' (don't initiate)
'p' (don't initiate, and error if player does not have profile)
*/

isAdmin = false;

Expand All @@ -38,7 +39,7 @@ export class Command {
return 0;
} // ms

wrap(msg: Discord.Message, args: string[], client: Discord.Client) {
async wrap(msg: Discord.Message, args: string[], client: Discord.Client) {
if (lockedDown) {
if (admin.includes(msg.author.id)) {
if (!this.isAdmin) {
Expand All @@ -56,14 +57,14 @@ export class Command {
}

try {
const isJoined = Boolean(client.guilds.cache.get("788421241005408268")?.members.cache.get(msg.author.id));
const isJoined = await (await client.guilds.fetch("788421241005408268"))?.members.fetch(msg.author.id);

if (this.isGame == "y" && !getUser(msg.author.id)) {
msg.channel.send({
embeds: [{
color: Colors.PRIMARY,
title: "Welcome!",
description: `Welcome to the bot, ${brackets(msg.author.tag)}!
description: `Welcome to the bot, ${brackets(msg.author.username)}!
**Use \`&guide\` to get a simple tutorial!**${!isJoined ? `
Join the [discord server](https://discord.gg/4vTPWdpjFz) for support and perks!` : ""}`
}]
Expand All @@ -74,7 +75,9 @@ Join the [discord server](https://discord.gg/4vTPWdpjFz) for support and perks!`
> Do \`&code\` to start playing!`, "Profile not found!");
}

if (this.isGame != "n" && getUser(msg.author.id).name != msg.author.tag) setUser(msg.author.id, { name: msg.author.tag } as CycleUser);
if (this.isGame != "n" && getUser(msg.author.id).name != msg.author.username) {
setUser(msg.author.id, { name: msg.author.username } as CycleUser);
}

if (Math.random() * 100 < 3 && !isJoined) {
msg.channel.send({
Expand Down Expand Up @@ -121,6 +124,11 @@ Join the [discord server](https://discord.gg/4vTPWdpjFz) for support and perks!`
if (this.cooldownUsers) this.cooldownUsers[user.id][1] = true;
}

/**
* Send a cooldown error, and propagate errors.
* @param msg Discord Message
* @param ms Time left (if cool-downed)
*/
wrapCooldown(msg: Discord.Message, ms: number) {
try {
this.cooldownError(msg, ms);
Expand All @@ -129,6 +137,7 @@ Join the [discord server](https://discord.gg/4vTPWdpjFz) for support and perks!`
}
}

// to be overriden
cooldownError(msg: Discord.Message, ms: number) {
Bot.errormsg(msg, `You still have ${brackets((ms / 1000).toFixed(2))} seconds left!`, "Cooldown!");
}
Expand Down
13 changes: 8 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,18 @@ For example, if you get **one**, type in ${g.codestr("&verify 1")}`,
cmdclss.setSent(msg.author);
}
} else if (cmdclss.isAdmin) {
if (admins.includes(msg.author.id)) cmdclss.wrap(msg, cmd.args, client);
else {
if (admins.includes(msg.author.id)) {
await cmdclss.wrap(msg, cmd.args, client);
} else {
try {
g.Bot.errormsg(msg, "haha you don't have the perms!", "Permissions needed!");
} catch {
// ignore BotErr
}
}
} else cmdclss.wrap(msg, cmd.args, client);
} else {
await cmdclss.wrap(msg, cmd.args, client);
}

if (!commandsUsed[msg.author.id]) {
const numbers = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"];
Expand Down Expand Up @@ -155,8 +158,8 @@ client.on("rateLimit", e => {
}
});

function showError(title: string, text: string) {
const channel = client.channels.cache.get("899518500576579615") as Discord.TextChannel;
async function showError(title: string, text: string) {
const channel = await client.channels.fetch("899518500576579615") as Discord.TextChannel;

if (channel) {
channel.send({
Expand Down

0 comments on commit 37afd9d

Please sign in to comment.