From 63eb7f9dbd07a7d2325a6a95c78ed8fa6a1d4bb1 Mon Sep 17 00:00:00 2001 From: MattIPv4 Date: Mon, 12 Aug 2024 02:28:22 +0100 Subject: [PATCH] Add new invite for user-install --- src/commands/invite.js | 5 +++-- src/components/index.js | 2 ++ src/components/invite-user.js | 13 +++++++++++++ src/components/invite.js | 2 +- src/index.js | 5 ++++- 5 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 src/components/invite-user.js diff --git a/src/commands/invite.js b/src/commands/invite.js index 2146b85..9171bb0 100644 --- a/src/commands/invite.js +++ b/src/commands/invite.js @@ -2,6 +2,7 @@ import { ComponentType, InteractionResponseType, ApplicationIntegrationType, Int import { createEmbed } from '../utils/embed.js'; import invite from '../components/invite.js'; +import inviteUser from '../components/invite-user.js'; export default { name: 'invite', @@ -23,13 +24,13 @@ export default { embeds: [ createEmbed( 'Invite', - 'Invite DNS over Discord to your server with https://dns-over-discord.v4.wtf/invite', + 'Invite DNS over Discord to your server with https://dns-over-discord.v4.wtf/invite\n\nOr, use the bot anywhere by adding it to your account with https://dns-over-discord.v4.wtf/invite/user', ), ], components: [ { type: ComponentType.ActionRow, - components: [ invite.component ], + components: [ invite.component, inviteUser.component ], }, ], }, diff --git a/src/components/index.js b/src/components/index.js index f96c12e..9d0653f 100644 --- a/src/components/index.js +++ b/src/components/index.js @@ -2,10 +2,12 @@ import digProvider from './dig-provider.js'; import digRefresh from './dig-refresh.js'; // import docs from './docs.js'; // import invite from './invite.js'; +// import inviteUser from './invite-user.js'; export default [ digProvider, digRefresh, // docs, // Don't export, as does not handle interaction requests // invite, // Don't export, as does not handle interaction requests + // inviteUser, // Don't export, as does not handle interaction requests ]; diff --git a/src/components/invite-user.js b/src/components/invite-user.js new file mode 100644 index 0000000..5ae96e7 --- /dev/null +++ b/src/components/invite-user.js @@ -0,0 +1,13 @@ +import { ComponentType, ButtonStyle, ApplicationIntegrationType } from 'discord-api-types/payloads'; + +const component = { + type: ComponentType.Button, + style: ButtonStyle.Link, + url: `https://discord.com/oauth2/authorize?client_id=${process.env.CLIENT_ID}&scope=applications.commands&integration_type=${ApplicationIntegrationType.UserInstall}`, + label: 'Add the bot to your account', +}; + +export default { + name: 'invite-user', + component, +}; diff --git a/src/components/invite.js b/src/components/invite.js index fbf7662..d941bb2 100644 --- a/src/components/invite.js +++ b/src/components/invite.js @@ -4,7 +4,7 @@ const component = { type: ComponentType.Button, style: ButtonStyle.Link, url: `https://discord.com/oauth2/authorize?client_id=${process.env.CLIENT_ID}&scope=applications.commands`, - label: 'Invite the bot', + label: 'Invite the bot to a server', }; export default { diff --git a/src/index.js b/src/index.js index 85ee7f1..3167fc9 100644 --- a/src/index.js +++ b/src/index.js @@ -1,5 +1,6 @@ import WorkersSentry from 'workers-sentry/worker.js'; import { createHandler } from 'workers-discord'; +import { ApplicationIntegrationType } from 'discord-api-types/payloads'; import commands from './commands/index.js'; import components from './components/index.js'; @@ -45,9 +46,11 @@ const handleRequest = async (request, env, ctx, sentry) => { if (request.method === 'GET' && url.pathname === '/terms') return textResponse(Terms); - // Invite redirect + // Invite redirects if (request.method === 'GET' && url.pathname === '/invite') return redirectResponse(`https://discord.com/oauth2/authorize?client_id=${process.env.CLIENT_ID}&scope=applications.commands`); + if (request.method === 'GET' && url.pathname === '/invite/user') + return redirectResponse(`https://discord.com/oauth2/authorize?client_id=${process.env.CLIENT_ID}&scope=applications.commands&integration_type=${ApplicationIntegrationType.UserInstall}`); // Discord redirect if (request.method === 'GET' && url.pathname === '/server')