diff --git a/commands/Moderation/case.js b/commands/Moderation/case.js index dd63b31..530ce79 100644 --- a/commands/Moderation/case.js +++ b/commands/Moderation/case.js @@ -2,29 +2,31 @@ const { Command } = require('klasa'); module.exports = class extends Command { - constructor(...args) { - super(...args, { - name: 'case', - permLevel: 4, - runIn: ['text'], - description: language => language.get('COMMAND_CASE_DESCRIPTION'), - usage: '' - }); - } + constructor(...args) { + super(...args, { + name: 'case', + permLevel: 4, + runIn: ['text'], + description: language => language.get('COMMAND_CASE_DESCRIPTION'), + usage: '' + }); + } - async run(msg, [selected]) { - const log = msg.guild.settings.modlogs[selected]; - if (!log) return msg.send(`${msg.language.get('COMMAND_CASE_SORRY')} ${msg.author}, ${msg.language.get('COMMAND_CASE_NO')}`); + async run(msg, [caseNum]) { + const logs = await this.provider.get('modlogs', msg.guild.id); + const info = logs.infractions.find(infractions => infractions.case === caseNum); - const [user, moderator] = await Promise.all([ - this.client.users.fetch(log.user), - this.client.users.fetch(log.moderator) - ]); - return msg.send([ - `User : ${user.tag} (${user.id})`, - `Moderator : ${moderator.tag} (${moderator.id})`, - `Reason : ${log.reason || `${msg.language.get('COMMAND_CASE_REASON')} '${msg.guild.settings.prefix}reason ${selected}' ${msg.language.get('COMMAND_CASE_CLAIM')}`}` - ], { code: 'http' }); - } + const user = this.client.users.get(info.user); + const moderator = this.client.users.get(info.moderator); + return msg.send([ + `User : ${user.tag} (${user.id})`, + `Moderator : ${moderator.tag} (${moderator.id})`, + `Reason : ${info.reason || `${msg.language.get('COMMAND_CASE_REASON')} '${msg.guild.settings.prefix}reason ${caseNum}' ${msg.language.get('COMMAND_CASE_CLAIM')}`}` + ], { code: 'http' }); + } + + get provider() { + return this.client.providers.default; + } }; diff --git a/posrednik.js b/posrednik.js index 39c2330..661046e 100644 --- a/posrednik.js +++ b/posrednik.js @@ -19,6 +19,31 @@ class Posrednik extends Client { } +const client = new Posrednik(); + +client.gateways.register('modlogs', { + moderator: { + type: 'user', + default: null + }, + user: { + type: 'user', + default: null + }, + action: { + type: 'user', + default: null + }, + timed: { + type: 'boolean', + default: false + }, + duration: { + type: 'integer', + default: 0 + } +}); + // Logs the account in // noinspection JSIgnoredPromiseFromCall -new Posrednik().login(config.token); +client.login(config.token); diff --git a/util/modlog.js b/util/modlog.js index 964653f..20ca86e 100644 --- a/util/modlog.js +++ b/util/modlog.js @@ -9,6 +9,7 @@ module.exports = class ModLog { this.user = null; this.moderator = null; this.reason = null; + this.timed = null; this.case = null; } @@ -43,10 +44,15 @@ module.exports = class ModLog { return this; } + setTimed(value) { + this.timed = value; + return this; + } + // Checks if the modlog channel still exsists if not it throws an error to the console async send() { - const channel = this.guild.channels.get(this.guild.settings.channels.modlog); + const channel = this.guild.channels.get(this.guild.settings.modlog); if (!channel) throw 'The modlog channel does not exist, did it get deleted?'; await this.getCase(); return channel.send({ embed: this.embed }); @@ -61,7 +67,8 @@ module.exports = class ModLog { .setDescription([ `**Type**: ${this.type[0].toUpperCase() + this.type.slice(1)}`, `**User**: ${this.user.tag} (${this.user.id})`, - `**Reason**: ${this.reason || `Use \`${this.guild.settings.prefix}reason ${this.case}\` to claim this log.`}` + `**Reason**: ${this.reason || `Use \`${this.guild.settings.prefix}reason ${this.case}\` to claim this log.`}`, + `**Timed Infraction**: ${this.timed}` ]) .setFooter(`Case ${this.case}`) .setTimestamp(); @@ -71,8 +78,14 @@ module.exports = class ModLog { // Here we get the case number and create a modlog provider entry async getCase() { - this.case = this.guild.settings.modlogs.length; - return this.guild.settings.update('modlogs', this.pack); + const modlogs = await this.provider.get('modlogs', this.guild.id); + if (!modlogs) { + this.case = 0; + return this.provider.create('modlogs', this.guild.id, { infractions: [this.pack] }).then(() => 0); + } + this.case = modlogs.infractions.length + modlogs.infractions.push(this.pack); + await this.provider.update('modlogs', this.guild.id, modlogs); } // Here we pack all the info together @@ -83,10 +96,15 @@ module.exports = class ModLog { user: this.user.id, moderator: this.moderator.id, reason: this.reason, - case: this.case + case: this.case, + timed: this.timed }; } + get provider() { + return this.client.providers.default; + } + // And here we just define the color for a certain type of offence or action static colour(type) {