From 9d035c4e2b6cee37e57d72163f1880c78b150b56 Mon Sep 17 00:00:00 2001 From: janderedev Date: Sat, 30 Apr 2022 16:17:46 +0200 Subject: [PATCH] port bridge to revolt.js 6.0 --- bridge/package.json | 2 +- bridge/src/discord/events.ts | 9 ++++--- bridge/src/revolt/client.ts | 6 +++-- bridge/src/revolt/events.ts | 2 +- bridge/yarn.lock | 48 +++++++++++++++++++++++++----------- docker-compose.yml.example | 2 +- 6 files changed, 47 insertions(+), 22 deletions(-) diff --git a/bridge/package.json b/bridge/package.json index 99aa2a6..e6a54a9 100644 --- a/bridge/package.json +++ b/bridge/package.json @@ -14,7 +14,7 @@ "license": "ISC", "dependencies": { "@discordjs/rest": "^0.4.1", - "@janderedev/revolt.js": "^5.2.8-patch.2", + "@janderedev/revolt.js": "^6.0.0-rc.21", "axios": "^0.26.1", "discord-api-types": "^0.31.2", "discord.js": "^13.6.0", diff --git a/bridge/src/discord/events.ts b/bridge/src/discord/events.ts index 20760e3..e46854e 100644 --- a/bridge/src/discord/events.ts +++ b/bridge/src/discord/events.ts @@ -1,7 +1,6 @@ import { BRIDGED_MESSAGES, BRIDGE_CONFIG, logger } from ".."; import { client } from "./client"; import { AUTUMN_URL, client as revoltClient } from "../revolt/client"; -import { ChannelPermission } from "@janderedev/revolt.js"; import axios from 'axios'; import { ulid } from "ulid"; import GenericEmbed from "../types/GenericEmbed"; @@ -84,11 +83,15 @@ client.on('messageCreate', async message => { const channel = revoltClient.channels.get(bridgeCfg.revolt); if (!channel) return logger.debug(`Discord: Cannot find associated channel`); - if (!(channel.permission & ChannelPermission.SendMessage)) { + if (!(channel.havePermission('SendMessage'))) { return logger.debug(`Discord: Lacking SendMessage permission; refusing to send`); } - if (!(channel.permission & ChannelPermission.Masquerade)) { + if (!(channel.havePermission('SendEmbeds'))) { + return logger.debug(`Discord: Lacking SendEmbeds permission; refusing to send`); + } + + if (!(channel.havePermission('Masquerade'))) { return logger.debug(`Discord: Lacking Masquerade permission; refusing to send`); } diff --git a/bridge/src/revolt/client.ts b/bridge/src/revolt/client.ts index 7ee2d81..f1a7402 100644 --- a/bridge/src/revolt/client.ts +++ b/bridge/src/revolt/client.ts @@ -4,13 +4,15 @@ import { logger } from '..'; let AUTUMN_URL = `http://autumnUrl`; -const client = new Client({ }); +const client = new Client({ + apiURL: process.env.REVOLT_API_URL, +}); const login = () => new Promise((resolve: (value: Client) => void) => { client.loginBot(process.env['REVOLT_TOKEN']!); client.once('ready', async () => { logger.info(`Revolt: ${client.user?.username} ready - ${client.servers.size} servers`); - + const apiConfig = await axios.get(client.apiURL); AUTUMN_URL = apiConfig.data?.features?.autumn?.url; diff --git a/bridge/src/revolt/events.ts b/bridge/src/revolt/events.ts index 817b51e..5d30d99 100644 --- a/bridge/src/revolt/events.ts +++ b/bridge/src/revolt/events.ts @@ -43,7 +43,7 @@ client.on('message/delete', async id => { }); client.on('message/update', async message => { - if (message.content && typeof message.content != 'string') return; + if (!message.content || typeof message.content != 'string') return; if (message.author_id == client.user?._id) return; try { diff --git a/bridge/yarn.lock b/bridge/yarn.lock index 857076e..fb130f2 100644 --- a/bridge/yarn.lock +++ b/bridge/yarn.lock @@ -37,10 +37,10 @@ node-fetch "^2.6.7" tslib "^2.3.1" -"@insertish/exponential-backoff@3.1.0-patch.0": - version "3.1.0-patch.0" - resolved "https://registry.yarnpkg.com/@insertish/exponential-backoff/-/exponential-backoff-3.1.0-patch.0.tgz#1fff134f70fc0906d11d09069d51183b542e42cf" - integrity sha512-1qhW81s3GDbssyaxRWdpBAn1cIw5s393HnrdYFjfa2i6rq3SEjQDK6U80g6dq/K0or6JRr2eCn75Wfc1IrGM0g== +"@insertish/exponential-backoff@3.1.0-patch.2": + version "3.1.0-patch.2" + resolved "https://registry.yarnpkg.com/@insertish/exponential-backoff/-/exponential-backoff-3.1.0-patch.2.tgz#08310c856b795c783a832f3f608c0feaff262c0d" + integrity sha512-0lsMVexkZ7dHpQlPrTZDRsm42hZ4/CzKxP1hbAEJH8IaEwrIEhhTKJuFxPuLOi2TwPImuocncjYHpGpwVNOemQ== "@insertish/isomorphic-ws@^4.0.1": version "4.0.1" @@ -57,20 +57,31 @@ axios "^0.26.1" openapi-typescript "^5.2.0" -"@janderedev/revolt.js@^5.2.8-patch.2": - version "5.2.8-patch.2" - resolved "https://registry.yarnpkg.com/@janderedev/revolt.js/-/revolt.js-5.2.8-patch.2.tgz#d74a6500e217a4cb94d139027dec2acb71f73a0f" - integrity sha512-2nucMuToKC5F4jsajmTauBaV9Q7oyl1KWKF0ysYYPzEKxK9LfPL560v9bQR/ff1g8GkEv4biAN/A17MCcddAuw== +"@insertish/oapi@0.1.15": + version "0.1.15" + resolved "https://registry.yarnpkg.com/@insertish/oapi/-/oapi-0.1.15.tgz#ee58b82d879ed5af54db846699941b8ad0262e7b" + integrity sha512-2G8eFxrojF651tBoRutQ8CJOw0u8UjYSlw/LQU+xycw5KpXslhWp/KSR86uIFyDIPddwfMCNA91vwHGCFRA63w== dependencies: - "@insertish/exponential-backoff" "3.1.0-patch.0" + typescript "^4.6.2" + optionalDependencies: + axios "^0.26.1" + openapi-typescript "^5.2.0" + +"@janderedev/revolt.js@^6.0.0-rc.21": + version "6.0.0-rc.21" + resolved "https://registry.yarnpkg.com/@janderedev/revolt.js/-/revolt.js-6.0.0-rc.21.tgz#0629700cd78d0f7db5f4707dc7a8f5ba67482e1a" + integrity sha512-uLFXrv6ZjLJ+e9keevv0sUeZY8gDw3RfSg07LNYVUfqi1T64WwmZypz3zc2kTacbfthIgI368K2e6f3q4toc4Q== + dependencies: + "@insertish/exponential-backoff" "3.1.0-patch.2" "@insertish/isomorphic-ws" "^4.0.1" axios "^0.21.4" eventemitter3 "^4.0.7" lodash.defaultsdeep "^4.6.1" lodash.flatten "^4.4.0" lodash.isequal "^4.5.0" + long "^5.2.0" mobx "^6.3.2" - revolt-api "0.5.3-alpha.12" + revolt-api "0.5.3-rc.15" ulid "^2.3.0" ws "^8.2.2" @@ -337,6 +348,11 @@ log75@^2.2.0: dependencies: ansi-colors "^4.1.1" +long@^5.2.0: + version "5.2.0" + resolved "https://registry.yarnpkg.com/long/-/long-5.2.0.tgz#2696dadf4b4da2ce3f6f6b89186085d94d52fd61" + integrity sha512-9RTUNjK60eJbx3uz+TEGF7fUr29ZDxR5QzXcyDpeSfeH28S9ycINflOgOlppit5U+4kNTe83KQnMEerw7GmE8w== + memory-pager@^1.0.2: version "1.5.0" resolved "https://registry.yarnpkg.com/memory-pager/-/memory-pager-1.5.0.tgz#d8751655d22d384682741c972f2c3d6dfa3e66b5" @@ -494,10 +510,14 @@ require-at@^1.0.6: resolved "https://registry.yarnpkg.com/require-at/-/require-at-1.0.6.tgz#9eb7e3c5e00727f5a4744070a7f560d4de4f6e6a" integrity sha512-7i1auJbMUrXEAZCOQ0VNJgmcT2VOKPRl2YGJwgpHpC9CE91Mv4/4UYIUm4chGJaI381ZDq1JUicFii64Hapd8g== -revolt-api@0.5.3-alpha.12: - version "0.5.3-alpha.12" - resolved "https://registry.yarnpkg.com/revolt-api/-/revolt-api-0.5.3-alpha.12.tgz#78f25b567b840c1fd072595526592a422cb01f25" - integrity sha512-MM42oI5+5JJMnAs3JiOwSQOy/SUYzYs3M8YRC5QI4G6HU7CfyB2HNWh5jFsyRlcLdSi13dGazHm31FUPHsxOzw== +revolt-api@0.5.3-rc.15: + version "0.5.3-rc.15" + resolved "https://registry.yarnpkg.com/revolt-api/-/revolt-api-0.5.3-rc.15.tgz#abd08dd8109d0ca31be118461eabbeb6c3b7792e" + integrity sha512-MYin3U+KoObNkILPf2cz+FPperynExkUu7CjzurMJCRvBncpnhb2czvWDvnhLDKBHlpo8W597xNqzQnaklV4ug== + dependencies: + "@insertish/oapi" "0.1.15" + axios "^0.26.1" + lodash.defaultsdeep "^4.6.1" revolt-api@^0.5.3-rc.8: version "0.5.3-rc.8" diff --git a/docker-compose.yml.example b/docker-compose.yml.example index 2f6b878..cea776c 100644 --- a/docker-compose.yml.example +++ b/docker-compose.yml.example @@ -54,7 +54,7 @@ services: - DB_STRING=mongodb://mogus:${DB_PASS}@mongo:27017/admin - NODE_ENV=production - BRIDGE_METRICS_PORT - - API_URL + - REVOLT_API_URL=${API_URL} # Uncomment if you enabled Prometheus metrics #ports: # - 127.0.0.1:${BRIDGE_METRICS_PORT}:${BRIDGE_METRICS_PORT}