Future-proof permissions
This commit is contained in:
@@ -1,12 +1,20 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
// @ts-check
|
// @ts-check
|
||||||
|
|
||||||
|
const DiscordTypes = require("discord-api-types/v10")
|
||||||
|
|
||||||
const {reg} = require("./src/matrix/read-registration")
|
const {reg} = require("./src/matrix/read-registration")
|
||||||
const token = reg.ooye.discord_token
|
const token = reg.ooye.discord_token
|
||||||
const id = Buffer.from(token.split(".")[0], "base64").toString()
|
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() {
|
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 */
|
/* 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.id = id
|
||||||
module.exports.addbot = addbot
|
module.exports.addbot = addbot
|
||||||
|
module.exports.permissions = permissions
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ const errorRetrySema = new Semaphore()
|
|||||||
*/
|
*/
|
||||||
async function onRetryReactionAdd(reactionEvent) {
|
async function onRetryReactionAdd(reactionEvent) {
|
||||||
const roomID = reactionEvent.room_id
|
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)
|
const event = await api.getEvent(roomID, reactionEvent.content["m.relates_to"]?.event_id)
|
||||||
|
|
||||||
// Check that it's a real error from OOYE
|
// Check that it's a real error from OOYE
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ const DiscordTypes = require("discord-api-types/v10")
|
|||||||
const getRelativePath = require("get-relative-path")
|
const getRelativePath = require("get-relative-path")
|
||||||
|
|
||||||
const {discord, as, db, sync} = require("../../passthrough")
|
const {discord, as, db, sync} = require("../../passthrough")
|
||||||
const {id} = require("../../../addbot")
|
const {id, permissions} = require("../../../addbot")
|
||||||
/** @type {import("../auth")} */
|
/** @type {import("../auth")} */
|
||||||
const auth = sync.require("../auth")
|
const auth = sync.require("../auth")
|
||||||
const {reg} = require("../../matrix/read-registration")
|
const {reg} = require("../../matrix/read-registration")
|
||||||
@@ -51,7 +51,7 @@ as.router.get("/oauth", defineEventHandler(async event => {
|
|||||||
async function tryAgain() {
|
async function tryAgain() {
|
||||||
const newState = randomUUID()
|
const newState = randomUUID()
|
||||||
await session.update({state: newState})
|
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)
|
const parsedQuery = await getValidatedQuery(event, schema.code.safeParse)
|
||||||
|
|||||||
+1
-1
@@ -4,5 +4,5 @@ const {addbot} = require("../addbot")
|
|||||||
const {test} = require("supertape")
|
const {test} = require("supertape")
|
||||||
|
|
||||||
test("addbot: returns message and invite link", t => {
|
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 `)
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user