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

Commit

Permalink
feat: new update
Browse files Browse the repository at this point in the history
- Merge user-related schemas into one
- Other updates
  • Loading branch information
wdhdev committed Jul 9, 2023
1 parent e534549 commit 4177c4f
Show file tree
Hide file tree
Showing 35 changed files with 279 additions and 283 deletions.
4 changes: 2 additions & 2 deletions src/buttons/logs/blocked-message-ban.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const emoji = require("../../config.json").emojis;

const bannedUserSchema = require("../../models/bannedUserSchema");
const immuneSchema = require("../../models/immuneSchema");
const userSchema = require("../../models/userSchema");

module.exports = {
name: "blocked-message-ban",
Expand All @@ -20,7 +20,7 @@ module.exports = {
return;
}

if(await immuneSchema.exists({ _id: id })) {
if(await userSchema.exists({ _id: id, immune: true })) {
const error = new Discord.EmbedBuilder()
.setColor(client.config_embeds.error)
.setDescription(`${emoji.cross} You cannot ban that user!`)
Expand Down
4 changes: 2 additions & 2 deletions src/buttons/logs/message-ban.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const emoji = require("../../config.json").emojis;

const bannedUserSchema = require("../../models/bannedUserSchema");
const immuneSchema = require("../../models/immuneSchema");
const userSchema = require("../../models/userSchema");

module.exports = {
name: "message-ban",
Expand All @@ -20,7 +20,7 @@ module.exports = {
return;
}

if(await immuneSchema.exists({ _id: id })) {
if(await userSchema.exists({ _id: id, immune: true })) {
const error = new Discord.EmbedBuilder()
.setColor(client.config_embeds.error)
.setDescription(`${emoji.cross} You cannot ban that user!`)
Expand Down
4 changes: 2 additions & 2 deletions src/buttons/logs/report-ban.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const emoji = require("../../config.json").emojis;

const bannedUserSchema = require("../../models/bannedUserSchema");
const immuneSchema = require("../../models/immuneSchema");
const userSchema = require("../../models/userSchema");

module.exports = {
name: "report-ban",
Expand All @@ -20,7 +20,7 @@ module.exports = {
return;
}

if(await immuneSchema.exists({ _id: id })) {
if(await userSchema.exists({ _id: id, immune: true })) {
const error = new Discord.EmbedBuilder()
.setColor(client.config_embeds.error)
.setDescription(`${emoji.cross} You cannot ban that user!`)
Expand Down
161 changes: 21 additions & 140 deletions src/commands/dev/admin.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,12 @@
const emoji = require("../../config.json").emojis;

const devSchema = require("../../models/devSchema");
const donatorSchema = require("../../models/donatorSchema");
const immuneSchema = require("../../models/immuneSchema");
const modSchema = require("../../models/modSchema");
const todoSchema = require("../../models/todoSchema");
const verifiedSchema = require("../../models/verifiedSchema");
const userSchema = require("../../models/userSchema");

module.exports = {
name: "admin",
description: "Admin Commands",
options: [
{
type: 2,
name: "dev",
description: "Manage the developer role.",
options: [
{
type: 1,
name: "add",
description: "[OWNER ONLY] Promote a user to a developer.",
options: [
{
type: 6,
name: "user",
description: "The user to promote.",
required: true
}
]
},

{
type: 1,
name: "remove",
description: "[OWNER ONLY] Demote a user from a developer.",
options: [
{
type: 6,
name: "user",
description: "The user to demote.",
required: true
}
]
}
]
},

{
type: 1,
name: "donators",
Expand Down Expand Up @@ -179,96 +140,8 @@ module.exports = {
try {
const logsChannel = client.channels.cache.get(client.config_channels.logs);

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

if(interaction.user.id !== client.config_default.owner) {
const error = new Discord.EmbedBuilder()
.setColor(client.config_embeds.error)
.setDescription(`${emoji.cross} You do not have permission to run this command!`)

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

if(interaction.options.getSubcommand() === "add") {
if(user.bot) {
const error = new Discord.EmbedBuilder()
.setColor(client.config_embeds.error)
.setDescription(`${emoji.cross} You cannot make a bot a developer!`)

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

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

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

new devSchema({ _id: user.id }).save();

const added = new Discord.EmbedBuilder()
.setColor(client.config_embeds.default)
.setDescription(`${emoji.tick} ${user} has been added to the developer role.`)

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

const log = 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("Role Added")
.addFields (
{ name: "🎭 Role", value: "💻 Developer" },
{ name: "👤 User", value: `${user}` }
)
.setTimestamp()

logsChannel.send({ embeds: [log] });
return;
}

if(interaction.options.getSubcommand() === "remove") {
if(!await devSchema.exists({ _id: user.id })) {
const error = new Discord.EmbedBuilder()
.setColor(client.config_embeds.error)
.setDescription(`${emoji.cross} ${user} is not a developer!`)

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

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

const removed = new Discord.EmbedBuilder()
.setColor(client.config_embeds.default)
.setDescription(`${emoji.tick} ${user} has been removed from the developer role.`)

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

const log = 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("Role Removed")
.addFields (
{ name: "🎭 Role", value: "💻 Developer" },
{ name: "👤 User", value: `${user}` }
)
.setTimestamp()

logsChannel.send({ embeds: [log] });
return;
}

return;
}

if(interaction.options.getSubcommand() === "donators") {
const data = await donatorSchema.find();
const data = await userSchema.find({ donator: true });

const users = [];

Expand All @@ -295,7 +168,7 @@ module.exports = {
}

if(interaction.options.getSubcommand() === "immune") {
const data = await immuneSchema.find();
const data = await userSchema.find({ immune: true });

const users = [];

Expand Down Expand Up @@ -334,7 +207,7 @@ module.exports = {
return;
}

if(await modSchema.exists({ _id: user.id })) {
if(await userSchema.exists({ _id: user.id, mod: true })) {
const error = new Discord.EmbedBuilder()
.setColor(client.config_embeds.error)
.setDescription(`${emoji.cross} ${user} is already a moderator!`)
Expand All @@ -343,7 +216,11 @@ module.exports = {
return;
}

new modSchema({ _id: user.id }).save();
if(!await userSchema.exists({ _id: user.id })) {
new userSchema({ _id: user.id, mod: true }).save();
} else {
userSchema.findOneAndUpdate({ _id: user.id }, { mod: true }, (err, data) => {});
}

const added = new Discord.EmbedBuilder()
.setColor(client.config_embeds.default)
Expand All @@ -366,7 +243,7 @@ module.exports = {
}

if(interaction.options.getSubcommand() === "remove") {
if(!await modSchema.exists({ _id: user.id })) {
if(!await userSchema.exists({ _id: user.id, mod: true })) {
const error = new Discord.EmbedBuilder()
.setColor(client.config_embeds.error)
.setDescription(`${emoji.cross} ${user} is not a moderator!`)
Expand All @@ -375,7 +252,7 @@ module.exports = {
return;
}

await modSchema.findOneAndDelete({ _id: user.id });
await userSchema.findOneAndUpdate({ _id: user.id }, { mod: false });

const removed = new Discord.EmbedBuilder()
.setColor(client.config_embeds.default)
Expand Down Expand Up @@ -556,7 +433,7 @@ module.exports = {
if(interaction.options.getSubcommand() === "unverify") {
const user = interaction.options.getUser("user");

if(!await verifiedSchema.exists({ _id: user.id })) {
if(!await userSchema.exists({ _id: user.id, verified: true })) {
const error = new Discord.EmbedBuilder()
.setColor(client.config_embeds.error)
.setDescription(`${emoji.cross} ${user} is not verified!`)
Expand All @@ -565,11 +442,11 @@ module.exports = {
return;
}

await verifiedSchema.findOneAndDelete({ _id: user.id });
userSchema.findOneAndUpdate({ _id: user.id }, { verified: false });

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

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

Expand All @@ -588,7 +465,7 @@ module.exports = {
}

if(interaction.options.getSubcommand() === "verified") {
const verified = await verifiedSchema.find();
const verified = await userSchema.find({ verified: true });

const users = [];

Expand Down Expand Up @@ -626,7 +503,7 @@ module.exports = {
return;
}

if(await verifiedSchema.exists({ _id: user.id })) {
if(await userSchema.exists({ _id: user.id, verified: true })) {
const error = new Discord.EmbedBuilder()
.setColor(client.config_embeds.error)
.setDescription(`${emoji.cross} ${user} is already verified!`)
Expand All @@ -635,7 +512,11 @@ module.exports = {
return;
}

new verifiedSchema({ _id: user.id }).save();
if(!await userSchema.exists({ _id: user.id })) {
new userSchema({ _id: user.id, verified: true }).save();
} else {
userSchema.findOneAndUpdate({ _id: user.id }, { verified: true }, (err, data) => {});
}

const verified = new Discord.EmbedBuilder()
.setColor(client.config_embeds.default)
Expand Down
13 changes: 5 additions & 8 deletions src/commands/info/bot.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
const bot = require("../../../package.json");

const devSchema = require("../../models/devSchema");
const donatorSchema = require("../../models/donatorSchema");
const messageSchema = require("../../models/messageSchema");
const modSchema = require("../../models/modSchema");
const verifiedSchema = require("../../models/verifiedSchema");
const userSchema = require("../../models/userSchema");

module.exports = {
name: "bot",
Expand All @@ -29,10 +26,10 @@ module.exports = {
{ name: "🟢 Online Since", value: `<t:${(Date.now() - client.uptime).toString().slice(0, -3)}:f> (<t:${(Date.now() - client.uptime).toString().slice(0, -3)}:R>)`, inline: true }
)

const developers = await devSchema.find();
const moderators = await modSchema.find();
const verified = await verifiedSchema.find();
const donators = await donatorSchema.find();
const developers = await userSchema.find({ dev: true });
const moderators = await userSchema.find({ mod: true });
const verified = await userSchema.find({ verified: true });
const donators = await userSchema.find({ donator: true });

const messages = await messageSchema.find();
const images = await messageSchema.find({ attachment: { $ne: null } });
Expand Down
4 changes: 2 additions & 2 deletions src/commands/info/developers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const emoji = require("../../config.json").emojis;

const devSchema = require("../../models/devSchema");
const userSchema = require("../../models/userSchema");

module.exports = {
name: "developers",
Expand All @@ -16,7 +16,7 @@ module.exports = {
ephemeral: true,
async execute(interaction, client, Discord) {
try {
const data = await devSchema.find();
const data = await userSchema.find({ dev: true });

const users = [];

Expand Down
4 changes: 2 additions & 2 deletions src/commands/info/moderators.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const emoji = require("../../config.json").emojis;

const modSchema = require("../../models/modSchema");
const userSchema = require("../../models/userSchema");

module.exports = {
name: "moderators",
Expand All @@ -16,7 +16,7 @@ module.exports = {
ephemeral: true,
async execute(interaction, client, Discord) {
try {
const data = await modSchema.find();
const data = await userSchema.find({ mod: true });

const users = [];

Expand Down
4 changes: 2 additions & 2 deletions src/commands/mod/ban.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const emoji = require("../../config.json").emojis;

const bannedUserSchema = require("../../models/bannedUserSchema");
const immuneSchema = require("../../models/immuneSchema");
const userSchema = require("../../models/userSchema");

module.exports = {
name: "ban",
Expand Down Expand Up @@ -63,7 +63,7 @@ module.exports = {
return;
}

if(await immuneSchema.exists({ _id: user.id })) {
if(await userSchema.exists({ _id: user.id, immune: true })) {
const error = new Discord.EmbedBuilder()
.setColor(client.config_embeds.error)
.setDescription(`${emoji.cross} You cannot ban that user!`)
Expand Down
Loading

0 comments on commit 4177c4f

Please sign in to comment.