Skip to content

Commit

Permalink
ticket blacklist
Browse files Browse the repository at this point in the history
  • Loading branch information
FnrDev committed May 28, 2022
1 parent 4313e4a commit ff93662
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 7 deletions.
37 changes: 37 additions & 0 deletions commands/ticket/blacklist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module.exports = {
name: "blacklist",
description: "Blacklist a user from creating a ticket.",
options: [
{
name: "user",
description: "The user to blacklist",
type: 6,
required: true
},
{
name: "reason",
description: "The reason of blacklist",
type: 3
}
],
permission: "ADMINISTATOR",
run: async(interaction, client) => {
const user = interaction.options.getUser('user');
const reason = interaction.options.getString('reason') || 'No reason provided';

// check if user blacklisted
const isBlacklist = await client.db.get('blacklist', user.id);
if (isBlacklist) {
return interaction.reply({
content: ':x: This user already blacklisted.',
ephemeral: true
})
}

await client.db.set('blacklist', user.id, { user: user.id, reason });

interaction.reply({
content: `✅ ${user} (\`${user.id}\`) has been blacklisted.`
})
}
}
7 changes: 7 additions & 0 deletions commands/ticket/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ module.exports = {
category: "ticket",
usage: "/new",
run: async(interaction, client) => {
const isUserBlacklisted = await client.db.get('blacklist', interaction.user.id);
if (isUserBlacklisted) {
return interaction.reply({
content: ':x: You have been blacklisted from creating tickets.',
ephemeral: true
})
}
const getAllData = await client.db.all("tickets");
const config = await client.db.get('config', interaction.guild.id);
if (!config) {
Expand Down
31 changes: 31 additions & 0 deletions commands/ticket/unblacklist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module.exports = {
name: "unblacklist",
description: "Remove blacklist a user.",
options: [
{
name: "user",
description: "The user to unblacklist",
type: 6,
required: true
}
],
permission: "ADMINISTATOR",
run: async(interaction, client) => {
const user = interaction.options.getUser('user');

// check if user blacklisted
const isBlacklist = await client.db.get('blacklist', user.id);
if (!isBlacklist) {
return interaction.reply({
content: ':x: This user is not blacklisted.',
ephemeral: true
})
}

await client.db.delete('blacklist', user.id);

interaction.reply({
content: `✅ ${user} (\`${user.id}\`) has been unblacklisted.`
})
}
}
9 changes: 2 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,9 @@ require('colors');
});
db.create("tickets");
db.create("config");
db.create("blacklist");
})();

process.on('unhandledRejection', (err) => {
console.error(`Unhandled Rejection: ${err}`.red);
});

process.on('uncaughtException', (err) => {
console.error(`Uncaught Exception: ${err}`.red);
});
process.on('unhandledRejection', console.log)

client.login(process.env.TOKEN);

0 comments on commit ff93662

Please sign in to comment.