diff --git a/resources/structures.js b/resources/structures.js index ae422d4..3502ef9 100644 --- a/resources/structures.js +++ b/resources/structures.js @@ -15,26 +15,29 @@ Structures.extend("Guild", g => { } /** * Get user infractions - * @param {User} get - User object - * @returns {Array} Infractions object + * @param {String} get - User ID + * @returns {Promise} Infractions object */ async getInfractions(get) { - let found; - if (this.infractions.length > 0) { - found = []; - this.infractions.map(r => { - if (r) { - for (const inf of r) { - if (inf?.by) { - if (inf.by.includes(get)) { - found.push(inf); - } + try { + const r = await database.collection("Guild").findOne({ document: this.id }); + this.infractions = r?.moderation?.infractions; + let found = []; + if (this.infractions.length > 0) { + for (const inf of this.infractions) { + let added = false; + for (const user of inf.by) { + if (user.id === get) { + found.push(inf); + break; } } } - }); - } - return found; + if (found.length > 0) { + return found; + } + } + } catch (e) { } } async setDefaultEmbed(set) { await database.collection("Guild").updateOne({document: this.id}, {$set:{"settings.defaultEmbed": set}}, {upsert: true}).catch(e => {throw e});