From 53683a66e8733be8519d3ffc4803c8d292e1538a Mon Sep 17 00:00:00 2001 From: Navy Date: Mon, 25 May 2020 00:43:27 +0300 Subject: [PATCH] nickname logs --- .../settings/moderation/NicknameLogs.js | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 structure/client/components/settings/moderation/NicknameLogs.js diff --git a/structure/client/components/settings/moderation/NicknameLogs.js b/structure/client/components/settings/moderation/NicknameLogs.js new file mode 100644 index 0000000..f0d7e73 --- /dev/null +++ b/structure/client/components/settings/moderation/NicknameLogs.js @@ -0,0 +1,98 @@ +const { Setting } = require('../../../../interfaces/'); + +class NicknameLogs extends Setting { + + constructor(client) { + + super(client, { + name: 'nicknameLog', + module: 'moderation', + aliases: [ + 'nicknameLogs', + 'nickLog', + 'nickLogs' + ], + usage: '', + guarded: true, + resolve: 'GUILD', + examples: [ + 'nicklogs reset', + 'nicklogs on|off', + 'nicklogs #channel' + ], + default: { + nicknameLog: { + channel: null, + enabled: false + } + } + }); + + this.client = client; + + } + + async handle(message, params) { + + // eslint-disable-next-line init-declarations + let index, changes, action; + // eslint-disable-next-line prefer-const + let [method, ...args] = params; + method = method.toLowerCase(); + + const setting = message.guild._settings[this.index] || this.default[this.index]; + const { guild } = message; + + if (this.client.resolver.resolveBoolean(method)) { + + setting.enabled = setting.channel && true; + index = 'S_NICKNAMELOG_TOGGLE'; + changes = message.format('ON_OFF_TOGGLE', { toggle: true }, true); + + } else if (this.client.resolver.resolveBoolean(method) === false) { + + setting.enabled = false; + index = 'S_NICKNAMELOG_TOGGLE' + changes = message.format('ON_OFF_TOGGLE', { toggle: false }, true); + + } else { + + const channel = guild.resolveChannel(method); + if (!channel) return { + msg: message.format('ERR_CHANNEL_RESOLVE', { resolveable: method }), + error: true + }; + + index = 'S_NICKNAMELOG_CHANNEL'; + changes = channel.name; + setting.channel = channel.id; + setting.enabled = true; + + } + + await message.guild._updateSettings({ [this.index]: setting }); + return { + msg: message.format(index, { changed: changes || '', action: message.format(action) }) + }; + + } + + async fields(guild) { + const setting = guild._settings[this.index]; + return [ + { + name: '》Enabled', + value: setting?.enabled || false, + inline: true + }, + { + name: '》Channel', + value: guild.resolveChannel(setting?.channel) || '`N/A`', + inline: true + } + ]; + } + +} + +module.exports = NicknameLogs; \ No newline at end of file