Add some more commands for management
This commit is contained in:
parent
84f512bec6
commit
24e742510d
148
index.js
148
index.js
|
@ -150,6 +150,45 @@ Client.on("ready", async () => {
|
|||
required: true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "massban",
|
||||
description: "Mass ban users from all games",
|
||||
type: 1,
|
||||
default_member_permissions: 8,
|
||||
options: [
|
||||
{
|
||||
name: "users",
|
||||
description: "The user IDs to ban, Comma separated",
|
||||
type: 3,
|
||||
required: true
|
||||
},
|
||||
{
|
||||
name: "reason",
|
||||
description: "The reason for the ban",
|
||||
type: 3,
|
||||
required: true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "massunban",
|
||||
description: "Mass unban users from all games",
|
||||
type: 1,
|
||||
default_member_permissions: 8,
|
||||
options: [
|
||||
{
|
||||
name: "users",
|
||||
description: "The user IDs to unban, Comma separated",
|
||||
type: 3,
|
||||
required: true
|
||||
}
|
||||
]
|
||||
},{
|
||||
name: "export",
|
||||
description: "Export the bans table",
|
||||
type: 1,
|
||||
default_member_permissions: 8
|
||||
}
|
||||
]
|
||||
|
||||
|
@ -348,6 +387,115 @@ Client.on("interactionCreate", async (interaction) => {
|
|||
}
|
||||
}
|
||||
})
|
||||
break;
|
||||
case "massban":
|
||||
// Ban multiple users
|
||||
users = await interaction.options.get("users").value
|
||||
reason = await interaction.options.get("reason").value
|
||||
users = users.split(",")
|
||||
users.forEach((user) => {
|
||||
db.get("SELECT * FROM bans WHERE userId = ?", [user], (err, row) => {
|
||||
if (err) {
|
||||
console.error(err)
|
||||
interaction.reply({
|
||||
content: "An error occurred while checking the user's ban status.",
|
||||
ephemeral: true
|
||||
})
|
||||
} else {
|
||||
if (!row) {
|
||||
db.run("INSERT INTO bans (userId, banned, reason, timestamp) VALUES (?, ?, ?, ?)", [user, 1, reason, new Date().toISOString()], (err) => {
|
||||
if (err) {
|
||||
console.error(err)
|
||||
interaction.reply({
|
||||
content: "An error occurred while banning the user.",
|
||||
ephemeral: true
|
||||
})
|
||||
}
|
||||
})
|
||||
} else if(row.banned === 0) {
|
||||
db.run("UPDATE bans SET banned = 1, reason = ?, timestamp = ? WHERE userId = ?", [reason, new Date().toISOString(), user], (err) => {
|
||||
if (err) {
|
||||
console.error(err)
|
||||
interaction.reply({
|
||||
content: "An error occurred while banning the user.",
|
||||
ephemeral: true
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
interaction.reply({
|
||||
content: "Users have been banned.",
|
||||
ephemeral: true
|
||||
})
|
||||
break;
|
||||
case "massunban":
|
||||
// Unban multiple users
|
||||
users = await interaction.options.get("users").value
|
||||
users = users.split(",")
|
||||
users.forEach((user) => {
|
||||
db.get("SELECT * FROM bans WHERE userId = ?", [user], (err, row) => {
|
||||
if (err) {
|
||||
console.error(err)
|
||||
interaction.reply({
|
||||
content: "An error occurred while checking the user's ban status.",
|
||||
ephemeral: true
|
||||
})
|
||||
} else {
|
||||
if (row) {
|
||||
if (!row.banned) {
|
||||
interaction.reply({
|
||||
content: "User is not banned.",
|
||||
ephemeral: true
|
||||
})
|
||||
return;
|
||||
}
|
||||
db.run("UPDATE bans SET banned = 0 WHERE userId = ?", [user], (err) => {
|
||||
if (err) {
|
||||
console.error(err)
|
||||
interaction.reply({
|
||||
content: "An error occurred while unbanning the user.",
|
||||
ephemeral: true
|
||||
})
|
||||
}
|
||||
})
|
||||
} else {
|
||||
interaction.reply({
|
||||
content: "User is not banned.",
|
||||
ephemeral: true
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
interaction.reply({
|
||||
content: "Users have been unbanned.",
|
||||
ephemeral: true
|
||||
})
|
||||
break;
|
||||
case "export":
|
||||
db.all("SELECT * FROM bans", (err, rows) => {
|
||||
if (err) {
|
||||
console.error(err)
|
||||
interaction.reply({
|
||||
content: "An error occurred while exporting the bans table.",
|
||||
ephemeral: true
|
||||
})
|
||||
} else {
|
||||
const data = JSON.stringify(rows)
|
||||
interaction.reply({
|
||||
content: "Here is the bans table.",
|
||||
files: [{
|
||||
attachment: Buffer.from(data),
|
||||
name: "bans.json"
|
||||
}],
|
||||
ephemeral: true
|
||||
})
|
||||
}
|
||||
})
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue