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

Commit

Permalink
feat: donator role
Browse files Browse the repository at this point in the history
  • Loading branch information
wdhdev committed Jul 9, 2023
1 parent 57b731a commit f04e287
Show file tree
Hide file tree
Showing 12 changed files with 221 additions and 53 deletions.
75 changes: 73 additions & 2 deletions src/commands/dev/admin.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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");
Expand Down Expand Up @@ -45,6 +46,13 @@ module.exports = {
]
},

{
type: 1,
name: "donators",
description: "[DEVELOPER ONLY] Get a list of all the donators.",
options: []
},

{
type: 1,
name: "immune",
Expand Down Expand Up @@ -117,6 +125,13 @@ module.exports = {
]
},

{
type: 1,
name: "supporters",
description: "[DEVELOPER ONLY] Get a list of all the supporters.",
options: []
},

{
type: 1,
name: "unverify",
Expand Down Expand Up @@ -252,12 +267,39 @@ module.exports = {
return;
}

if(interaction.options.getSubcommand() === "donators") {
const data = await donatorSchema.find();

const users = [];

for(const user of data) {
users.push(user._id);
}

if(!users.length) {
const error = new Discord.EmbedBuilder()
.setColor(client.config_embeds.error)
.setDescription(`${emoji.cross} There are no donators!`)

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

const donators = new Discord.EmbedBuilder()
.setColor(client.config_embeds.default)
.setTitle("💸 Donators")
.setDescription(`<@${users.join(">, <@")}>`)

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

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

const users = [];

for(const user of immune) {
for(const user of data) {
users.push(user._id);
}

Expand Down Expand Up @@ -482,6 +524,35 @@ module.exports = {
return;
}

if(interaction.options.getSubcommand() === "supporters") {
const guild = await client.guilds.fetch(client.config_default.guild);
const members = await guild.members.fetch();
const boosters = members.filter(member => member.premiumSinceTimestamp);

const users = [];

for(const [userId, guildMember] of boosters) {
users.push(userId);
}

if(!users.length) {
const error = new Discord.EmbedBuilder()
.setColor(client.config_embeds.error)
.setDescription(`${emoji.cross} There are no supporters!`)

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

const supporters = new Discord.EmbedBuilder()
.setColor(client.config_embeds.default)
.setTitle("💖 Supporters")
.setDescription(`<@${users.join(">, <@")}>`)

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

if(interaction.options.getSubcommand() === "unverify") {
const user = interaction.options.getUser("user");

Expand Down
6 changes: 5 additions & 1 deletion src/commands/info/bot.js
Original file line number Diff line number Diff line change
@@ -1,6 +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");
Expand Down Expand Up @@ -31,6 +32,8 @@ module.exports = {
const developers = await devSchema.find();
const moderators = await modSchema.find();
const verifiedUsers = await verifiedSchema.find();
const donators = await donatorSchema.find();

const messages = await messageSchema.find();
const images = await messageSchema.find({ attachment: { $ne: null } });

Expand All @@ -44,6 +47,7 @@ module.exports = {
const stat_developers = `💻 ${developers.length} Developer${developers.length === 1 ? "" : "s"}`;
const stat_moderators = `🔨 ${moderators.length} Moderator${moderators.length === 1 ? "" : "s"}`;
const stat_verified = `✅ ${verifiedUsers.length} Verified User${verifiedUsers.length === 1 ? "" : "s"}`;
const stat_donators = `💸 ${donators.length} Donator${boosters.size === 1 ? "" : "s"}`;
const stat_supporters = `💖 ${boosters.size} Supporter${boosters.size === 1 ? "" : "s"}`;

const stat_messages = `💬 ${messages.length} Message${messages.length === 1 ? "" : "s"}`;
Expand All @@ -53,7 +57,7 @@ module.exports = {
.setColor(client.config_embeds.default)
.addFields (
{ name: "🤖 Bot", value: `${stat_guilds}\n${stat_users}`, inline: true },
{ name: "🎭 Roles", value: `${stat_developers}\n${stat_moderators}\n${stat_verified}\n${stat_supporters}`, inline: true },
{ name: "🎭 Roles", value: `${stat_developers}\n${stat_moderators}\n${stat_verified}\n${stat_donators}\n${stat_supporters}`, inline: true },
{ name: "🌐 Global Chat", value: `${stat_messages}\n${stat_images}`, inline: true }
)

Expand Down
4 changes: 2 additions & 2 deletions src/commands/info/developers.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ module.exports = {
ephemeral: true,
async execute(interaction, client, Discord) {
try {
const devs = await devSchema.find();
const data = await devSchema.find();

const users = [];

for(const user of devs) {
for(const user of data) {
users.push(user._id);
}

Expand Down
4 changes: 2 additions & 2 deletions src/commands/info/moderators.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ module.exports = {
ephemeral: true,
async execute(interaction, client, Discord) {
try {
const mods = await modSchema.find();
const data = await modSchema.find();

const users = [];

for(const user of mods) {
for(const user of data) {
users.push(user._id);
}

Expand Down
46 changes: 0 additions & 46 deletions src/commands/info/supporters.js

This file was deleted.

1 change: 1 addition & 0 deletions src/commands/mod/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module.exports = {
if(role.dev) roles.push("💻 Developer");
if(role.mod) roles.push("🔨 Moderator");
if(role.verified) roles.push("✅ Verified");
if(role.donator) roles.push("💸 Donator");
if(role.supporter) roles.push("💖 Supporter");

// Immunity
Expand Down
126 changes: 126 additions & 0 deletions src/commands/owner/donator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
const emoji = require("../../config.json").emojis;

const donatorSchema = require("../../models/donatorSchema");

module.exports = {
name: "donator",
description: "Manage the donator role.",
options: [
{
type: 1,
name: "add",
description: "[OWNER ONLY] Add a user to the donator role.",
options: [
{
type: 6,
name: "user",
description: "The user to add.",
required: true
}
]
},

{
type: 1,
name: "remove",
description: "[OWNER ONLY] Remove a user from the donator role.",
options: [
{
type: 6,
name: "user",
description: "The user to remove.",
required: true
}
]
}
],
default_member_permissions: null,
botPermissions: [],
requiredRoles: ["owner"],
cooldown: 0,
enabled: true,
hidden: true,
deferReply: true,
ephemeral: true,
async execute(interaction, client, Discord) {
try {
const logsChannel = client.channels.cache.get(client.config_channels.logs);
const user = interaction.options.getUser("user");

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 donator!`)

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

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

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

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

const added = new Discord.EmbedBuilder()
.setColor(client.config_embeds.default)
.setDescription(`${emoji.tick} ${user} has been added to the donator 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: "💸 Donator" },
{ name: "👤 User", value: `${user}` }
)
.setTimestamp()

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

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

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

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

const removed = new Discord.EmbedBuilder()
.setColor(client.config_embeds.default)
.setDescription(`${emoji.tick} ${user} has been removed from the donator 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: "💸 Donator" },
{ name: "👤 User", value: `${user}` }
)
.setTimestamp()

logsChannel.send({ embeds: [log] });
return;
}
} catch(err) {
client.logCommandError(err, interaction, Discord);
}
}
}
1 change: 1 addition & 0 deletions src/context-menu/user/User Info.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module.exports = {
if(role.dev) roles.push("💻 Developer");
if(role.mod) roles.push("🔨 Moderator");
if(role.verified) roles.push("✅ Verified");
if(role.donator) roles.push("💸 Donator");
if(role.supporter) roles.push("💖 Supporter");

// Immunity
Expand Down
7 changes: 7 additions & 0 deletions src/models/donatorSchema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const mongoose = require("mongoose");

const schema = new mongoose.Schema({
_id: String
})

module.exports = mongoose.model("donators", schema, "donators")
1 change: 1 addition & 0 deletions src/util/roles/assign.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/util/roles/get.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const devSchema = require("../../models/devSchema");
const donatorSchema = require("../../models/donatorSchema");
const modSchema = require("../../models/modSchema");
const verifiedSchema = require("../../models/verifiedSchema");

Expand All @@ -17,6 +18,7 @@ module.exports = async function (userId, client) {
"dev": await devSchema.exists({ _id: userId }) ? true : false,
"mod": await modSchema.exists({ _id: userId }) ? true : false,
"verified": await verifiedSchema.exists({ _id: userId }) ? true : false,
"donator": await donatorSchema.exists({ _id: userId }) ? true : false,
"supporter": supporter
}
}
Loading

0 comments on commit f04e287

Please sign in to comment.