further refactor resolveMethod
This commit is contained in:
parent
128633eac2
commit
553c84379e
@ -43,7 +43,7 @@ class IgnoreSetting extends Setting {
|
||||
const setting = message.guild._settings[this.index];
|
||||
const { guild } = message;
|
||||
const { resolver } = this.client;
|
||||
const response = await resolver.resolveMethod(params, null, setting.channels, { resolver: resolver.resolveChannels.bind(resolver), guild });
|
||||
const response = await resolver.resolveMethod(params, { existing: setting.channels, resolver: resolver.resolveChannels.bind(resolver), guild });
|
||||
|
||||
if (!response) method = params.shift();
|
||||
else ({ method } = response);
|
||||
@ -93,7 +93,7 @@ class IgnoreSetting extends Setting {
|
||||
|
||||
} else if (method === 'bypass') {
|
||||
|
||||
const response = await resolver.resolveMethod(params, null, setting.roleBypass, { resolver: resolver.resolveRoles.bind(resolver), guild });
|
||||
const response = await resolver.resolveMethod(params, { existing: setting.roleBypass, resolver: resolver.resolveRoles.bind(resolver), guild });
|
||||
|
||||
if (response.method === 'add') {
|
||||
|
||||
|
@ -65,7 +65,7 @@ module.exports = class LinkFilter extends FilterSetting {
|
||||
|
||||
} else if (['blacklist', 'whitelist'].includes(method)) {
|
||||
|
||||
const result = await resolver.resolveMethod(args, null, null, {
|
||||
const result = await resolver.resolveMethod(args, {
|
||||
allowedMethods: ['add', 'remove', 'set', 'reset'],
|
||||
resolver: resolver.resolveDomains.bind(resolver)
|
||||
});
|
||||
@ -117,7 +117,7 @@ module.exports = class LinkFilter extends FilterSetting {
|
||||
let msg = message.format(index, langParams);
|
||||
if (existsInOpposite.length) msg += '\n\n' + message.format('S_LINKFILTER_OPPOSITE', { opposite: existsInOpposite.join('`, `'), op: _opposite });
|
||||
if (skipped.length) msg += '\n\n' + message.format('S_LINKFILTER_SKIPPED', { skipped: skipped.join('`, `') });
|
||||
if (result.failed.length) msg += '\n\n' + message.format('S_LINKFILTER_FAILED', { failed: result.failed.join('`, `') });
|
||||
if (result.failed?.length) msg += '\n\n' + message.format('S_LINKFILTER_FAILED', { failed: result.failed.join('`, `') });
|
||||
|
||||
await message.guild._updateSettings({ [this.index]: setting });
|
||||
return {
|
||||
@ -127,7 +127,8 @@ module.exports = class LinkFilter extends FilterSetting {
|
||||
|
||||
} else if (['ignore', 'channelignore', 'ignorechannel'].includes(method)) {
|
||||
|
||||
const resolved = await resolver.resolveMethod(args, null, setting.ignore, {
|
||||
const resolved = await resolver.resolveMethod(args, {
|
||||
existing: setting.ignore,
|
||||
resolver: resolver.resolveChannels.bind(resolver),
|
||||
guild,
|
||||
allowedMethods: ['add', 'remove', 'set', 'reset']
|
||||
@ -142,7 +143,8 @@ module.exports = class LinkFilter extends FilterSetting {
|
||||
|
||||
} else if (['bypass', 'roleignore', 'ignorerole'].includes(method)) {
|
||||
|
||||
const resolved = await resolver.resolveMethod(args, null, setting.bypass, {
|
||||
const resolved = await resolver.resolveMethod(args, {
|
||||
existing: setting.bypass,
|
||||
resolver: resolver.resolveRoles.bind(resolver),
|
||||
guild,
|
||||
allowedMethods: ['add', 'remove', 'set', 'reset']
|
||||
@ -182,7 +184,7 @@ module.exports = class LinkFilter extends FilterSetting {
|
||||
} else if (['action', 'actions'].includes(method)) {
|
||||
|
||||
const submethod = args.shift().toLowerCase();
|
||||
const resolved = await resolver.resolveMethod([submethod], null, null, {
|
||||
const resolved = await resolver.resolveMethod([submethod], {
|
||||
allowedMethods: ['add', 'remove', 'edit', 'list', 'reset']
|
||||
});
|
||||
if (!resolved) return { error: true, msg: message.format('ERR_INVALID_METHOD', { method: submethod }) };
|
||||
|
@ -55,7 +55,7 @@ class MessageLogsSetting extends Setting {
|
||||
msg: message.format('MISSING_ARGS'),
|
||||
error: true
|
||||
};
|
||||
const response = await this.resolveMethod(args, undefined, setting.ignoredRoles, { resolver: guild.resolveRoles.bind(guild) });
|
||||
const response = await this.resolveMethod(args, { existing: setting.ignoredRoles, resolver: guild.resolveRoles.bind(guild) });
|
||||
|
||||
if (response) {
|
||||
|
||||
@ -102,7 +102,7 @@ class MessageLogsSetting extends Setting {
|
||||
msg: message.format('MISSING_ARGS'),
|
||||
error: true
|
||||
};
|
||||
const response = await this.resolveMethod(args, null, setting.ignoredChannels, { resolver: guild.resolveChannels.bind(guild) });
|
||||
const response = await this.resolveMethod(args, { existing: setting.ignoredChannels, resolver: guild.resolveChannels.bind(guild) });
|
||||
|
||||
if (response) {
|
||||
|
||||
@ -143,7 +143,7 @@ class MessageLogsSetting extends Setting {
|
||||
|
||||
} else if (['attachments', 'images', 'attachment', 'image'].includes(method)) {
|
||||
|
||||
if (guild.premium < 2) return {
|
||||
if (guild.premium < 2 && !message.author.developer) return {
|
||||
msg: message.format('PREMIUM_REQUIRED', { required: 2, tier: guild.premium }),
|
||||
error: true
|
||||
};
|
||||
@ -242,8 +242,8 @@ class MessageLogsSetting extends Setting {
|
||||
|
||||
async fields(guild) {
|
||||
const setting = guild._settings[this.index];
|
||||
const roles = setting?.ignoredRoles ? await Promise.all(setting.ignoredRoles.map(async (role) => await guild.resolveRole(role))) : undefined;
|
||||
const channels = setting?.ignoredChannels ? await Promise.all(setting.ignoredChannels.map(async (c) => await guild.resolveChannel(c))) : undefined;
|
||||
const roles = setting?.ignoredRoles ? await Promise.all(setting.ignoredRoles.map(async (role) => guild.resolveRole(role))) : undefined;
|
||||
const channels = setting?.ignoredChannels ? await Promise.all(setting.ignoredChannels.map(async (c) => guild.resolveChannel(c))) : undefined;
|
||||
return [
|
||||
{
|
||||
name: '》 Status',
|
||||
|
@ -88,7 +88,7 @@ class ModerationPointsSetting extends Setting {
|
||||
|
||||
} else if (method === 'associate') {
|
||||
|
||||
const { method: submethod, changed } = await resolver.resolveMethod(params, null, Object.keys(setting.associations));
|
||||
const { method: submethod, changed } = await resolver.resolveMethod(params, { existing: Object.keys(setting.associations) });
|
||||
|
||||
if (submethod === 'reset') {
|
||||
setting.associations = {};
|
||||
|
@ -52,7 +52,7 @@ class ProtectionSetting extends Setting {
|
||||
|
||||
} else {
|
||||
|
||||
const response = await resolver.resolveMethod(params, null, setting.roles, { resolver: resolver.resolveRoles.bind(resolver), guild });
|
||||
const response = await resolver.resolveMethod(params, { existing: setting.roles, resolver: resolver.resolveRoles.bind(resolver), guild });
|
||||
if (!response) return { error: true, msg: message.format('ERR_INVALID_METHOD', { method }) };
|
||||
({ method } = response);
|
||||
if (method !== 'list' && !response.resolved.length) return { error: true, msg: message.format('ERR_ROLERESOLVE') };
|
||||
|
@ -33,13 +33,14 @@ class AutoroleSetting extends Setting {
|
||||
const setting = message.guild._settings[this.index];
|
||||
const { guild } = message;
|
||||
const { resolver } = this.client;
|
||||
const response = await resolver.resolveMethod(params, null, setting.roles, {
|
||||
const response = await resolver.resolveMethod(params, {
|
||||
existing: setting.roles,
|
||||
resolver: resolver.resolveRoles.bind(resolver),
|
||||
guild
|
||||
});
|
||||
|
||||
let index = null,
|
||||
langParams = {};
|
||||
let index = null;
|
||||
const langParams = {};
|
||||
|
||||
if (!response) return {
|
||||
error: true,
|
||||
|
@ -37,7 +37,8 @@ class StickyRoleSetting extends Setting {
|
||||
const langParams = {};
|
||||
let index = null;
|
||||
|
||||
const response = await resolver.resolveMethod(params, null, setting.roles, {
|
||||
const response = await resolver.resolveMethod(params, {
|
||||
existing: setting.roles,
|
||||
resolver: resolver.resolveRoles.bind(resolver),
|
||||
guild
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user