Add "addbot" feature
This commit is contained in:
parent
6d83df2e95
commit
708955c062
6 changed files with 40 additions and 1 deletions
15
addbot.js
Normal file
15
addbot.js
Normal 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
3
addbot.sh
Executable 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"
|
|
@ -4,6 +4,7 @@ const assert = require("assert").strict
|
||||||
const util = require("util")
|
const util = require("util")
|
||||||
const DiscordTypes = require("discord-api-types/v10")
|
const DiscordTypes = require("discord-api-types/v10")
|
||||||
const reg = require("../matrix/read-registration")
|
const reg = require("../matrix/read-registration")
|
||||||
|
const {addbot} = require("../addbot")
|
||||||
|
|
||||||
const {discord, sync, db, select} = require("../passthrough")
|
const {discord, sync, db, select} = require("../passthrough")
|
||||||
/** @type {import("../matrix/api")}) */
|
/** @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} */
|
/** @type {CommandExecute} */
|
||||||
|
|
|
@ -45,6 +45,7 @@
|
||||||
"tap-dot": "github:cloudrac3r/tap-dot#9dd7750ececeae3a96afba91905be812b6b2cc2d"
|
"tap-dot": "github:cloudrac3r/tap-dot#9dd7750ececeae3a96afba91905be812b6b2cc2d"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"addbot": "node addbot.js",
|
||||||
"test": "cross-env FORCE_COLOR=true supertape --no-check-assertions-count --format tap test/test.js | tap-dot",
|
"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",
|
"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"
|
"cover": "c8 --skip-full -r html -r text supertape --no-check-assertions-count --format fail test/test.js"
|
||||||
|
|
|
@ -73,6 +73,13 @@ Follow these steps:
|
||||||
|
|
||||||
7. Start the bridge: `node start.js`
|
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
|
# Development information
|
||||||
|
|
||||||
* Be sure to install dependencies with `--save-dev` so you can run the tests.
|
* Be sure to install dependencies with `--save-dev` so you can run the tests.
|
||||||
|
|
4
stdin.js
4
stdin.js
|
@ -2,9 +2,10 @@
|
||||||
|
|
||||||
const repl = require("repl")
|
const repl = require("repl")
|
||||||
const util = require("util")
|
const util = require("util")
|
||||||
|
const {addbot} = require("./addbot")
|
||||||
|
|
||||||
const passthrough = require("./passthrough")
|
const passthrough = require("./passthrough")
|
||||||
const { discord, config, sync, db } = passthrough
|
const {discord, config, sync, db} = passthrough
|
||||||
|
|
||||||
const data = sync.require("./test/data")
|
const data = sync.require("./test/data")
|
||||||
const createSpace = sync.require("./d2m/actions/create-space")
|
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) {
|
async function customEval(input, _context, _filename, callback) {
|
||||||
let depth = 0
|
let depth = 0
|
||||||
if (input === "exit\n") return process.exit()
|
if (input === "exit\n") return process.exit()
|
||||||
|
if (input === "addbot\n") return callback(null, addbot())
|
||||||
if (input.startsWith(":")) {
|
if (input.startsWith(":")) {
|
||||||
const depthOverwrite = input.split(" ")[0]
|
const depthOverwrite = input.split(" ")[0]
|
||||||
depth = +depthOverwrite.slice(1)
|
depth = +depthOverwrite.slice(1)
|
||||||
|
|
Loading…
Reference in a new issue