Skip to content

Commit 8c7eba4

Browse files
committed
Ticket updates
1 parent db98ee3 commit 8c7eba4

11 files changed

Lines changed: 663 additions & 312 deletions

src/commands/login.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, SlashCommandBuilder } from 'discord.js';
22
import { getCollection } from '../lib/mongo.js';
33
import { pollForDeviceKey, startDeviceAuth } from '../lib/open-domains.js';
4+
import { buildTicketLoginUpdateMessage, getUserTicketContext } from '../lib/ticket-session.js';
45

56
const collectionName = 'sessions';
67

@@ -67,7 +68,7 @@ export const command = {
6768

6869
const verificationUrl = device.verification_uri_complete || device.verification_uri;
6970
const discordVerificationUrl = verificationUrl
70-
? `${verificationUrl}${verificationUrl.includes('?') ? '&' : '?'}APP=discord_bot`
71+
? `${verificationUrl}${verificationUrl.includes('?') ? '&' : '?'}APP=discord_bot&code=${encodeURIComponent(device.user_code)}`
7172
: undefined;
7273
const codeLine = device.user_code ? `Enter code **${device.user_code}**` : 'Approve the request';
7374

@@ -114,6 +115,15 @@ export const command = {
114115
content: 'Login complete. Your OpenDomains API key is stored securely.',
115116
ephemeral: true,
116117
});
118+
119+
const ticketContext = await getUserTicketContext(userId);
120+
if (ticketContext?.channelId && ticketContext?.guildId) {
121+
const guild = await interaction.client.guilds.fetch(ticketContext.guildId).catch(() => null);
122+
const channel = await guild?.channels.fetch(ticketContext.channelId).catch(() => null);
123+
if (channel?.isTextBased()) {
124+
await channel.send({ content: buildTicketLoginUpdateMessage(interaction.user) });
125+
}
126+
}
117127
} catch (error) {
118128
await sessions.updateOne(
119129
{ userId },

0 commit comments

Comments
 (0)