proper listing method for settings

This commit is contained in:
Erik 2022-09-22 00:59:25 +03:00
parent e28b2f2890
commit a70098259f
Signed by untrusted user: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB
14 changed files with 115 additions and 10 deletions

View File

@ -38,6 +38,7 @@ class IgnoreSetting extends Setting {
{ name: 'remove', value: 'remove' }, { name: 'remove', value: 'remove' },
{ name: 'set', value: 'set' }, { name: 'set', value: 'set' },
{ name: 'reset', value: 'reset' }, { name: 'reset', value: 'reset' },
{ name: 'list', value: 'list' }
], ],
dependsOn: ['list']//, valueAsAlias: true, flag: true dependsOn: ['list']//, valueAsAlias: true, flag: true
} }
@ -50,6 +51,8 @@ class IgnoreSetting extends Setting {
const { list, method } = opts; const { list, method } = opts;
if (method.value === 'list') return this.list(setting[list.value], interaction, list.value);
const response = await this._prompt(interaction, { const response = await this._prompt(interaction, {
index: `SETTING_PROMPT_${method.value.toUpperCase()}`, index: `SETTING_PROMPT_${method.value.toUpperCase()}`,
params: { list: list.value } params: { list: list.value }

View File

@ -40,6 +40,7 @@ class ProtectionSetting extends Setting {
{ name: 'remove', value: 'remove' }, { name: 'remove', value: 'remove' },
{ name: 'set', value: 'set' }, { name: 'set', value: 'set' },
{ name: 'reset', value: 'reset' }, { name: 'reset', value: 'reset' },
{ name: 'list', value: 'list' }
], ],
dependsOn: [] dependsOn: []
}, },
@ -62,6 +63,8 @@ class ProtectionSetting extends Setting {
if (type) setting.type = type.value; if (type) setting.type = type.value;
if (enabled) setting.enabled = enabled.value; if (enabled) setting.enabled = enabled.value;
if (roles.value === 'list') return this.list(setting.roles, interaction, 'roles');
if (roles) { if (roles) {
const response = await this._prompt(interaction, { const response = await this._prompt(interaction, {

View File

@ -60,6 +60,7 @@ class MessageLog extends Setting {
{ name: 'remove', value: 'remove' }, { name: 'remove', value: 'remove' },
{ name: 'set', value: 'set' }, { name: 'set', value: 'set' },
{ name: 'reset', value: 'reset' }, { name: 'reset', value: 'reset' },
{ name: 'list', value: 'list' }
], ],
dependsOn: ['list'] dependsOn: ['list']
}, },
@ -107,6 +108,8 @@ class MessageLog extends Setting {
if (method && list) { if (method && list) {
if (method === 'list') return this.list(setting[list], interaction, list);
const time = 120; const time = 120;
const content = await this._prompt(interaction, { const content = await this._prompt(interaction, {
message: guild.format(`SETTING_PROMPT_${method.toUpperCase()}`, message: guild.format(`SETTING_PROMPT_${method.toUpperCase()}`,
@ -114,7 +117,7 @@ class MessageLog extends Setting {
time time
}); });
if (content.error) return content; if (content.error) return content;
if (method.value === 'reset' && !this.client.resolver.resolveBoolean(content)) { if (method === 'reset' && !this.client.resolver.resolveBoolean(content)) {
return { index: 'SETTING_NO_CHANGE' }; return { index: 'SETTING_NO_CHANGE' };
} }

View File

@ -32,6 +32,7 @@ class Grantable extends Setting {
{ name: 'remove', value: 'remove' }, { name: 'remove', value: 'remove' },
{ name: 'set', value: 'set' }, { name: 'set', value: 'set' },
{ name: 'reset', value: 'reset' }, { name: 'reset', value: 'reset' },
{ name: 'list', value: 'list' }
] ]
} }
] ]
@ -45,6 +46,9 @@ class Grantable extends Setting {
let index = 'SETTING_SUCCESS_ALT'; let index = 'SETTING_SUCCESS_ALT';
if (enabled) setting.enabled = enabled.value; if (enabled) setting.enabled = enabled.value;
if (roles.value === 'list') return this.list(setting.roles, interaction, 'roles');
if (roles) { if (roles) {
const response = await this._prompt(interaction, { const response = await this._prompt(interaction, {

View File

@ -97,7 +97,7 @@ class InviteFilterSetting extends FilterSetting {
if (method && list) { if (method && list) {
if (list === 'actions') return this._action(interaction, method, setting[list]); if (list === 'actions') return this._action(interaction, method, setting[list]);
else if (method === 'list') return { error: false, message: setting[list].join(', ') }; else if (method === 'list') return this.list(setting[list], interaction, list); //{ error: false, message: setting[list].join(', ') };
const { guild } = interaction; const { guild } = interaction;
const time = 120; const time = 120;
@ -168,17 +168,17 @@ class InviteFilterSetting extends FilterSetting {
}, },
{ {
name: 'GENERAL_IGNORED', name: 'GENERAL_IGNORED',
value: setting.ignore?.map((channel) => `<#${channel}>`).join(', ') || '**N/A**', value: setting.ignore.map((channel) => `<#${channel}>`).join(', ') || '**N/A**',
inline: true inline: true
}, },
{ {
name: 'GENERAL_BYPASS', name: 'GENERAL_BYPASS',
value: setting.bypass?.map((role) => `<@&${role}>`).join(', ') || '**N/A**', value: setting.bypass.map((role) => `<@&${role}>`).join(', ') || '**N/A**',
inline: true inline: true
}, },
{ {
name: 'SETTING_FILTER_ACTIONS', name: 'SETTING_FILTER_ACTIONS',
value: setting.actions?.reduce((acc, val) => { value: setting.actions.reduce((acc, val) => {
let str = `**${val.type}**`; let str = `**${val.type}**`;
if (val.points) str += ` (${val.points} points)`; if (val.points) str += ` (${val.points} points)`;
if (val.duration) str += ` for ${Util.humanise(val.duration)}`; if (val.duration) str += ` for ${Util.humanise(val.duration)}`;

View File

@ -115,7 +115,7 @@ class LinkFilterSetting extends FilterSetting {
if (method && list) { if (method && list) {
if (list === 'actions') return this._action(interaction, method, setting[list]); if (list === 'actions') return this._action(interaction, method, setting[list]);
else if (method === 'list') return { error: false, message: setting[list].join(', ') }; else if (method === 'list') return this.list(setting[list], interaction, list); //{ error: false, message: setting[list].join(', ') };
const { guild } = interaction; const { guild } = interaction;
const time = 120; const time = 120;

View File

@ -91,7 +91,7 @@ class MentionFilter extends FilterSetting {
if (method && list) { if (method && list) {
if (list.value === 'actions') return this._action(interaction, method.value, setting[list.value]); if (list.value === 'actions') return this._action(interaction, method.value, setting[list.value]);
else if (method.value === 'list') return { message: setting[list.value].join(', ') }; else if (method.value === 'list') return this.list(setting[list.value], interaction, list.value); //{ message: setting[list.value].join(', ') };
const { guild } = interaction; const { guild } = interaction;
const time = 120; const time = 120;

View File

@ -0,0 +1,42 @@
const { Setting } = require("../../../interfaces");
class RaidprotectionSetting extends Setting {
constructor(client) {
super(client, {
name: 'raidprotection',
display: 'Raid Protection',
description: 'Prevent users meeting certain criteria from joining',
module: 'moderation',
default: {
enabled: false,
age: 0,
pfpCheck: false
},
commandOptions: [
{
type: 'BOOLEAN', flag: true, valueOptional: true, defaultValue: true,
name: 'enabled',
description: 'Toggle enable state'
}, {
type: 'BOOLEAN', flag: true, valueOptional: true, defaultValue: true,
name: 'pfpcheck',
description: 'Whether to check for a default profile picture'
}, {
type: 'TIME',
name: 'age',
description: 'Threshold for the account age'
}
]
});
}
async execute(invoker, { enabled, pfpcheck, age }, settings) {
}
}
module.exports = RaidprotectionSetting;

View File

@ -106,7 +106,7 @@ class WordFilterSetting extends FilterSetting {
if (method && list) { if (method && list) {
if (list === 'actions') return this._action(interaction, method, setting[list]); if (list === 'actions') return this._action(interaction, method, setting[list]);
else if (method === 'list') return { error: false, message: setting[list].join(', ') }; else if (method === 'list') return this.list(setting[list], interaction, list); //{ error: false, message: setting[list].join(', ') };
const { guild } = interaction; const { guild } = interaction;
const time = 120; const time = 120;

View File

@ -70,7 +70,7 @@ class WordWatcher extends FilterSetting {
if (method && list) { if (method && list) {
if (list.value === 'actions') return this._action(interaction, method.value, setting[list.value], { _wordWatcher: true }); if (list.value === 'actions') return this._action(interaction, method.value, setting[list.value], { _wordWatcher: true });
else if (method.value === 'list') return { error: false, content: setting[list.value].join(', ') }; else if (method.value === 'list') return this.list(setting[list.value], interaction, list.value); //{ error: false, content: setting[list.value].join(', ') };
const { guild } = interaction; const { guild } = interaction;
const time = 120; const time = 120;

View File

@ -47,6 +47,8 @@ class Autorole extends Setting {
if (typeof enabled === 'boolean') setting.enabled = enabled; if (typeof enabled === 'boolean') setting.enabled = enabled;
if (method === 'list') return this.list(setting.roles, interaction, 'roles');
if (method) { if (method) {
const { guild } = interaction; const { guild } = interaction;
const time = 120; const time = 120;

View File

@ -25,6 +25,7 @@ class SelfroleSetting extends Setting {
{ name: 'remove', value: 'remove' }, { name: 'remove', value: 'remove' },
{ name: 'set', value: 'set' }, { name: 'set', value: 'set' },
{ name: 'reset', value: 'reset' }, { name: 'reset', value: 'reset' },
{ name: 'list', value: 'list' }
], ],
}, { }, {
name: 'channel', name: 'channel',
@ -41,7 +42,9 @@ class SelfroleSetting extends Setting {
if (!roles && !channel && !text) return { error: true, index: 'SETTING_MISSING_ARG' }; if (!roles && !channel && !text) return { error: true, index: 'SETTING_MISSING_ARG' };
const { guild } = invoker; const { guild } = invoker;
if (roles.value === 'list') return this.list(setting.roles, invoker, 'roles');
if (roles) { if (roles) {
const response = await this._prompt(invoker, { const response = await this._prompt(invoker, {
index: `SETTING_PROMPT_${roles.value.toUpperCase()}`, index: `SETTING_PROMPT_${roles.value.toUpperCase()}`,

View File

@ -47,6 +47,8 @@ class Autorole extends Setting {
const method = opts.roles?.value; const method = opts.roles?.value;
if (typeof enabled === 'boolean') setting.enabled = enabled; if (typeof enabled === 'boolean') setting.enabled = enabled;
if (method === 'list') return this.list(setting.roles, interaction, 'roles');
if (method) { if (method) {
const { guild } = interaction; const { guild } = interaction;
const time = 120; const time = 120;

View File

@ -244,6 +244,49 @@ class Setting extends Component {
return { list, modified }; return { list, modified };
} }
async list(items, invoker, type = 'text') {
items = items.map((i) => i.toString());
const strings = [];
let string = '';
const { resolver } = this.client;
const resolvers = {
bypass: resolver.resolveRole.bind(resolver),
roles: resolver.resolveRole.bind(resolver),
ignore: resolver.resolveChannel.bind(resolver),
channels: resolver.resolveChannel.bind(resolver)
};
for (let item of items) {
if (resolvers[type]) {
const resolved = await resolvers[type](item, true, invoker.guild);
if(resolved) item = resolved.toString();
}
if (string.length + item.length > 2000 && string.length) {
strings.push(string);
string = '';
}
string += `${item}, `;
}
if(string.length) strings.push(string.substring(0, string.length -2));
// await invoker.reply({ content: `Ok.`, emoji: 'success' });
for (const str of strings) {
if(!invoker.replied) await invoker.reply(str);
else await invoker.channel.send(str);
}
return null;
}
// Functions for message component based settings // Functions for message component based settings
/** /**
* Abstract components method, should be overridden by the implementing class and called, returns the select menu component. * Abstract components method, should be overridden by the implementing class and called, returns the select menu component.