subcommand to list tall current settings configs

This commit is contained in:
Erik 2022-08-02 14:43:00 +03:00
parent 915428f1a2
commit fbb7c8a234
Signed by untrusted user: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB

View File

@ -1,5 +1,6 @@
const { SlashCommand } = require("../../../interfaces");
const { Util } = require('../../../../utilities');
const { Constants: { EmbedLimits, ZeroWidthChar, EmbedDefaultColor } } = require("../../../../constants");
class SettingsCommand extends SlashCommand {
@ -14,6 +15,10 @@ class SettingsCommand extends SlashCommand {
name: 'list',
description: 'List available settings',
type: 'SUB_COMMAND'
}, {
name: 'current',
description: 'Display ALL current configurations (big embed)',
type: 'SUB_COMMAND'
}
],
memberPermissions: ['ManageGuild']
@ -25,6 +30,7 @@ class SettingsCommand extends SlashCommand {
const subcmd = invoker.subcommand.name;
if (subcmd === 'list') return this._listSettings(invoker);
else if(subcmd === 'current') return this._currentSettings(invoker);
}
@ -57,6 +63,60 @@ class SettingsCommand extends SlashCommand {
}
async _currentSettings(invoker) {
const { guild } = invoker;
const { settings } = this.client.registry;
const fields = [];
for (const setting of settings.values()) {
const settingFields = await setting.fields(guild);
if (!settingFields.length) continue;
let _field = {
name: `**__${setting.name.toUpperCase()}__**`,
value: ''
};
for (const field of settingFields) {
if (field.name === ZeroWidthChar) continue;
const str = `**${guild.format(field.name)}**\n${field.value}`;
if (_field.value.length + str.length >= EmbedLimits.fieldValue) {
fields.push(_field);
_field = {
name: ZeroWidthChar,
value: ''
};
}
_field.value += `\n\n${str}`;
}
fields.push(_field);
}
const embeds = [];
let embed = { fields: [] };
for (const field of fields) {
field.inline = true;
embed.fields.push(field);
if (embed.fields.length === EmbedLimits.fieldObjects ||
embed.fields.reduce((count, field) => {
count += field.name.length + field.value.length;
return count;
}, 0) >= EmbedLimits.embed) {
embeds.push(embed);
embed = { fields: [] };
}
}
await invoker.reply({ embeds: [embeds.shift()] });
for (const embed of embeds) {
embed.color = EmbedDefaultColor;
await invoker.channel.send({ embeds: [embed] });
}
return null;
}
}
module.exports = SettingsCommand;