-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeletetag.js
79 lines (57 loc) · 2.32 KB
/
deletetag.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const { MessageEmbed } = require('discord.js');
const db = require(`quick.db`);
const moment = require("moment");
const { stripIndents } = require('common-tags');
const yes = ["yes", "y", "ye", "yeah", "yup", "yea", "ya"];
const no = ["no", "n", "nah", "nope", "nop"];
exports.run = async (client, message, args, color) => {
try {
if (message.author.bot) return message.channel.send(`**Bots cannot use the Tags System!**`)
let name = args[0];
if (!name) return message.channel.send("You must specify the name of the Tag to delete.")
let tags = await db.fetch(`tags_${message.guild.id}-${name}`);
let createdbyid = tags.createdbyid;
if (message.author.id !== createdbyid) return message.channel.send(`**Cannot Delete this Tag!** ❌\n\n*You do not own this Tag!*`)
let confirmembed = new MessageEmbed()
.setTitle(`**Delete Tag?**`)
.setDescription(stripIndents`
**Are you sure you want to Delete this Tag?**
**\`${name}\`**
*Type **\`yes\`** ✅ to **confirm** this or **\`no\`** to Decline ❌*
***Typing \`yes\` will result in the Tag Data to disappear.***
`)
.setColor(`#f67b63`)
message.channel.send(confirmembed);
const hit = await verifyText(message.channel, message.author);
if (hit) {
db.delete(`tags_${message.guild.id}-${name}`);
message.channel.send(`Successfully Deleted Tag **» ${name}** ✅`);
} else {
message.channel.send(`**Cancelled Tag Deletion...** *I understand the reasons!*`);
}
} catch (e){
if (e.message === "Cannot read property 'content' of null")
return message.channel.send(`**Tag Not Found** 🔎\n\n*Names are Case Sensitive. Make sure its spelt correctly!*`);
};
async function verifyText(channel, user, time = 30000) {
const filter = res => {
const value = res.content.toLowerCase();
return (
res.author.id === user.id && (yes.includes(value) || no.includes(value))
);
};
const verify = await channel.awaitMessages(filter, {
max: 1,
time
});
if (!verify.size) return 0;
const choice = verify.first().content.toLowerCase();
if (yes.includes(choice)) return true;
if (no.includes(choice)) return false;
return false;
}
}
module.exports.help = {
name: "deletetag",
aliases: ["delete"]
}