Future-proof permissions

This commit is contained in:
Cadence Ember
2025-12-05 17:13:56 +13:00
parent 33ec4a9bea
commit 261bb1b8c8
4 changed files with 14 additions and 5 deletions

View File

@@ -1,12 +1,20 @@
#!/usr/bin/env node
// @ts-check
const DiscordTypes = require("discord-api-types/v10")
const {reg} = require("./src/matrix/read-registration")
const token = reg.ooye.discord_token
const id = Buffer.from(token.split(".")[0], "base64").toString()
const permissions =
( DiscordTypes.PermissionFlagsBits.ManageWebhooks
| DiscordTypes.PermissionFlagsBits.ManageGuildExpressions
| DiscordTypes.PermissionFlagsBits.ManageMessages
| DiscordTypes.PermissionFlagsBits.PinMessages
| DiscordTypes.PermissionFlagsBits.UseExternalEmojis)
function addbot() {
return `Open this link to add the bot to a Discord server:\nhttps://discord.com/oauth2/authorize?client_id=${id}&scope=bot&permissions=1610883072 `
return `Open this link to add the bot to a Discord server:\nhttps://discord.com/oauth2/authorize?client_id=${id}&scope=bot&permissions=${permissions} `
}
/* c8 ignore next 3 */
@@ -16,3 +24,4 @@ if (process.argv.find(a => a.endsWith("addbot") || a.endsWith("addbot.js"))) {
module.exports.id = id
module.exports.addbot = addbot
module.exports.permissions = permissions

View File

@@ -161,7 +161,7 @@ const errorRetrySema = new Semaphore()
*/
async function onRetryReactionAdd(reactionEvent) {
const roomID = reactionEvent.room_id
errorRetrySema.request(async () => {
await errorRetrySema.request(async () => {
const event = await api.getEvent(roomID, reactionEvent.content["m.relates_to"]?.event_id)
// Check that it's a real error from OOYE

View File

@@ -8,7 +8,7 @@ const DiscordTypes = require("discord-api-types/v10")
const getRelativePath = require("get-relative-path")
const {discord, as, db, sync} = require("../../passthrough")
const {id} = require("../../../addbot")
const {id, permissions} = require("../../../addbot")
/** @type {import("../auth")} */
const auth = sync.require("../auth")
const {reg} = require("../../matrix/read-registration")
@@ -51,7 +51,7 @@ as.router.get("/oauth", defineEventHandler(async event => {
async function tryAgain() {
const newState = randomUUID()
await session.update({state: newState})
return sendRedirect(event, `https://discord.com/oauth2/authorize?client_id=${id}&scope=${scope}&permissions=1610883072&response_type=code&redirect_uri=${redirect_uri}&state=${newState}`)
return sendRedirect(event, `https://discord.com/oauth2/authorize?client_id=${id}&scope=${scope}&permissions=${permissions}&response_type=code&redirect_uri=${redirect_uri}&state=${newState}`)
}
const parsedQuery = await getValidatedQuery(event, schema.code.safeParse)

View File

@@ -4,5 +4,5 @@ const {addbot} = require("../addbot")
const {test} = require("supertape")
test("addbot: returns message and invite link", t => {
t.equal(addbot(), `Open this link to add the bot to a Discord server:\nhttps://discord.com/oauth2/authorize?client_id=684280192553844747&scope=bot&permissions=1610883072 `)
t.equal(addbot(), `Open this link to add the bot to a Discord server:\nhttps://discord.com/oauth2/authorize?client_id=684280192553844747&scope=bot&permissions=2251801424568320 `)
})