2021-06-23 10:51:34 +02:00
|
|
|
const { FilterSetting } = require('../../../../interfaces/');
|
2020-11-11 23:58:13 +01:00
|
|
|
const { Util } = require('../../../../../util');
|
2021-06-23 10:51:34 +02:00
|
|
|
const emojis = {
|
|
|
|
WARN: '<:note:744490065354293258>',
|
|
|
|
MUTE: '<:muted:853709118988353556>',
|
|
|
|
KICK: '👢',
|
|
|
|
BAN: '🔨',
|
|
|
|
SOFTBAN: '🧹',
|
|
|
|
DELETE: '<:failure:723595130912637018>'
|
|
|
|
};
|
2020-11-11 23:58:13 +01:00
|
|
|
|
2021-06-23 10:51:34 +02:00
|
|
|
module.exports = class WordWatcher extends FilterSetting {
|
2020-11-11 23:58:13 +01:00
|
|
|
|
|
|
|
constructor(client) {
|
|
|
|
|
|
|
|
super(client, {
|
|
|
|
name: 'wordWatcher',
|
|
|
|
module: 'moderation',
|
|
|
|
aliases: [],
|
|
|
|
resolve: 'GUILD',
|
|
|
|
usage: '<option> <method> <value..>',
|
|
|
|
examples: [
|
2021-06-23 10:51:34 +02:00
|
|
|
'wordwatcher off'
|
2020-11-11 23:58:13 +01:00
|
|
|
],
|
|
|
|
default: {
|
|
|
|
wordWatcher: {
|
|
|
|
channel: null,
|
|
|
|
words: [],
|
|
|
|
ignore: [],
|
2021-06-23 10:51:34 +02:00
|
|
|
bypass: [],
|
|
|
|
actions: []
|
2020-11-11 23:58:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
async handle(message, params) {
|
|
|
|
|
|
|
|
const { resolver } = this.client;
|
|
|
|
const { guild } = message;
|
|
|
|
const setting = guild._settings[this.index];
|
|
|
|
|
2021-05-10 14:38:53 +02:00
|
|
|
let index = null,
|
|
|
|
langParams = {};
|
2020-11-11 23:58:13 +01:00
|
|
|
|
2021-06-23 10:51:34 +02:00
|
|
|
// eslint-disable-next-line prefer-const
|
|
|
|
let [first, ...rest] = params;
|
|
|
|
rest = rest.map((param) => Util.sanitiseRegex(param, ['?', '\\', '(', ')', '|', '\\[', '\\]', '.', '-']));
|
|
|
|
const result = await resolver.resolveMethod([first, ...rest], {
|
2020-11-11 23:58:13 +01:00
|
|
|
existing: setting.words,
|
|
|
|
allowedMethods: ['add', 'set', 'remove', 'reset', 'off']
|
|
|
|
});
|
2021-06-23 10:51:34 +02:00
|
|
|
const method = first.toLowerCase();
|
2020-11-11 23:58:13 +01:00
|
|
|
|
|
|
|
// if (method.on || method.off) return {
|
|
|
|
// error: true,
|
|
|
|
// msg: message.format('MISSING_ARGS')
|
|
|
|
// };
|
|
|
|
|
|
|
|
if (['off'].includes(result.method)) {
|
|
|
|
|
|
|
|
index = 'S_WORDWATCHER_TOGGLE';
|
|
|
|
langParams.toggle = message.format('ON_OFF_TOGGLE', { toggle: false }, true);
|
|
|
|
setting.channel = null;
|
|
|
|
|
|
|
|
} else if (['ignore', 'channels', 'channelignore'].includes(method)) {
|
|
|
|
|
2021-05-10 14:38:53 +02:00
|
|
|
langParams = await this._processChannelIgnore(params, setting, guild, 'S_WORDWATCHER_IGNORE_');
|
|
|
|
if (langParams.error) return langParams;
|
|
|
|
({ index } = langParams);
|
|
|
|
|
|
|
|
// result = await resolver.resolveMethod(params, {
|
|
|
|
// existing: setting.ignore,
|
|
|
|
// resolver: resolver.resolveChannels.bind(resolver),
|
|
|
|
// guild,
|
|
|
|
// allowedMethods: ['add', 'set', 'remove', 'reset']
|
|
|
|
// });
|
|
|
|
|
|
|
|
// if (!result) return {
|
|
|
|
// error: true,
|
|
|
|
// msg: message.format('ERR_INVALID_METHOD', {
|
|
|
|
// method
|
|
|
|
// })
|
|
|
|
// };
|
2020-11-11 23:58:13 +01:00
|
|
|
|
2021-05-10 14:38:53 +02:00
|
|
|
// index = `S_WORDWATCHER_IGNORE_${result.method.toUpperCase()}`;
|
|
|
|
// langParams.changes = result.resolved.map((res) => res.name).join('`, `');
|
2020-11-11 23:58:13 +01:00
|
|
|
|
|
|
|
} else if (['roles', 'roleignore', 'bypass'].includes(method)) {
|
|
|
|
|
2021-05-10 14:38:53 +02:00
|
|
|
langParams = await this._processRoleBypass(params, setting, guild, 'S_WORDWATCHER_BYPASS_');
|
|
|
|
if (langParams.error) return langParams;
|
|
|
|
({ index } = langParams);
|
|
|
|
|
|
|
|
// result = await resolver.resolveMethod(params, {
|
|
|
|
// existing: setting.bypass,
|
|
|
|
// resolver: resolver.resolveRoles.bind(resolver),
|
|
|
|
// guild,
|
|
|
|
// allowedMethods: ['add', 'set', 'remove', 'reset']
|
|
|
|
// });
|
|
|
|
|
|
|
|
// if (!result) return {
|
|
|
|
// error: true,
|
|
|
|
// msg: message.format('ERR_INVALID_METHOD', {
|
|
|
|
// method
|
|
|
|
// })
|
|
|
|
// };
|
|
|
|
|
|
|
|
// index = `S_WORDWATCHER_BYPASS_${result.method.toUpperCase()}`;
|
|
|
|
// langParams.changes = result.resolved.map((res) => res.name).join('`, `');
|
2020-11-11 23:58:13 +01:00
|
|
|
|
2021-06-23 10:51:34 +02:00
|
|
|
} else if (['action', 'actions'].includes(method)) {
|
|
|
|
|
|
|
|
params.shift();
|
|
|
|
langParams = await this._action(message, params, setting, { _wordWatcher: true });
|
|
|
|
({ index } = langParams);
|
|
|
|
|
2020-11-11 23:58:13 +01:00
|
|
|
} else if (result) {
|
|
|
|
|
|
|
|
setting.words = result.result;
|
2021-05-10 14:45:55 +02:00
|
|
|
index = result.changed.length || result.method === 'reset' ? `S_WORDWATCHER_${result.method.toUpperCase()}` : 'S_NO_CHANGE';
|
2020-11-11 23:58:13 +01:00
|
|
|
langParams.changes = result.changed.join('**, **');
|
2021-06-23 10:51:34 +02:00
|
|
|
|
2020-11-11 23:58:13 +01:00
|
|
|
} else {
|
|
|
|
|
2020-11-13 20:14:13 +01:00
|
|
|
const channel = await guild.resolveChannel(method);
|
2020-11-11 23:58:13 +01:00
|
|
|
if (!channel) return {
|
|
|
|
msg: message.format('ERR_CHANNEL_RESOLVE', { resolveable: method }),
|
|
|
|
error: true
|
|
|
|
};
|
|
|
|
if (channel.type !== 'text') return {
|
|
|
|
error: true,
|
|
|
|
msg: message.format('ERR_CHANNEL_TYPE', { type: channel.type })
|
|
|
|
};
|
|
|
|
|
|
|
|
const perms = channel.permissionsFor(guild.me);
|
|
|
|
const missingPerms = [];
|
|
|
|
if (!perms.has('SEND_MESSAGES')) missingPerms.push('SEND_MESSAGES');
|
|
|
|
if (!perms.has('VIEW_CHANNEL')) missingPerms.push('VIEW_CHANNEL');
|
|
|
|
|
|
|
|
if (missingPerms.length) return {
|
|
|
|
error: true,
|
|
|
|
msg: message.format('ERR_CHANNEL_PERMS', { channel: channel.name, perms: missingPerms.join(', ') })
|
|
|
|
};
|
|
|
|
|
|
|
|
index = 'S_WORDWATCHER_CHANNEL';
|
|
|
|
langParams.channel = channel.id;
|
|
|
|
setting.channel = channel.id;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-06-23 10:51:34 +02:00
|
|
|
if (langParams.error) return {
|
|
|
|
error: true,
|
|
|
|
msg: langParams.msg
|
|
|
|
};
|
|
|
|
|
2020-11-11 23:58:13 +01:00
|
|
|
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: '》 Status',
|
|
|
|
value: guild.format('SETTING_STATUS', { bool: Boolean(setting.channel) }, true),
|
|
|
|
inline: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: '》 Channel',
|
|
|
|
value: setting?.channel ? `<#${setting.channel}>` : '`N/A`',
|
|
|
|
inline: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: '\u200b',
|
|
|
|
value: '\u200b',
|
|
|
|
inline: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: '》 Ignored channels',
|
|
|
|
value: setting?.ignore.length ? setting.ignore.map((id) => `<#${id}>`) : '`N/A`',
|
|
|
|
inline: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: '》 Role bypass',
|
|
|
|
value: setting?.bypass.length ? setting.bypass.map((id) => `<@&${id}>`) : '`N/A`',
|
|
|
|
inline: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: '》 Words',
|
|
|
|
value: setting.words.join(', ') || '`N/A`',
|
|
|
|
inline: true
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-06-23 10:51:34 +02:00
|
|
|
async _createTrigger(message, action, actionObject, setting) {
|
|
|
|
|
|
|
|
const response = await message.prompt(message.format('S_WORDWATCHER_ACTION_ADD_TRIGGERS'), { time: 60 * 1000 });
|
|
|
|
if (!response && !response.content) {
|
|
|
|
if (setting.actions.find((ac) => ac.trigger === 'generic')) return {
|
|
|
|
error: true,
|
|
|
|
msg: message.format('S_FILTER_ACTIONS_EXISTING', { trigger: 'generic' })
|
|
|
|
};
|
|
|
|
setting.actions.push(actionObject);
|
|
|
|
actionObject.trigger = 'generic';
|
|
|
|
return actionObject;
|
|
|
|
}
|
|
|
|
if (['cancel', 'abort', 'exit'].includes(action.toLowerCase())) return {
|
|
|
|
error: true,
|
|
|
|
msg: message.format('ERR_CANCEL')
|
|
|
|
};
|
|
|
|
|
|
|
|
const emoji = await this.client.resolver.resolveEmoji(response.content, message.guild);
|
|
|
|
// WAITING FOR BUTTONS
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-11-11 23:58:13 +01:00
|
|
|
};
|