{"_id":"@code6226/cf-workers-discord-bot","_rev":"1-013a3cab0b1bee8930ee982c751370b1","name":"@code6226/cf-workers-discord-bot","dist-tags":{"latest":"1.1.2"},"versions":{"1.1.1":{"name":"@code6226/cf-workers-discord-bot","private":false,"description":"Interact with Discord from within a Cloudflare Worker","version":"1.1.1","license":"MIT","main":"dist/index.js","scripts":{"test:ci":"jest --ci","build":"tsc -p tsconfig.build.json --outDir dist/","clean":"rimraf dist/","clean:node":"rimraf package-lock.json node_modules/","lint":"prettier -c .","format":"npm run lint -- --write"},"author":{"name":"Greg Brimble","email":"greg@glenstack.com","url":"https://glenstack.com/"},"bugs":{"url":"https://github.com/glenstack/glenstack/tree/master/packages/cf-workers-discord-bot","email":"hello@glenstack.com"},"repository":{"type":"git","url":"git+https://github.com/glenstack/glenstack.git","directory":"packages/cf-workers-discord-bot"},"devDependencies":{"@types/jest":"26.0.10","@types/node":"14.6.0","cross-fetch":"3.0.5","jest":"26.4.1","prettier":"2.0.5","rimraf":"3.0.2","ts-jest":"26.2.0","typescript":"4.0.2"},"publishConfig":{"access":"public"},"dependencies":{"@code6226/cf-workers-fetch-helpers":"*","@glenstack/cf-workers-router":"*","tweetnacl":"1.0.3"},"types":"./dist\\index.d.ts","gitHead":"c9a959a13a68779843946eaf7f3a91bb8b68e02d","homepage":"https://github.com/glenstack/glenstack#readme","_id":"@code6226/cf-workers-discord-bot@1.1.1","_nodeVersion":"16.14.2","_npmVersion":"8.5.0","dist":{"integrity":"sha512-b1sDtjCpD5lCtqMUtiehHbnit1uGl+I9HJhAGpHw6RlevcZcuzC9OZ2N69vRKDx/C8oaNGMdctXpunbLH3Stbg==","shasum":"3db88cf606b6bbb38c8e2addd32376b949b50f5a","tarball":"https://registry.npmjs.org/@code6226/cf-workers-discord-bot/-/cf-workers-discord-bot-1.1.1.tgz","fileCount":13,"unpackedSize":23361,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIF1WUo8/1s30yOGhALOSMk7cuNZnjr5T8Ks69jHX4y44AiAOsW0P5vlmLj/RnzfTYUgHk53U1pmKJX/c961SrHVqew=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJibrIQACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoF/w/+InBqDL/rcpq+YewMvS2rwBbZAcUeZBtVZEDtSVocNgL63m15\r\nHZRtapQwBmIZKxnnemHOIA2AqIPD32lpQkqXeWyyFk/+b0NIXomCoTMACaDo\r\neksNv1ud952mk7i9IQYuEtbwdhVhXANcjJGwdP3hPALkTdqtnB+FYbgkfJwR\r\nPybYgv94r1aWdJsKTy1PcnKixIz8rAIIcB1zUFVJC2Skjho26DErxcvdiRsF\r\nhCmjRvCWTTc44Y8jShIOLNaIA3SO0uhTSp6Z1svm6wdXxJQY+yTpaaalWAgt\r\nfOy6FQGOAVOhZtTB7g8E9lMV0zXe1eIbQvyz2pTzo3PzKHEFMKJJrBJA3i6Q\r\niFSCrIxYHUbiy7id8buk2q2UPNE38I4PKa02s4Wb6EEZF6P0WRBs5b07j827\r\n1Ehk1jZMTdSx++q7ZkSZFkZmtKGknnBGUdx4l3Nv9dc46lXUZKDztOsPqh7L\r\nAvZoyz8fJvWOllheJxE36AMgX4Enb3fTUt77vOJ2TO4VUkghEwKNh4qAET6x\r\nRfe6BYDbTPX5mFtF4p7tCbzN4imAx958yGI75kbJpcH3nVKgzExDuLPloYru\r\nRiRH8Ou4mfdQzs1lFdcqTvsm+2wP45gF5duvHd3FXaxvG1Caqm5bB2LhPN4P\r\n2V5rLUasBIQ9c7rsHRuw2ksoc/VQfOrqcrk=\r\n=jEk2\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"code6226","email":"code6226@gmail.com"},"directories":{},"maintainers":[{"name":"code6226","email":"code6226@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/cf-workers-discord-bot_1.1.1_1651421711961_0.8107377523591217"},"_hasShrinkwrap":false},"1.1.2":{"name":"@code6226/cf-workers-discord-bot","private":false,"description":"Interact with Discord from within a Cloudflare Worker","version":"1.1.2","license":"MIT","main":"dist/index.js","scripts":{"test:ci":"jest --ci","build":"tsc -p tsconfig.build.json --outDir dist/","clean":"rimraf dist/","clean:node":"rimraf package-lock.json node_modules/","lint":"prettier -c .","format":"npm run lint -- --write"},"author":{"name":"Greg Brimble","email":"greg@glenstack.com","url":"https://glenstack.com/"},"bugs":{"url":"https://github.com/glenstack/glenstack/tree/master/packages/cf-workers-discord-bot","email":"hello@glenstack.com"},"repository":{"type":"git","url":"git+https://github.com/Code6226/glenstack.git","directory":"packages/cf-workers-discord-bot"},"devDependencies":{"@types/jest":"26.0.10","@types/node":"14.6.0","cross-fetch":"3.0.5","jest":"26.4.1","prettier":"2.0.5","rimraf":"3.0.2","ts-jest":"26.2.0","typescript":"4.0.2"},"publishConfig":{"access":"public"},"dependencies":{"@code6226/cf-workers-fetch-helpers":"*","@glenstack/cf-workers-router":"*","discord-interactions":"^3.2.0"},"types":"./dist\\index.d.ts","gitHead":"4694be780746251542e357491b0922df60c51aa9","homepage":"https://github.com/Code6226/glenstack#readme","_id":"@code6226/cf-workers-discord-bot@1.1.2","_nodeVersion":"16.14.2","_npmVersion":"8.5.0","dist":{"integrity":"sha512-UEcCU9W5a/++Ti7rbzytjAvI7ImLauCw0R5QZx981r1oZT838Jrh5d4j3IAX4iILwXlaEAMBiMTrjk/pjk0DXA==","shasum":"c3189e5e30be9b66639a50680e69b9d2d90e565b","tarball":"https://registry.npmjs.org/@code6226/cf-workers-discord-bot/-/cf-workers-discord-bot-1.1.2.tgz","fileCount":13,"unpackedSize":23570,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHJRi7jPEsVkC5P7UCgvNb8Mt1k2Zk3mZI7MHVd4OjakAiAskx8SngRHRF+upIO26ghTKv1J0jZ1Xak3H7hF/Vpmfg=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJibtvvACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmplug/8COzdmscfqsG7if+536fItMtAxlW8Z7nZyG/Bak6tUePQNMcA\r\nwUnsI2mVS8y5WK9WS7iePFTkGLYAiSso1OtrPd8L1qQH0qul9/Z2Y3iuAG0d\r\neE9jr6q9n7GY7cArHb02JEEWpL9o6XCXGMaGXMjh7uTuyT2NQnwoGotozkTr\r\nFnlW19maBaH7RfgCDq5ebKC7kAMfqLehrdj1Wb0JUFGaYePQ2wGmFDDp2UM/\r\nF9CX4GrDXM8zqMWrbcotfOvzwucsmR6dii9rCaVikJEhbXOgz6xOhuEhmXVG\r\nQV88vkfQP/gdUzVxKvZ5Krhf9TcNWqgmaJWcn+e3u4SO+p9VkVxQYwe5ag2G\r\nn7f7fTlY/4xGWkpXX94KxfkoBXrhToKlpNCnlmm/9SfuZjacXHKmNi8QI6KU\r\nhMz2OWaRKK3btBAv0w9liPCdTFCFKy52f3F2R+atwO6of9kPGHzW1uppRPNZ\r\ndUYAYY/4ZFGDtapNniEI4P4O/fVp7BZDt1n9Qm/7eQZmHaycXQ2vaOf+oEEQ\r\nIz/r6SXYaWpVYddQbnICSxQqr/8rDdMwdjIMPmGt5esIHKvaTzvsNDRxZJzV\r\nJMI7LcH5qRgKjoTxuPWWHMcnU4neuPko7Y/aNOdHwC0jX7drpUr4PZIAHhZc\r\npNiEThZ3RuuVNpMpBXPG4VrWRoBASvY1y08=\r\n=TUNn\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"code6226","email":"code6226@gmail.com"},"directories":{},"maintainers":[{"name":"code6226","email":"code6226@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/cf-workers-discord-bot_1.1.2_1651432431204_0.8180054100451377"},"_hasShrinkwrap":false}},"time":{"created":"2022-05-01T16:15:11.908Z","1.1.1":"2022-05-01T16:15:12.120Z","modified":"2022-05-01T19:13:51.409Z","1.1.2":"2022-05-01T19:13:51.343Z"},"maintainers":[{"name":"code6226","email":"code6226@gmail.com"}],"description":"Interact with Discord from within a Cloudflare Worker","homepage":"https://github.com/Code6226/glenstack#readme","repository":{"type":"git","url":"git+https://github.com/Code6226/glenstack.git","directory":"packages/cf-workers-discord-bot"},"author":{"name":"Greg Brimble","email":"greg@glenstack.com","url":"https://glenstack.com/"},"bugs":{"url":"https://github.com/glenstack/glenstack/tree/master/packages/cf-workers-discord-bot","email":"hello@glenstack.com"},"license":"MIT","readme":"# Cloudflare Workers Discord Bot\n\nInteract with [Discord](https://discord.com/) from within [Cloudflare Workers](https://workers.cloudflare.com/).\n\n_This is the same as @glenstack/cf-workers-fetch-helpers, except it has the [Buffer bug](https://github.com/glenstack/glenstack/issues/13#issuecomment-1075535069) fixed_\n\n## Installation\n\n```sh\nnpm install --save @code6226/cf-workers-discord-bot\n```\n\n## Usage\n\n### `createSlashCommandHandler`\n\n```typescript\nimport {\n  createSlashCommandHandler,\n  ApplicationCommand,\n  InteractionHandler,\n  Interaction,\n  InteractionResponse,\n  InteractionResponseType,\n} from \"@code6226/cf-workers-discord-bot\";\n\nconst helloCommand: ApplicationCommand = {\n  name: \"hello\",\n  description: \"Bot will say hello to you!\",\n};\n\nconst helloHandler: InteractionHandler = async (\n  interaction: Interaction\n): Promise<InteractionResponse> => {\n  const userID = interaction.member.user.id;\n\n  return {\n    type: InteractionResponseType.ChannelMessageWithSource,\n    data: {\n      content: `Hello, <@${userID}>!`,\n      allowed_mentions: {\n        users: [userID],\n      },\n    },\n  };\n};\n\nconst slashCommandHandler = createSlashCommandHandler({\n  applicationID: \"799627301675466772\",\n  applicationSecret: APPLICATION_SECRET, // You should store this in a secret\n  publicKey: \"1b780f7f71ac39645d44cc4dce8fa78c860d0157cb0912d755b7a7cb95394532\",\n  commands: [[helloCommand, helloHandler]],\n});\n\naddEventListener(\"fetch\", (event) => {\n  event.respondWith(slashCommandHandler(event.request));\n});\n```\n\n`createSlashCommandHandler` takes one parameter:\n\n1. An object with the following parameters:\n\n   - `applicationID`: The \"Client ID\" of your [Discord application](https://discord.com/developers/applications/).\n   - `applicationSecret`: The \"Client Secret\" of your [Discord application](https://discord.com/developers/applications/). **Note: this should be stored securely as a [secret](https://developers.cloudflare.com/workers/cli-wrangler/commands#secret) in the Worker.**\n   - `publicKey`: The \"Public Key\" of your [Discord application](https://discord.com/developers/applications/).\n   - `commands`: An array of the commands for your bot to register and respond to.\n\n     Each element of this array should be itself an array with two elements:\n\n     1. An [`ApplicationCommand`](https://discord.com/developers/docs/interactions/slash-commands#applicationcommand) object used to register the command.\n     1. A function which takes a single parameter, an [`Interaction`](https://discord.com/developers/docs/interactions/slash-commands#interaction) object, and returns an [`InteractionResponse`](https://discord.com/developers/docs/interactions/slash-commands#interaction-response) or a Promise of an [`InteractionResponse`](https://discord.com/developers/docs/interactions/slash-commands#interaction-response).\n\nIt returns a function which takes a Request and returns a Promise of a Response. It should typically be given to the `event.respondWith` function.\n\nThis makes your application respond to three types of Requests:\n\n- `GET /`: Redirects the user to Discord to authorize the bot on a server.\n- `POST /interaction`: The incoming webhook from Discord to respond to Slash Commands or Pings. **Note: this URL needs to be configured in the Discord Developer Portal as the \"Interactions Endpoint URL\" e.g. `https://my-discord-bot.workers.dev/interaction`**\n- `GET /setup`: Registers the commands with Discord. **Note: this endpoint must be visited once to initialize the new commands, and again everytime the commands are updated.**\n","readmeFilename":"README.md"}