From b7b5d0dc5db3e7a7170b78daa06f50d0e8c945e0 Mon Sep 17 00:00:00 2001 From: Neko Life Date: Mon, 24 May 2021 17:26:11 +0000 Subject: [PATCH] Definitely working structures --- resources/structures.js | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) 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});