From 71ee670ba2a8e28e687a8ebb8220603d87a2dace Mon Sep 17 00:00:00 2001 From: LunaUrsa <1836049+LunaUrsa@users.noreply.github.com> Date: Wed, 20 Dec 2023 11:22:49 -0600 Subject: [PATCH] Update AI linking --- src/discord/commands/global/d.ai.ts | 45 ++++++++++++++++------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/src/discord/commands/global/d.ai.ts b/src/discord/commands/global/d.ai.ts index ad3754a1e..e7eb837c8 100644 --- a/src/discord/commands/global/d.ai.ts +++ b/src/discord/commands/global/d.ai.ts @@ -1096,6 +1096,7 @@ async function link( interaction: ChatInputCommandInteraction, ): Promise { const visible = interaction.options.getBoolean('ephemeral') !== false; + if (!interaction.guild) return; await interaction.deferReply({ ephemeral: !visible }); const personaName = interaction.options.getString('name') ?? 'tripbot'; @@ -1139,38 +1140,42 @@ async function link( }, }); - if (aiLinkData) { - await db.ai_channels.update({ - where: { - id: aiLinkData.id, - }, - data: { + const verb = aiLinkData ? 'updated' : 'created'; + + await db.ai_channels.upsert({ + where: { + channel_id_persona_id: { channel_id: textChannel.id, persona_id: personaData.id, }, - }); - await interaction.editReply({ - embeds: [embedTemplate() - .setTitle('Modal') - .setColor(Colors.Red) - .setDescription(`Success: The link between ${personaName} and <#${textChannel.id}> was updated!`)], - - }); - return; - } - - await db.ai_channels.create({ - data: { + }, + create: { channel_id: textChannel.id, persona_id: personaData.id, }, + update: { + channel_id: textChannel.id, + persona_id: personaData.id, + }, + }); + + await interaction.editReply({ + embeds: [embedTemplate() + .setTitle('Modal') + .setColor(Colors.Red) + .setDescription(`Success: The link between ${personaName} and <#${textChannel.id}> was ${verb}!`)], }); + await interaction.editReply({ embeds: [embedTemplate() .setTitle('Modal') .setColor(Colors.Red) - .setDescription(`Success: The link between ${personaName} and <#${textChannel.id}> was created!`)], + .setDescription(`Success: The link between ${personaName} and <#${textChannel.id}> was ${verb}!`)], + }); + const channelAiLog = await discordClient.channels.fetch(env.CHANNEL_AILOG) as TextChannel; + await channelAiLog.send({ + content: `New AI link between ${personaName} and <#${textChannel.id}> on the ${interaction.guild.name} server ${interaction.member} (<@${env.DISCORD_OWNER_ID}>)`, }); return; }