incomplete stuff, pushing so I can work remotely

This commit is contained in:
Erik 2020-09-18 03:30:50 +03:00
parent c2df48ba6f
commit f450ccac38
3 changed files with 203 additions and 1 deletions

View File

@ -22,7 +22,7 @@ class AutoModerationSetting extends Setting {
],
default: {
autoModeration: {
enabled: true,
enabled: false,
thresholds: {
},

View File

@ -0,0 +1,43 @@
const { Setting } = require('../../../../interfaces/');
module.exports = class LinkFilter extends Setting {
constructor(client) {
super(client, {
name: 'linkFilter',
module: 'moderation',
aliases: [],
resolve: 'GUILD',
usage: '<option> <method> <value..>',
examples: [
'linkfilter on',
'linkfilter reset',
'linkfilter mode <blacklist|whitelist>',
'linkfilter blacklist <add|set|clear|remove> word "a phrase with several words"',
'linkfilter whitelist <add|set|clear|remove> word "a phrase with several words"',
'linkfilter bypass <add|set|clear|remove> role "role with several words in name"',
'linkfilter ignore <add|set|clear|remove> #channel channel-name',
'linkfilter silent on',
'linkfilter actions word mute 5 min 1 point' // time reg: (\d{1,3}\s?[a-z]{1,7} ?){1,2} | points reg: \d{1,3}\s?(points?|pts?|p) -- parse points first
],
default: {
linkFilter: {
enabled: false,
silent: false,
blacklist: [],
whitelist: [],
actions: { // Link certain words to actions with or without points ex fuck: { action: 'MUTE', points: null, force: false, duration: 300 }
}
}
}
});
}
fields(guild) {
return [];
}
};

View File

@ -0,0 +1,159 @@
const { Setting } = require('../../../../interfaces/');
module.exports = class WordFilter extends Setting {
constructor(client) {
super(client, {
name: 'wordFilter',
module: 'moderation',
aliases: [],
resolve: 'GUILD',
usage: '<option> <method> <value..>',
examples: [
'wordfilter on',
'wordfilter reset',
'wordfilter explicit <add|set|clear|remove> word "a phrase"',
'wordfilter fuzzy <add|set|clear|remove> word "a phrase"',
'wordfilter tokenized <add|set|clear|remove> partOfAword',
'wordfilter whitelist <add|set|clear|remove> word "a phrase"',
'wordfilter bypass <add|set|clear|remove> role "rolename with several words"',
'wordfilter ignore <add|set|clear|remove> #channel channel-name',
'wordfilter silent on',
'wordfilter actions word mute 5 min 1 point' // time reg: (\d{1,3}\s?[a-z]{1,7} ?){1,2} | points reg: \d{1,3}\s?(points?|pts?|p) -- parse points first
],
default: {
wordFilter: {
enabled: false,
silent: false,
explicit: [],
fuzzy: [],
tokenized: [],
whitelist: [],
actions: { // Link certain words to actions with or without points ex fuck: { action: 'MUTE', points: null, force: false, duration: 300 }
fuck: {
action: 'MUTE',
points: 10,
force: true,
duration: 300
}
},
ignore: [],
bypass: []
}
}
});
}
async handle(message, params) {
const [_method, ...args] = params;
let method = _method.toLowerCase();
const { resolver } = this.client;
const { guild } = message;
const setting = guild._settings[this.index];
let index = null, langParams = {};
const bool = resolver.resolveBoolean(method);
console.log(message.content)
console.log(message._clean)
console.log(args)
if (bool || bool === false) {
index = 'S_WORDFILTER_TOGGLE';
langParams.toggle = message.format('ON_OFF_TOGGLE', { toggle: bool }, true);
setting.enabled = bool;
} else if (['explicit', 'fuzzy', 'tokenized', 'token', 'whitelist'].includes(method)) {
if (method === 'token') method = 'tokenized';
const resolved = await resolver.resolveMethod(args, null, setting[method]);
if (!resolved || !['add', 'remove', 'set', 'reset'].includes(resolved.method)) return {
error: true,
msg: message.format('ERR_INVALID_METHOD', { method: resolved.method })
};
setting[method] = resolved.result || [];
index = 'S_WORDFILTER_' + method.toUpperCase() + '_' + resolved.method.toUpperCase();
langParams = { changed: resolved.changed.join('`, `') || '' };
} else if (['ignore', 'channelignore', 'ignorechannel'].includes(method)) {
} else if (['bypass', 'roleignore', 'ignorerole'].includes(method)) {
} else if (method === 'silent') {
} else if (['action', 'actions'].includes(method)) {
}
return {
error: false,
msg: message.format(index, langParams)
};
}
async fields(guild) {
const setting = guild._settings[this.index];
const { resolver } = this.client;
return [
{
name: "》 Status",
value: guild.format('SETTING_STATUS', { bool: Boolean(setting.enabled) }, true),
inline: true
},
{
name: '》 Silent',
value: guild.format('SETTING_STATUS', { bool: Boolean(setting.silent) }, true),
inline: true
},
{
name: '》 Explicit filter',
value: setting.explicit.join(', ') || '`N/A`',
inline: true
},
{
name: '》 Fuzzy filter',
value: setting.fuzzy.join(', ') || '`N/A`',
inline: true
},
{
name: '》 Tokenized filter',
value: setting.tokenized.join(', ') || '`N/A`',
inline: true
},
{
name: '》 Whitelist',
value: setting.whitelist.join(', ') || '`N/A`',
inline: true
},
{
name: '》 Ignored channels',
value: setting.ignore.map((channel) => `<#${channel.id}>`).join(', ') || '`N/A`',
inline: true
},
{
name: '》 Role bypass',
value: setting.bypass.map((role) => `<@&${role.id}>`).join(', ') || '`N/A`',
inline: true
},
{
name: '》 Actions',
value: Object.entries(setting.actions).reduce((acc, [key, val]) => {
let str = `\`${key}\`: **${val.action}**`;
if (val.points) str += ` (${val.points} points)`;
if (val.duration) str += ` for ${resolver.timeAgo(val.duration, true, true, true)}`;
if (val.force) str += ` - **FORCED**`;
acc.push(str);
return acc;
}, []).join('\n') || '`N/A`'
}
];
}
};