Working structures

This commit is contained in:
Neko Life 2021-05-24 13:42:26 +00:00
parent 0b0fcf916b
commit 4140f5c49b

View file

@ -1,70 +1,64 @@
'use strict'; 'use strict';
const { Structures } = require("discord.js"); const { Structures, User } = require("discord.js"),
{ database } = require("../database/mongo");
class Settings { Structures.extend("Guild", g => {
constructor(client, type, id) { return class Guild extends g {
this.client = client;
this.type = type;
this.id = id;
}
get(setting) {
collection(this.type).findOne({ id: this.id })[setting];
}
}
Structures.extend("Guild", Guild => {
return class GuildSettings extends Guild {
constructor(client, data) { constructor(client, data) {
super(client, data); super(client, data);
this.settings = new Settings(client, "Guild", this.id); database.collection("Guild").findOne({document: this.id}).then(r => {
this.infractions = r?.moderation?.infractions;
this.moderation = r?.moderation?.settings;
this.defaultEmbed = r?.settings?.defaultEmbed;
}).catch(() => {});
} }
embed = { /**
footer: { * Get user infractions
text: undefined, * @param {User} get - User object
icon: undefined * @returns {Array<Object>} Infractions object
}, */
timestamp: false async getInfractions(get) {
}; let found;
moderation = { if (this.infractions.length > 0) {
mute: { found = [];
role: undefined, this.infractions.map(r => {
duration: { if (r) {
date: undefined, for (const inf of r) {
string: undefined if (inf?.by) {
}, if (inf.by.includes(get)) {
log: undefined, found.push(inf);
publicLog: undefined }
}, }
ban: { }
duration: { }
date: undefined, });
string: undefined
},
log: undefined,
publicLog: undefined
},
kick: {
log: undefined,
publicLog: undefined
} }
return found;
}
async setDefaultEmbed(set) {
await database.collection("Guild").updateOne({document: this.id}, {$set:{"settings.defaultEmbed": set}}, {upsert: true}).catch(e => {throw e});
this.defaultEmbed = set;
return true;
}
async setModerationSettings(set) {
await database.collection("Guild").updateOne({document:this.id}, {$set:{"moderation.settings": set}}, {upsert: true}).catch(e => {throw e});
this.moderation = set;
return true;
} }
} }
}); });
Structures.extend("User", User => { Structures.extend("User", u => {
return class Settings extends User { return class User extends u {
constructor(client, data) { constructor(client, data) {
super(client, data); super(client, data);
this.settings = new Settings(client, User, this.id); database.collection("User").findOne({document: this.id}).then(r => this.defaultEmbed = r?.settings?.defaultEmbed).catch(() => {});
}
async setDefaultEmbed(set) {
await database.collection("User").updateOne({document: this.id}, {$set:{"settings.defaultEmbed": set}}, {upsert: true}).catch(e => {throw e});
this.defaultEmbed = set;
return true;
} }
embed = {
footer: {
text: undefined,
icon: undefined
},
timestamp: false
};
} }
}); });