guild indexing

This commit is contained in:
Erik 2020-06-10 17:49:46 +03:00
parent 883a1de725
commit 9101d99e08

View File

@ -0,0 +1,97 @@
const { Setting } = require('../../../../interfaces');
class DescriptionSetting extends Setting {
constructor(client) {
super(client, {
name: 'index',
module: 'utility',
index: 'guildIndex',
aliases: [
],
usage: '<method|value..>',
examples: [
'index on',
'index description some description here',
'description some description here',
'description clear'
],
guarded: false,
resolve: 'GUILD',
default: {
guildIndex: {
indexed: false,
description: 'Use `-settings description` to change your guild description',
tags: []
}
},
custom: true
});
this.client = client;
}
async handle(message, params) {
let index = null,
langParams = {};
const setting = message.guild._settings[this.index] || this.default[this.index];
const { guild } = message;
const { resolver } = this.client;
const method = params[0].toLowerCase();
if (method === 'description' || message._settingCaller === 'description') {
if (method === 'description') params.shift();
if (params[0].toLowerCase() === 'clear') setting.description = this.default[this.index].description;
else setting.description = params.join(', ');
index = 'S_INDEX_DESCRIPTION_SET';
langParams.changes = setting.description || 'N/A';
} else if (resolver.resolveBoolean(method)) {
setting.indexed = true;
index = 'S_INDEX_TOGGLE';
langParams.toggle = message.format('ON_OFF_TOGGLE', { toggle: true }, true);
} else if (resolver.resolveBoolean(method) === false) {
setting.indexed = false;
index = 'S_INDEX_TOGGLE';
langParams.toggle = message.format('ON_OFF_TOGGLE', { toggle: false }, true);
} else return { error: true, msg: message.format('ERR_INVALID_METHOD', { method }) };
await message.guild._updateSettings({ [this.index]: setting });
return { error: false, msg: message.format(index, langParams) };
}
async fields(guild) {
const setting = guild._settings[this.index];
return [
{
name: '》Indexing',
value: setting?.indexed,
inline: true
}, {
name: '》Tags',
value: setting?.tags.join(', ') || 'N/A',
inline: true
}, {
name: '》Description',
value: setting?.description || 'N/A'
}
];
}
}
module.exports = DescriptionSetting;