enable spam detection in servers in discovery

This commit is contained in:
Lea 2023-03-15 23:48:55 +01:00
parent 38d58069c8
commit 489f08b3b3
Signed by: Lea
GPG key ID: 1BAFFE8347019C42
4 changed files with 58 additions and 6 deletions

View file

@ -18,6 +18,10 @@ export default {
switch(action) {
case 'ignore_blacklist': {
if (args[0] == 'yes') {
if (message.serverContext.discoverable) {
return message.reply('Your server is currently listed in server discovery. As part of Revolt\'s [Discover Guidelines](<https://support.revolt.chat/kb/safety/discover-guidelines>), all servers on Discover are enrolled to AutoMod\'s antispam features.');
}
await dbs.SERVERS.update({ id: message.serverContext._id }, { $set: { allowBlacklistedUsers: true } });
await message.reply('Globally blacklisted users will no longer get banned in this server. Previously banned users will need to be unbanned manually.');
} else if (args[0] == 'no') {
@ -32,10 +36,14 @@ export default {
case 'spam_detection': {
if (args[0] == 'on') {
await dbs.SERVERS.update({ id: message.serverContext._id }, { $set: { antispamEnabled: true } });
await message.reply('Spam detection is now enabled in this server.\nIf a user wrongfully gets kicked '
await message.reply('Spam detection is now enabled in this server.\nIf a user is wrongfully kicked '
+ 'or banned, please report it here: https://rvlt.gg/jan\n\n'
+ 'Please make sure to grant AutoMod permission to **Kick**, **Ban** and **Manage Messages**!');
} else if (args[0] == 'off') {
if (message.serverContext.discoverable) {
return message.reply('Your server is currently listed in server discovery. As part of Revolt\'s [Discover Guidelines](<https://support.revolt.chat/kb/safety/discover-guidelines>), all servers on Discover are enrolled to AutoMod\'s antispam features.');
}
await dbs.SERVERS.update({ id: message.serverContext._id }, { $set: { antispamEnabled: false } });
await message.reply('Spam detection is now disabled in this server.');

View file

@ -1,12 +1,13 @@
import { Message } from "@janderedev/revolt.js/dist/maps/Messages";
import { ulid } from "ulid";
import { dbs } from "../..";
import { client, dbs } from "../..";
import AntispamRule from "automod/dist/types/antispam/AntispamRule";
import Infraction from "automod/dist/types/antispam/Infraction";
import InfractionType from "automod/dist/types/antispam/InfractionType";
import ModerationAction from "automod/dist/types/antispam/ModerationAction";
import logger from "../logger";
import { isModerator, storeInfraction } from "../util";
import { awaitClient, isModerator, storeInfraction } from "../util";
import { getDmChannel, sanitizeMessageContent } from "../util";
let msgCountStore: Map<string, { users: any }> = new Map();
@ -105,4 +106,46 @@ function getWarnMsg(rule: AntispamRule, message: Message) {
} else return `<@${message.author_id}>, please stop spamming.`;
}
// Scan all servers for the `discoverable` flag and notify their owners that antispam is forcefully enabled
const notifyPublicServers = async () => {
logger.info('Sending antispam notification to public servers');
const servers = Array.from(client.servers.values())
.filter(server => server.discoverable);
const res = await dbs.SERVERS.find({
id: { $in: servers.map(s => s._id) },
discoverAutospamNotify: { $in: [ undefined, false ] },
});
res.forEach(async (serverConfig) => {
try {
logger.info(`Sending notification to owner of server ${serverConfig._id}`);
const server = client.servers.get(serverConfig.id);
const channel = await getDmChannel(server!.owner);
await channel.sendMessage(`Hi there,
It looks like your server, **${sanitizeMessageContent(server!.name).trim()}**, has been added to server discovery. Congratulations!
In order to keep Revolt free of spam, AutoMod enables spam protection by default on public servers.
You are receiving this message to inform you that said features have been enabled automatically in your server.
Please ensure that AutoMod has appropriate permissions to kick and ban users.
You may also want to set up a logging channel by running \`/botctl logs modaction #yourchannel\` to receive details about antispam events if you haven't done so already.
Thanks for being part of Revolt!`);
await dbs.SERVERS.update(
{ id: serverConfig.id },
{ $set: { discoverAutospamNotify: true, antispamEnabled: true, allowBlacklistedUsers: false } },
);
} catch(e) {
console.error(e);
}
});
}
awaitClient().then(() => notifyPublicServers());
export { antispam }

View file

@ -60,8 +60,8 @@ __metadata:
linkType: hard
"@janderedev/revolt.js@npm:latest":
version: 6.0.20-patch.7
resolution: "@janderedev/revolt.js@npm:6.0.20-patch.7"
version: 6.0.20-patch.8
resolution: "@janderedev/revolt.js@npm:6.0.20-patch.8"
dependencies:
"@insertish/exponential-backoff": 3.1.0-patch.2
"@insertish/isomorphic-ws": ^4.0.1
@ -75,7 +75,7 @@ __metadata:
revolt-api: 0.5.16
ulid: ^2.3.0
ws: ^8.2.2
checksum: 3917cb81acc5fd9ab2df2f63fff7e7074c7bb3e94c93ca4d6cf709657d083d824e751abaadf81f9e0fbb669cf4cb84400108c57cd7a4390f5e120a045342479c
checksum: 104c8e1a10adb485fcec58056c596e16195ea920dba75632c6533683fb3bf4dfc9df150cb6bf84b2a7231b9db1ef7b8a595763b5bdc4b226b3d6059c2e2e5ec9
languageName: node
linkType: hard

View file

@ -29,6 +29,7 @@ class ServerConfig {
dmOnKick?: boolean; // Whether users should receive a DM when kicked/banned. Default false
dmOnWarn?: boolean; // Whether users should receive a DM when warned. Default false
contact?: string; // How to contact the server staff. Sent on kick/ban/warn DMs. http(s)/mailto link or normal text.
discoverAutospamNotify?: boolean; // Whether we have notified the server owner that antispam is enabled for servers on discover.
}
export default ServerConfig;