|
1 | 1 | import { ActionRowBuilder, ButtonBuilder, ButtonStyle, SlashCommandBuilder } from 'discord.js'; |
2 | 2 | import { getCollection } from '../lib/mongo.js'; |
3 | 3 | import { pollForDeviceKey, startDeviceAuth } from '../lib/open-domains.js'; |
| 4 | +import { buildTicketLoginUpdateMessage, getUserTicketContext } from '../lib/ticket-session.js'; |
4 | 5 |
|
5 | 6 | const collectionName = 'sessions'; |
6 | 7 |
|
@@ -67,7 +68,7 @@ export const command = { |
67 | 68 |
|
68 | 69 | const verificationUrl = device.verification_uri_complete || device.verification_uri; |
69 | 70 | const discordVerificationUrl = verificationUrl |
70 | | - ? `${verificationUrl}${verificationUrl.includes('?') ? '&' : '?'}APP=discord_bot` |
| 71 | + ? `${verificationUrl}${verificationUrl.includes('?') ? '&' : '?'}APP=discord_bot&code=${encodeURIComponent(device.user_code)}` |
71 | 72 | : undefined; |
72 | 73 | const codeLine = device.user_code ? `Enter code **${device.user_code}**` : 'Approve the request'; |
73 | 74 |
|
@@ -114,6 +115,15 @@ export const command = { |
114 | 115 | content: 'Login complete. Your OpenDomains API key is stored securely.', |
115 | 116 | ephemeral: true, |
116 | 117 | }); |
| 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 | + } |
117 | 127 | } catch (error) { |
118 | 128 | await sessions.updateOne( |
119 | 129 | { userId }, |
|
0 commit comments