1
0
Fork 0

Add "addbot" feature

This commit is contained in:
Cadence Ember 2023-10-02 21:48:06 +13:00
parent 6d83df2e95
commit 708955c062
6 changed files with 40 additions and 1 deletions

15
addbot.js Normal file
View file

@ -0,0 +1,15 @@
// @ts-check
const config = require("./config")
function addbot() {
const token = config.discordToken
const id = Buffer.from(token.split(".")[0], "base64")
return `Open this link to add the bot to a Discord server:\nhttps://discord.com/oauth2/authorize?client_id=${id}&scope=bot&permissions=1610883072 `
}
if (process.argv.find(a => a.endsWith("addbot") || a.endsWith("addbot.js"))) {
console.log(addbot())
}
module.exports.addbot = addbot

3
addbot.sh Executable file
View file

@ -0,0 +1,3 @@
#!/usr/bin/env sh
echo "Open this link to add the bot to a Discord server:"
echo "https://discord.com/oauth2/authorize?client_id=$(grep discordToken config.js | sed -E 's!.*: ["'\'']([A-Za-z0-9+=/_-]*).*!\1!g' | base64 -d)&scope=bot&permissions=1610883072"

View file

@ -4,6 +4,7 @@ const assert = require("assert").strict
const util = require("util")
const DiscordTypes = require("discord-api-types/v10")
const reg = require("../matrix/read-registration")
const {addbot} = require("../addbot")
const {discord, sync, db, select} = require("../passthrough")
/** @type {import("../matrix/api")}) */
@ -201,6 +202,16 @@ const commands = [{
})
}
)
}, {
aliases: ["addbot"],
execute: replyctx(
async (message, channel, guild, ctx) => {
return discord.snow.channel.createMessage(channel.id, {
...ctx,
content: addbot()
})
}
)
}]
/** @type {CommandExecute} */

View file

@ -45,6 +45,7 @@
"tap-dot": "github:cloudrac3r/tap-dot#9dd7750ececeae3a96afba91905be812b6b2cc2d"
},
"scripts": {
"addbot": "node addbot.js",
"test": "cross-env FORCE_COLOR=true supertape --no-check-assertions-count --format tap test/test.js | tap-dot",
"test-slow": "cross-env FORCE_COLOR=true supertape --no-check-assertions-count --format tap test/test.js -- --slow | tap-dot",
"cover": "c8 --skip-full -r html -r text supertape --no-check-assertions-count --format fail test/test.js"

View file

@ -73,6 +73,13 @@ Follow these steps:
7. Start the bridge: `node start.js`
8. Add the bot to a server - use any *one* of the following commands for an invite link:
* (in the REPL) `addbot`
* (in a chat) `//addbot`
* $ `node addbot.js`
* $ `npm run addbot`
* $ `./addbot.sh`
# Development information
* Be sure to install dependencies with `--save-dev` so you can run the tests.

View file

@ -2,9 +2,10 @@
const repl = require("repl")
const util = require("util")
const {addbot} = require("./addbot")
const passthrough = require("./passthrough")
const { discord, config, sync, db } = passthrough
const {discord, config, sync, db} = passthrough
const data = sync.require("./test/data")
const createSpace = sync.require("./d2m/actions/create-space")
@ -39,6 +40,7 @@ setImmediate(() => { // assign after since old extraContext data will get remove
async function customEval(input, _context, _filename, callback) {
let depth = 0
if (input === "exit\n") return process.exit()
if (input === "addbot\n") return callback(null, addbot())
if (input.startsWith(":")) {
const depthOverwrite = input.split(" ")[0]
depth = +depthOverwrite.slice(1)