This repository has been archived by the owner on Jul 15, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: blocking users + reduce db requests
- Loading branch information
Showing
26 changed files
with
404 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
const { PermissionFlagsBits } = require("discord.js"); | ||
|
||
const emoji = require("../../config.json").emojis; | ||
|
||
const Guild = require("../../models/Guild"); | ||
const User = require("../../models/User"); | ||
|
||
module.exports = { | ||
name: "block", | ||
description: "Block a user's messages sending to this guild.", | ||
options: [ | ||
{ | ||
type: 6, | ||
name: "user", | ||
description: "The user to block.", | ||
required: true | ||
} | ||
], | ||
default_member_permissions: PermissionFlagsBits.ManageGuild.toString(), | ||
botPermissions: [], | ||
requiredRoles: [], | ||
cooldown: 10, | ||
enabled: true, | ||
hidden: false, | ||
deferReply: true, | ||
ephemeral: true, | ||
async execute(interaction, client, Discord) { | ||
try { | ||
const user = interaction.options.getUser("user"); | ||
|
||
let data = await Guild.findOne({ _id: interaction.guild.id }); | ||
const userData = await User.findOne({ _id: user.id }); | ||
|
||
if(!data) { | ||
const error = new Discord.EmbedBuilder() | ||
.setColor(client.config_embeds.error) | ||
.setDescription(`${emoji.cross} This guild is not registered!`) | ||
|
||
await interaction.editReply({ embeds: [error] }); | ||
return; | ||
} | ||
|
||
if(data.blockedUsers.includes(user.id)) { | ||
const error = new Discord.EmbedBuilder() | ||
.setColor(client.config_embeds.error) | ||
.setDescription(`${emoji.cross} That user is already blocked!`) | ||
|
||
await interaction.editReply({ embeds: [error] }); | ||
return; | ||
} | ||
|
||
if(userData.dev || userData.mod) { | ||
const error = new Discord.EmbedBuilder() | ||
.setColor(client.config_embeds.error) | ||
.setDescription(`${emoji.cross} You cannot block Global Chat staff!`) | ||
|
||
await interaction.editReply({ embeds: [error] }); | ||
return; | ||
} | ||
|
||
if(user.id === interaction.guild.ownerId) { | ||
const error = new Discord.EmbedBuilder() | ||
.setColor(client.config_embeds.error) | ||
.setDescription(`${emoji.cross} You cannot block the guild owner!`) | ||
|
||
await interaction.editReply({ embeds: [error] }); | ||
return; | ||
} | ||
|
||
if(user.bot) { | ||
const error = new Discord.EmbedBuilder() | ||
.setColor(client.config_embeds.error) | ||
.setDescription(`${emoji.cross} You cannot block bots!`) | ||
|
||
await interaction.editReply({ embeds: [error] }); | ||
return; | ||
} | ||
|
||
if(!data.blockedUsers) { | ||
Guild.findOneAndUpdate({ _id: interaction.guild.id }, { blockedUsers: [user.id] }, (err, data) => {}); | ||
} else { | ||
data.blockedUsers.push(user.id); | ||
await data.save(); | ||
} | ||
|
||
const blocked = new Discord.EmbedBuilder() | ||
.setColor(client.config_embeds.default) | ||
.setDescription(`${emoji.tick} ${user} has been blocked!`) | ||
|
||
await interaction.editReply({ embeds: [blocked] }); | ||
} catch(err) { | ||
client.logCommandError(err, interaction, Discord); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
const { PermissionFlagsBits } = require("discord.js"); | ||
|
||
const emoji = require("../../config.json").emojis; | ||
|
||
const Guild = require("../../models/Guild"); | ||
|
||
module.exports = { | ||
name: "blocked", | ||
description: "Get a list of all the guild's blocked users.", | ||
options: [], | ||
default_member_permissions: PermissionFlagsBits.ManageGuild.toString(), | ||
botPermissions: [], | ||
requiredRoles: [], | ||
cooldown: 10, | ||
enabled: true, | ||
hidden: false, | ||
deferReply: true, | ||
ephemeral: true, | ||
async execute(interaction, client, Discord) { | ||
try { | ||
const data = await Guild.findOne({ _id: interaction.guild.id }); | ||
|
||
if(!data) { | ||
const error = new Discord.EmbedBuilder() | ||
.setColor(client.config_embeds.error) | ||
.setDescription(`${emoji.cross} This guild is not registered!`) | ||
|
||
await interaction.editReply({ embeds: [error] }); | ||
return; | ||
} | ||
|
||
if(!data.blockedUsers.length) { | ||
const error = new Discord.EmbedBuilder() | ||
.setColor(client.config_embeds.error) | ||
.setDescription(`${emoji.cross} This guild has not blocked any users!`) | ||
|
||
await interaction.editReply({ embeds: [error] }); | ||
return; | ||
} | ||
|
||
const blocked = new Discord.EmbedBuilder() | ||
.setColor(client.config_embeds.red) | ||
.setTitle("⛔ Blocked Users") | ||
.setDescription(`<@${data.blockedUsers.join(">, <@")}>`) | ||
|
||
await interaction.editReply({ embeds: [blocked] }); | ||
} catch(err) { | ||
client.logCommandError(err, interaction, Discord); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.