diff --git a/bot/src/bot/db.ts b/bot/src/bot/db.ts index 723b983..63cc69c 100644 --- a/bot/src/bot/db.ts +++ b/bot/src/bot/db.ts @@ -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 } diff --git a/bridge/src/discord/events.ts b/bridge/src/discord/events.ts index e6f5fc4..37fe456 100644 --- a/bridge/src/discord/events.ts +++ b/bridge/src/discord/events.ts @@ -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; } diff --git a/lib/src/misc/bridge_config_keys.ts b/lib/src/misc/bridge_config_keys.ts index 0afec86..1d6f0dd 100644 --- a/lib/src/misc/bridge_config_keys.ts +++ b/lib/src/misc/bridge_config_keys.ts @@ -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.", + }, }; diff --git a/lib/src/types/BridgeConfig.ts b/lib/src/types/BridgeConfig.ts index 83ec1f6..e49433a 100644 --- a/lib/src/types/BridgeConfig.ts +++ b/lib/src/types/BridgeConfig.ts @@ -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; }