Skip to content
This repository has been archived by the owner on Jul 15, 2024. It is now read-only.

Commit

Permalink
feat: various changes + updates
Browse files Browse the repository at this point in the history
- Organise permissions in `/permissions`
- Remove `/ban info`
- Replace `/ban user` with `/ban`
- Move required perms check to interactionCreate, remove from functions
- Improve GC channel checking
  • Loading branch information
wdhdev committed Jul 1, 2023
1 parent f9b7f8f commit 122fe20
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 196 deletions.
272 changes: 105 additions & 167 deletions src/commands/mod/ban.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,28 @@ const verifiedSchema = require("../../models/verifiedSchema");

module.exports = {
name: "ban",
description: "Ban management commands.",
description: "[MODERATOR ONLY] Ban a user.",
options: [
{
type: 1,
name: "info",
description: "[MODERATOR ONLY] Get information about a user's ban.",
options: [
{
type: 6,
name: "user",
description: "The user who's ban information to get.",
required: true
}
]
type: 6,
name: "user",
description: "The user you want to ban.",
required: true
},

{
type: 1,
name: "user",
description: "[MODERATOR ONLY] Ban a user.",
options: [
{
type: 6,
name: "user",
description: "The user you want to ban.",
required: true
},

{
type: 3,
name: "reason",
description: "Why you want to ban the user.",
max_length: 250,
required: true
},

{
type: 5,
name: "appealable",
description: "Do you want this user to be able to appeal?",
required: true
}
]
type: 3,
name: "reason",
description: "Why you want to ban the user.",
max_length: 250,
required: true
},

{
type: 5,
name: "appealable",
description: "Do you want this user to be able to appeal?",
required: true
}
],
default_member_permissions: null,
Expand All @@ -72,141 +51,100 @@ module.exports = {
return;
}

if(interaction.options.getSubcommandGroup() === "info") {
const user = interaction.options.getUser("user");

if(!await bannedUserSchema.exists({ _id: user.id })) {
const error = new Discord.EmbedBuilder()
.setColor(client.config_embeds.error)
.setDescription(`${emoji.error} ${user} is not banned!`)

await interaction.editReply({ embeds: [error], ephemeral: true });
return;
}

const data = await bannedUserSchema.findOne({ _id: user.id });

if(!data.timestamp || !data.reason || !data.mod) {
const error = new Discord.EmbedBuilder()
.setColor(client.config_embeds.error)
.setDescription(`${emoji.error} No information is available about this ban!`)

await interaction.editReply({ embeds: [error], ephemeral: true });
return;
}

const banInfo = new Discord.EmbedBuilder()
.setColor(client.config_embeds.default)
.setAuthor({ name: user.tag.endsWith("#0") ? `@${user.username}` : user.tag, iconURL: user.displayAvatarURL({ format: "png", dynamic: true }), url: `https://discord.com/users/${user.id}` })
.setTitle("Ban Information")
.addFields (
{ name: "🕰️ Timestamp", value: `<t:${data.timestamp.slice(0, -3)}>` },
{ name: "❓ Reason", value: `${data.reason}` },
{ name: "📜 Appealable", value: data.allowAppeal ? "✅" : "❌" },
{ name: "🔨 Moderator", value: `<@${data.mod}>` }
)

await interaction.editReply({ embeds: [banInfo] });
const user = interaction.options.getUser("user");
const reason = interaction.options.getString("reason");
const appealable = interaction.options.getBoolean("appealable");

if(user.id === interaction.user.id) {
const error = new Discord.EmbedBuilder()
.setColor(client.config_embeds.error)
.setDescription(`${emoji.error} You cannot ban yourself!`)

await interaction.editReply({ embeds: [error], ephemeral: true });
return;
}

if(interaction.options.getSubcommand() === "user") {
const user = interaction.options.getUser("user");
const reason = interaction.options.getString("reason");
const appealable = interaction.options.getBoolean("appealable");

if(user.id === interaction.user.id) {
const error = new Discord.EmbedBuilder()
.setColor(client.config_embeds.error)
.setDescription(`${emoji.error} You cannot ban yourself!`)

await interaction.editReply({ embeds: [error], ephemeral: true });
return;
}

if(user.bot) {
const error = new Discord.EmbedBuilder()
.setColor(client.config_embeds.error)
.setDescription(`${emoji.error} You cannot ban bots!`)

await interaction.editReply({ embeds: [error], ephemeral: true });
return;
}

if(user.id === client.config_default.owner) {
const error = new Discord.EmbedBuilder()
.setColor(client.config_embeds.error)
.setDescription(`${emoji.error} You cannot ban that user!`)

await interaction.editReply({ embeds: [error], ephemeral: true });
return;
}

if(await bannedUserSchema.exists({ _id: user.id })) {
const error = new Discord.EmbedBuilder()
.setColor(client.config_embeds.error)
.setDescription(`${emoji.error} ${user} is already banned!`)

await interaction.editReply({ embeds: [error], ephemeral: true });
return;
}

new bannedUserSchema({
_id: user.id,
timestamp: Date.now(),
allowAppeal: appealable,
reason: reason,
mod: interaction.user.id
}).save()

await devSchema.findOneAndDelete({ _id: user.id });
await modSchema.findOneAndDelete({ _id: user.id });
await verifiedSchema.findOneAndDelete({ _id: user.id });

const ban = new Discord.EmbedBuilder()
if(user.bot) {
const error = new Discord.EmbedBuilder()
.setColor(client.config_embeds.error)
.setTitle("Banned")
.setDescription("ℹ️ You have been banned from using Global Chat.")
.addFields (
{ name: "❓ Reason", value: `${reason}` },
{ name: "📜 Appealable", value: appealable ? "✅" : "❌" }
)
.setTimestamp()

if(appealable) {
ban.addFields (
{ name: "ℹ️ How to Appeal", value: "1. Join the [support server](https://discord.gg/globalchat).\n2. Go to the [appeal channel](https://discord.com/channels/1067023529226293248/1094505532267704331).\n3. Click \`Submit\` and fill in the form.\n4. Wait for a response to your appeal." }
)
}

let sentDM = false;

try {
await user.send({ embeds: [ban] });
sentDM = true;
} catch {}

const banned = new Discord.EmbedBuilder()
.setColor(client.config_embeds.default)
.setDescription(`${emoji.successful} ${user} has been banned.`)

await interaction.editReply({ embeds: [banned] });

const banLog = new Discord.EmbedBuilder()
.setColor(client.config_embeds.default)
.setAuthor({ name: interaction.user.tag.endsWith("#0") ? `@${interaction.user.username}` : interaction.user.tag, iconURL: interaction.user.displayAvatarURL({ format: "png", dynamic: true }), url: `https://discord.com/users/${interaction.user.id}` })
.setTitle("User Banned")
.addFields (
{ name: "👤 User", value: `${user}` },
{ name: "🔔 User Notified", value: sentDM ? "✅" : "❌" },
{ name: "❓ Reason", value: `${reason}` },
{ name: "📜 Appealable", value: appealable ? "✅" : "❌" }
)
.setTimestamp()

modLogsChannel.send({ embeds: [banLog] });
.setDescription(`${emoji.error} You cannot ban bots!`)

await interaction.editReply({ embeds: [error], ephemeral: true });
return;
}

if(user.id === client.config_default.owner) {
const error = new Discord.EmbedBuilder()
.setColor(client.config_embeds.error)
.setDescription(`${emoji.error} You cannot ban that user!`)

await interaction.editReply({ embeds: [error], ephemeral: true });
return;
}

if(await bannedUserSchema.exists({ _id: user.id })) {
const error = new Discord.EmbedBuilder()
.setColor(client.config_embeds.error)
.setDescription(`${emoji.error} ${user} is already banned!`)

await interaction.editReply({ embeds: [error], ephemeral: true });
return;
}

new bannedUserSchema({
_id: user.id,
timestamp: Date.now(),
allowAppeal: appealable,
reason: reason,
mod: interaction.user.id
}).save()

await devSchema.findOneAndDelete({ _id: user.id });
await modSchema.findOneAndDelete({ _id: user.id });
await verifiedSchema.findOneAndDelete({ _id: user.id });

const ban = new Discord.EmbedBuilder()
.setColor(client.config_embeds.error)
.setTitle("Banned")
.setDescription("ℹ️ You have been banned from using Global Chat.")
.addFields (
{ name: "❓ Reason", value: `${reason}` },
{ name: "📜 Appealable", value: appealable ? "✅" : "❌" }
)
.setTimestamp()

if(appealable) {
ban.addFields (
{ name: "ℹ️ How to Appeal", value: "1. Join the [support server](https://discord.gg/globalchat).\n2. Go to the [appeal channel](https://discord.com/channels/1067023529226293248/1094505532267704331).\n3. Click \`Submit\` and fill in the form.\n4. Wait for a response to your appeal." }
)
}

let sentDM = false;

try {
await user.send({ embeds: [ban] });
sentDM = true;
} catch {}

const banned = new Discord.EmbedBuilder()
.setColor(client.config_embeds.default)
.setDescription(`${emoji.successful} ${user} has been banned.`)

await interaction.editReply({ embeds: [banned] });

const banLog = new Discord.EmbedBuilder()
.setColor(client.config_embeds.default)
.setAuthor({ name: interaction.user.tag.endsWith("#0") ? `@${interaction.user.username}` : interaction.user.tag, iconURL: interaction.user.displayAvatarURL({ format: "png", dynamic: true }), url: `https://discord.com/users/${interaction.user.id}` })
.setTitle("User Banned")
.addFields (
{ name: "👤 User", value: `${user}` },
{ name: "🔔 User Notified", value: sentDM ? "✅" : "❌" },
{ name: "❓ Reason", value: `${reason}` },
{ name: "📜 Appealable", value: appealable ? "✅" : "❌" }
)
.setTimestamp()

modLogsChannel.send({ embeds: [banLog] });
} catch(err) {
client.logCommandError(err, interaction, Discord);
}
Expand Down
16 changes: 7 additions & 9 deletions src/commands/user/permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ module.exports = {
async execute(interaction, client, Discord) {
try {
const permissions = {
ManageWebhooks: "Manage Webhooks",
ViewChannel: "Read Messages/View Channels",
SendMessages: "Send Messages",
ManageMessages: "Manage Messages",
EmbedLinks: "Embed Links",
AttachFiles: "Attach Files",
EmbedLinks: "Embed Links",
ManageMessages: "Manage Messages",
ManageWebhooks: "Manage Webhooks",
ReadMessageHistory: "Read Message History",
UseExternalEmojis: "Use External Emojis"
SendMessages: "Send Messages",
UseExternalEmojis: "Use External Emojis",
ViewChannel: "Read Messages/View Channels"
}

const perms = [];
Expand Down Expand Up @@ -49,9 +49,7 @@ module.exports = {
.setURL("https://wdh.gg/globalchat")
)

if(disallowedPerms.length) return await interaction.editReply({ embeds: [permissionsEmbed], components: [inviteButton] });

await interaction.editReply({ embeds: [permissionsEmbed] });
await interaction.editReply({ embeds: [permissionsEmbed], components: disallowedPerms.length ? [inviteButton] : [] });
} catch(err) {
client.logCommandError(err, interaction, Discord);
}
Expand Down
3 changes: 3 additions & 0 deletions src/events/guild/interactionCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ module.exports = {
name: "interactionCreate",
async execute(client, Discord, interaction) {
try {
const requiredPerms = ["SendMessages", "EmbedLinks"];

if(!interaction.guild) return;
if(!interaction.guild.members.me.permissions.has(requiredPerms)) return;

if(interaction.isButton()) return await buttonInteraction(client, Discord, interaction);
if(interaction.isCommand()) return await commandInteraction(client, Discord, interaction);
Expand Down
13 changes: 5 additions & 8 deletions src/events/guild/messageCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,16 @@ module.exports = {
name: "messageCreate",
async execute(client, Discord, message) {
try {
if(message.author.bot || !message.guild) return;

const requiredPerms = ["SendMessages", "EmbedLinks", "ManageMessages"];

if(message.author.bot || !message.guild) return;
if(!message.guild.members.me.permissions.has(requiredPerms)) return;

channelSchema.findOne({ _id: message.guild.id }, async (err, data) => {
if(data && data.channel && data.channel === message.channel.id) {
send(message, client, Discord);
}
})
if(await channelSchema.exists({ _id: message.guild.id, channel: message.channel.id })) {
await send(message, client, Discord);
}
} catch(err) {
client.logEventError(err);
}
}
}
}
7 changes: 1 addition & 6 deletions src/util/interaction/button.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
const emoji = require("../../config.json").emojis;

module.exports = async function buttonInteraction(client, Discord, interaction) {
module.exports = async (client, Discord, interaction) => {
try {
const requiredPerms = ["SendMessages", "EmbedLinks"];

if(!interaction.guild.members.me.permissions.has(requiredPerms)) return;
if(!interaction.isButton()) return;

const button = client.buttons.get(interaction.customId);

if(button) {
Expand Down
7 changes: 1 addition & 6 deletions src/util/interaction/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@ const bannedUserSchema = require("../../models/bannedUserSchema");

const cooldowns = new Map();

module.exports = async function commandInteraction(client, Discord, interaction) {
module.exports = async (client, Discord, interaction) => {
try {
const requiredPerms = ["SendMessages", "EmbedLinks"];

if(!interaction.guild.members.me.permissions.has(requiredPerms)) return;
if(!interaction.isCommand()) return;

if(await bannedUserSchema.exists({ _id: interaction.user.id })) {
const error = new Discord.EmbedBuilder()
.setColor(client.config_embeds.error)
Expand Down

0 comments on commit 122fe20

Please sign in to comment.