big work today!
diff --git a/src/utils/client.ts b/src/utils/client.ts
index b05ef5f..857fb1d 100644
--- a/src/utils/client.ts
+++ b/src/utils/client.ts
@@ -32,14 +32,13 @@
callback: (interaction: Interaction) => Promise<void>,
check: (interaction: Interaction, partial: boolean) => Promise<boolean> | boolean,
autocomplete: (interaction: AutocompleteInteraction) => Promise<string[]>
- } | undefined,{name: string, description: string}]> = {};
+ } | undefined, {name: string, description: string}]> = {};
fetchedCommands = new Collection<string, Discord.ApplicationCommand>();
constructor(database: typeof NucleusClient.prototype.database) {
super({ intents: 0b1100011011011111111111});
this.database = database;
}
}
-
const client = new NucleusClient({
guilds: await new Guilds().setup(),
history: new History(),
diff --git a/src/utils/commandRegistration/register.ts b/src/utils/commandRegistration/register.ts
index 1a19e2c..78e3b0f 100644
--- a/src/utils/commandRegistration/register.ts
+++ b/src/utils/commandRegistration/register.ts
@@ -111,7 +111,7 @@
context.command.setNameLocalizations(context.nameLocalizations ?? {})
commands.push(context.command);
- client.commands["contextCommands/message/" + context.command.name] = context;
+ client.commands["contextCommands/message/" + context.command.name] = [context, {name: context.name ?? context.command.name, description: context.description ?? context.command.description}];
console.log(`${last.replace("└", " ").replace("├", "│")} └─ ${colors.green}Loaded ${file.name} [${i} / ${totalFiles}]${colors.none}`)
} catch (e) {
@@ -181,6 +181,7 @@
}
async function execute(check: Function | undefined, callback: Function | undefined, data: CommandInteraction) {
+ console.log(client.commands["contextCommands/user/User info"])
if (!callback) return;
if (check) {
let result;
@@ -197,7 +198,7 @@
.setColor(NucleusColors.red)
.setEmoji(getEmojiByName("CONTROL.BLOCKCROSS"))
], ephemeral: true});
- };
+ }
}
callback(data);
}
diff --git a/src/utils/database.ts b/src/utils/database.ts
index 239da13..e7336d0 100644
--- a/src/utils/database.ts
+++ b/src/utils/database.ts
@@ -1,3 +1,4 @@
+import type { GuildMember } from "discord.js";
import type Discord from "discord.js";
import { Collection, MongoClient } from "mongodb";
import config from "../config/main.js";
@@ -245,11 +246,36 @@
await this.premium.insertOne({ user: user, appliesTo: [], level: level });
}
- async hasPremium(guild: string) {
+ async hasPremium(guild: string): Promise<[boolean, string, number] | null> {
+ const entries = await this.premium.find({}).toArray();
+ const members = await (await client.guilds.fetch(guild)).members.fetch()
+ for(const {user} of entries) {
+ const member = members.get(user);
+ if(member) {
+ const modPerms = //TODO: Create list in config for perms
+ member.permissions.has("Administrator") ||
+ member.permissions.has("ManageChannels") ||
+ member.permissions.has("ManageRoles") ||
+ member.permissions.has("ManageEmojisAndStickers") ||
+ member.permissions.has("ManageWebhooks") ||
+ member.permissions.has("ManageGuild") ||
+ member.permissions.has("KickMembers") ||
+ member.permissions.has("BanMembers") ||
+ member.permissions.has("ManageEvents") ||
+ member.permissions.has("ManageMessages") ||
+ member.permissions.has("ManageThreads")
+ const entry = entries.find(e => e.user === member.id);
+ if(entry && (entry.level === 3) && modPerms) return [true, member.id, entry.level];
+ }
+ }
const entry = await this.premium.findOne({
- appliesTo: { $in: [guild] }
+ appliesTo: {
+ $elemMatch: {
+ $eq: guild
+ }
+ }
});
- return entry ? true : false;
+ return entry ? [true, entry.user, entry.level] : null;
}
async fetchUser(user: string): Promise<PremiumSchema | null> {
@@ -258,26 +284,55 @@
return entry;
}
- async checkAllPremium() {
+ async checkAllPremium(member?: GuildMember) {
const entries = await this.premium.find({}).toArray();
- for(const {user, expiresAt} of entries) {
- if(expiresAt) expiresAt < Date.now() ? await this.premium.deleteOne({user: user}) : null;
- const member = await (await client.guilds.fetch("684492926528651336")).members.fetch(user)
- let level: number = 0;
- if (member.roles.cache.has("1066468879309750313")) {
+ if(member) {
+ const entry = entries.find(e => e.user === member.id);
+ if(entry) {
+ const expiresAt = entry.expiresAt;
+ if(expiresAt) expiresAt < Date.now() ? await this.premium.deleteOne({user: member.id}) : null;
+ }
+ const roles = member.roles;
+ let level = 0;
+ if (roles.cache.has("1066468879309750313")) {
level = 99;
- } else if (member.roles.cache.has("1066465491713003520")) {
+ } else if (roles.cache.has("1066465491713003520")) {
level = 1;
- } else if (member.roles.cache.has("1066439526496604194")) {
+ } else if (roles.cache.has("1066439526496604194")) {
level = 2;
- } else if (member.roles.cache.has("1066464134322978912")) {
+ } else if (roles.cache.has("1066464134322978912")) {
level = 3;
}
-
+ await this.updateUser(member.id, level);
if (level > 0) {
- await this.updateUser(user, level);
+ await this.premium.updateOne({ user: member.id }, {$unset: { expiresAt: ""}})
} else {
- await this.premium.updateOne({ user: user }, { expiresAt: (Date.now() + (1000*60*60*24*3)) })
+ await this.premium.updateOne({ user: member.id }, {$set: { expiresAt: (Date.now() + (1000*60*60*24*3)) }})
+ }
+ } else {
+ const members = await (await client.guilds.fetch('684492926528651336')).members.fetch();
+ for(const {roles, id} of members.values()) {
+ const entry = entries.find(e => e.user === id);
+ if(entry) {
+ const expiresAt = entry.expiresAt;
+ if(expiresAt) expiresAt < Date.now() ? await this.premium.deleteOne({user: id}) : null;
+ }
+ let level: number = 0;
+ if (roles.cache.has("1066468879309750313")) {
+ level = 99;
+ } else if (roles.cache.has("1066465491713003520")) {
+ level = 1;
+ } else if (roles.cache.has("1066439526496604194")) {
+ level = 2;
+ } else if (roles.cache.has("1066464134322978912")) {
+ level = 3;
+ }
+ await this.updateUser(id, level);
+ if (level > 0) {
+ await this.premium.updateOne({ user: id }, {$unset: { expiresAt: ""}})
+ } else {
+ await this.premium.updateOne({ user: id }, {$set: { expiresAt: (Date.now() + (1000*60*60*24*3)) }})
+ }
}
}
}