Skip to content

Commit

Permalink
Add new invite for user-install
Browse files Browse the repository at this point in the history
  • Loading branch information
MattIPv4 committed Aug 12, 2024
1 parent a7358be commit 63eb7f9
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/commands/invite.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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 ],
},
],
},
Expand Down
2 changes: 2 additions & 0 deletions src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
];
13 changes: 13 additions & 0 deletions src/components/invite-user.js
Original file line number Diff line number Diff line change
@@ -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,
};
2 changes: 1 addition & 1 deletion src/components/invite.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit 63eb7f9

Please sign in to comment.