forked from Galactic/galactic-bot
proper listing method for settings
This commit is contained in:
parent
e28b2f2890
commit
a70098259f
@ -38,6 +38,7 @@ class IgnoreSetting extends Setting {
|
||||
{ name: 'remove', value: 'remove' },
|
||||
{ name: 'set', value: 'set' },
|
||||
{ name: 'reset', value: 'reset' },
|
||||
{ name: 'list', value: 'list' }
|
||||
],
|
||||
dependsOn: ['list']//, valueAsAlias: true, flag: true
|
||||
}
|
||||
@ -50,6 +51,8 @@ class IgnoreSetting extends Setting {
|
||||
|
||||
const { list, method } = opts;
|
||||
|
||||
if (method.value === 'list') return this.list(setting[list.value], interaction, list.value);
|
||||
|
||||
const response = await this._prompt(interaction, {
|
||||
index: `SETTING_PROMPT_${method.value.toUpperCase()}`,
|
||||
params: { list: list.value }
|
||||
|
@ -40,6 +40,7 @@ class ProtectionSetting extends Setting {
|
||||
{ name: 'remove', value: 'remove' },
|
||||
{ name: 'set', value: 'set' },
|
||||
{ name: 'reset', value: 'reset' },
|
||||
{ name: 'list', value: 'list' }
|
||||
],
|
||||
dependsOn: []
|
||||
},
|
||||
@ -62,6 +63,8 @@ class ProtectionSetting extends Setting {
|
||||
if (type) setting.type = type.value;
|
||||
if (enabled) setting.enabled = enabled.value;
|
||||
|
||||
if (roles.value === 'list') return this.list(setting.roles, interaction, 'roles');
|
||||
|
||||
if (roles) {
|
||||
|
||||
const response = await this._prompt(interaction, {
|
||||
|
@ -60,6 +60,7 @@ class MessageLog extends Setting {
|
||||
{ name: 'remove', value: 'remove' },
|
||||
{ name: 'set', value: 'set' },
|
||||
{ name: 'reset', value: 'reset' },
|
||||
{ name: 'list', value: 'list' }
|
||||
],
|
||||
dependsOn: ['list']
|
||||
},
|
||||
@ -107,6 +108,8 @@ class MessageLog extends Setting {
|
||||
|
||||
if (method && list) {
|
||||
|
||||
if (method === 'list') return this.list(setting[list], interaction, list);
|
||||
|
||||
const time = 120;
|
||||
const content = await this._prompt(interaction, {
|
||||
message: guild.format(`SETTING_PROMPT_${method.toUpperCase()}`,
|
||||
@ -114,7 +117,7 @@ class MessageLog extends Setting {
|
||||
time
|
||||
});
|
||||
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' };
|
||||
}
|
||||
|
||||
|
@ -32,6 +32,7 @@ class Grantable extends Setting {
|
||||
{ name: 'remove', value: 'remove' },
|
||||
{ name: 'set', value: 'set' },
|
||||
{ name: 'reset', value: 'reset' },
|
||||
{ name: 'list', value: 'list' }
|
||||
]
|
||||
}
|
||||
]
|
||||
@ -45,6 +46,9 @@ class Grantable extends Setting {
|
||||
let index = 'SETTING_SUCCESS_ALT';
|
||||
|
||||
if (enabled) setting.enabled = enabled.value;
|
||||
|
||||
if (roles.value === 'list') return this.list(setting.roles, interaction, 'roles');
|
||||
|
||||
if (roles) {
|
||||
|
||||
const response = await this._prompt(interaction, {
|
||||
|
@ -97,7 +97,7 @@ class InviteFilterSetting extends FilterSetting {
|
||||
if (method && 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 time = 120;
|
||||
@ -168,17 +168,17 @@ class InviteFilterSetting extends FilterSetting {
|
||||
},
|
||||
{
|
||||
name: 'GENERAL_IGNORED',
|
||||
value: setting.ignore?.map((channel) => `<#${channel}>`).join(', ') || '**N/A**',
|
||||
value: setting.ignore.map((channel) => `<#${channel}>`).join(', ') || '**N/A**',
|
||||
inline: true
|
||||
},
|
||||
{
|
||||
name: 'GENERAL_BYPASS',
|
||||
value: setting.bypass?.map((role) => `<@&${role}>`).join(', ') || '**N/A**',
|
||||
value: setting.bypass.map((role) => `<@&${role}>`).join(', ') || '**N/A**',
|
||||
inline: true
|
||||
},
|
||||
{
|
||||
name: 'SETTING_FILTER_ACTIONS',
|
||||
value: setting.actions?.reduce((acc, val) => {
|
||||
value: setting.actions.reduce((acc, val) => {
|
||||
let str = `**${val.type}**`;
|
||||
if (val.points) str += ` (${val.points} points)`;
|
||||
if (val.duration) str += ` for ${Util.humanise(val.duration)}`;
|
||||
|
@ -115,7 +115,7 @@ class LinkFilterSetting extends FilterSetting {
|
||||
if (method && 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 time = 120;
|
||||
|
@ -91,7 +91,7 @@ class MentionFilter extends FilterSetting {
|
||||
if (method && list) {
|
||||
|
||||
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 time = 120;
|
||||
|
@ -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;
|
@ -106,7 +106,7 @@ class WordFilterSetting extends FilterSetting {
|
||||
if (method && 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 time = 120;
|
||||
|
@ -70,7 +70,7 @@ class WordWatcher extends FilterSetting {
|
||||
if (method && list) {
|
||||
|
||||
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 time = 120;
|
||||
|
@ -47,6 +47,8 @@ class Autorole extends Setting {
|
||||
|
||||
if (typeof enabled === 'boolean') setting.enabled = enabled;
|
||||
|
||||
if (method === 'list') return this.list(setting.roles, interaction, 'roles');
|
||||
|
||||
if (method) {
|
||||
const { guild } = interaction;
|
||||
const time = 120;
|
||||
|
@ -25,6 +25,7 @@ class SelfroleSetting extends Setting {
|
||||
{ name: 'remove', value: 'remove' },
|
||||
{ name: 'set', value: 'set' },
|
||||
{ name: 'reset', value: 'reset' },
|
||||
{ name: 'list', value: 'list' }
|
||||
],
|
||||
}, {
|
||||
name: 'channel',
|
||||
@ -42,6 +43,8 @@ class SelfroleSetting extends Setting {
|
||||
if (!roles && !channel && !text) return { error: true, index: 'SETTING_MISSING_ARG' };
|
||||
const { guild } = invoker;
|
||||
|
||||
if (roles.value === 'list') return this.list(setting.roles, invoker, 'roles');
|
||||
|
||||
if (roles) {
|
||||
const response = await this._prompt(invoker, {
|
||||
index: `SETTING_PROMPT_${roles.value.toUpperCase()}`,
|
||||
|
@ -47,6 +47,8 @@ class Autorole extends Setting {
|
||||
const method = opts.roles?.value;
|
||||
if (typeof enabled === 'boolean') setting.enabled = enabled;
|
||||
|
||||
if (method === 'list') return this.list(setting.roles, interaction, 'roles');
|
||||
|
||||
if (method) {
|
||||
const { guild } = interaction;
|
||||
const time = 120;
|
||||
|
@ -244,6 +244,49 @@ class Setting extends Component {
|
||||
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
|
||||
/**
|
||||
* Abstract components method, should be overridden by the implementing class and called, returns the select menu component.
|
||||
|
Loading…
Reference in New Issue
Block a user