add disallow_opt_out configuration option

This commit is contained in:
Jan 2022-11-07 21:59:15 +01:00
parent 603d922a33
commit 6d5b91d07f
No known key found for this signature in database
GPG key ID: 5D5E18ACB990F57A
4 changed files with 36 additions and 17 deletions

View file

@ -30,6 +30,7 @@ function getDBUrl() {
}
async function databaseMigrations() {
// prettier-ignore
async function setIndexes(collection: ICollection, toIndex: string[]) {
try {
const indexes = await collection.indexes();
@ -44,21 +45,32 @@ async function databaseMigrations() {
}
}
await setIndexes(dbs.BRIDGE_CONFIG, [ 'discord', 'revolt' ]);
await setIndexes(dbs.BRIDGE_REQUESTS, [ 'id', 'revolt' ]);
await setIndexes(dbs.BRIDGE_CONFIG, ["discord", "revolt"]);
await setIndexes(dbs.BRIDGE_REQUESTS, ["id", "revolt"]);
await setIndexes(dbs.BRIDGED_MESSAGES, [
"discord.messageId",
"revolt.messageId",
"revolt.nonce",
"origin",
]);
await setIndexes(dbs.INFRACTIONS, [ 'createdBy', 'user', 'server' ]);
await setIndexes(dbs.PENDING_LOGINS, [ 'code', 'user' ]);
await setIndexes(dbs.SERVERS, [ 'id' ]);
await setIndexes(dbs.SESSIONS, [ 'user', 'token' ]);
await setIndexes(dbs.TEMPBANS, [ 'id', 'until' ]);
await setIndexes(dbs.USERS, [ 'id' ]);
await setIndexes(dbs.VOTEKICKS, [ 'id', 'server', 'target' ]);
await setIndexes(dbs.INFRACTIONS, ["createdBy", "user", "server"]);
await setIndexes(dbs.PENDING_LOGINS, ["code", "user"]);
await setIndexes(dbs.SERVERS, ["id"]);
await setIndexes(dbs.SESSIONS, ["user", "token"]);
await setIndexes(dbs.TEMPBANS, ["id", "until"]);
await setIndexes(dbs.USERS, ["id"]);
await setIndexes(dbs.VOTEKICKS, ["id", "server", "target"]);
// Migrate `disallowIfOptedOut` to `config.disallow_opt_out` on bridge_config
await dbs.BRIDGE_CONFIG.update(
{
disallowIfOptedOut: { $exists: true },
"config.disallow_opt_out": { $exists: false },
},
{
$rename: { disallowIfOptedOut: "config.disallow_opt_out" },
}
);
}
export { databaseMigrations }

View file

@ -101,7 +101,11 @@ client.on('messageCreate', async message => {
}
}
if (bridgeCfg.disallowIfOptedOut && userConfig?.optOut && message.deletable) {
if (
bridgeCfg.config?.disallow_opt_out &&
userConfig?.optOut &&
message.deletable
) {
await message.delete();
return;
}

View file

@ -4,10 +4,10 @@ export const CONFIG_KEYS = {
description:
"If enabled, nicknames and avatar overrides will be bridged.",
},
// disallow_opt_out: {
// friendlyName: "Disallow users who opted out of message bridging",
// description:
// "If enabled, all messages by users who opted out of their messages being bridged (`/bridge opt_out`) will be deleted. " +
// "You should enable this if your Revolt server is bridged to a mostly unmoderated Discord server.",
// },
disallow_opt_out: {
friendlyName: "Disallow users who opted out of message bridging",
description:
"If enabled, all messages by users who opted out of their messages being bridged (`/bridge opt_out`) will be deleted. " +
"You should enable this if your Revolt server is bridged to a mostly unmoderated Discord server.",
},
};

View file

@ -15,6 +15,9 @@ export default class {
config?: { [key in keyof typeof CONFIG_KEYS]: boolean | undefined };
// If true, messages by users who have opted out of bridging will be deleted.
/**
* @deprecated Use config.disallow_opt_out
* Will be automatically removed by database migrations
*/
disallowIfOptedOut?: boolean;
}