From fff93443905aa76dea22aeb8b9b46b1bd7e771df Mon Sep 17 00:00:00 2001 From: Janett Gerrard Date: Thu, 25 Apr 2024 10:56:24 +0100 Subject: [PATCH 1/3] create the event in a voice channel --- src/commandCenter/commands/Partify.ts | 28 +++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/commandCenter/commands/Partify.ts b/src/commandCenter/commands/Partify.ts index 7dd101f..9f6c104 100755 --- a/src/commandCenter/commands/Partify.ts +++ b/src/commandCenter/commands/Partify.ts @@ -6,6 +6,9 @@ import { GuildScheduledEventCreateOptions, GuildScheduledEventEntityType, GuildScheduledEventPrivacyLevel, + ChannelType, + VoiceChannel, + // Snowflake, } from 'discord.js' import { Command } from '../../Command' import { stringToTime } from '../utils/stringToTime' @@ -36,9 +39,23 @@ export const Partify: Command = { }, ], run: async (_: Client, interaction: CommandInteraction) => { - console.log(interaction.options.get('theme')?.value) const timeInput = interaction.options.get('when')?.value as string const targetTime = stringToTime(timeInput, interaction.createdAt) + const guildChanManager = interaction.guild?.channels + if (guildChanManager === undefined) { + throw new Error("can't get guildchannelmanager") + } + // console.log("count",guildChanManager.channelCountWithoutThreads) + const channels = await guildChanManager.fetch() + let voiceChan = channels.find(chan => chan?.type == ChannelType.GuildVoice) as VoiceChannel + if (voiceChan === undefined || voiceChan === null) { + voiceChan = await guildChanManager.create({ + name: "party", + type: ChannelType.GuildVoice, + }) + } + + const generatedPartyIdea = await fetchOpenAIChatCompletion( interaction.options.get('theme')?.value as string, @@ -48,13 +65,16 @@ export const Partify: Command = { console.log(partyJson) // this gives us an object to use in creating the event // { name: string, description: string } + + const newEvent: GuildScheduledEventCreateOptions = { ...partyJson, scheduledStartTime: targetTime, - scheduledEndTime: dayjs(targetTime).add(1,"hour").toDate(), - entityType: GuildScheduledEventEntityType.External, + // scheduledEndTime: dayjs(targetTime).add(1,"hour").toDate(), + entityType: GuildScheduledEventEntityType.Voice, privacyLevel: GuildScheduledEventPrivacyLevel.GuildOnly, - entityMetadata: {location: "voice channel"} + channel: voiceChan + // entityMetadata: {location: "voice channel"} } // code to generate event goes here From c0191e3d03e16a0a22d98367808901fafa9fd05c Mon Sep 17 00:00:00 2001 From: Janett Gerrard Date: Thu, 25 Apr 2024 11:11:09 +0100 Subject: [PATCH 2/3] type shenanigans --- src/commandCenter/commands/Partify.ts | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/src/commandCenter/commands/Partify.ts b/src/commandCenter/commands/Partify.ts index 9f6c104..11bdbbe 100755 --- a/src/commandCenter/commands/Partify.ts +++ b/src/commandCenter/commands/Partify.ts @@ -8,7 +8,6 @@ import { GuildScheduledEventPrivacyLevel, ChannelType, VoiceChannel, - // Snowflake, } from 'discord.js' import { Command } from '../../Command' import { stringToTime } from '../utils/stringToTime' @@ -41,22 +40,19 @@ export const Partify: Command = { run: async (_: Client, interaction: CommandInteraction) => { const timeInput = interaction.options.get('when')?.value as string const targetTime = stringToTime(timeInput, interaction.createdAt) - const guildChanManager = interaction.guild?.channels - if (guildChanManager === undefined) { - throw new Error("can't get guildchannelmanager") + if (interaction.guild === null) { + throw new Error("can't get guild") } - // console.log("count",guildChanManager.channelCountWithoutThreads) - const channels = await guildChanManager.fetch() + const guild = interaction.guild + const channels = await guild.channels.fetch() let voiceChan = channels.find(chan => chan?.type == ChannelType.GuildVoice) as VoiceChannel if (voiceChan === undefined || voiceChan === null) { - voiceChan = await guildChanManager.create({ + voiceChan = await guild.channels.create({ name: "party", type: ChannelType.GuildVoice, }) } - - const generatedPartyIdea = await fetchOpenAIChatCompletion( interaction.options.get('theme')?.value as string, partySystemPrompt @@ -66,19 +62,15 @@ export const Partify: Command = { // this gives us an object to use in creating the event // { name: string, description: string } - - const newEvent: GuildScheduledEventCreateOptions = { + const newEventDetails: GuildScheduledEventCreateOptions = { ...partyJson, scheduledStartTime: targetTime, - // scheduledEndTime: dayjs(targetTime).add(1,"hour").toDate(), entityType: GuildScheduledEventEntityType.Voice, privacyLevel: GuildScheduledEventPrivacyLevel.GuildOnly, channel: voiceChan - // entityMetadata: {location: "voice channel"} } - // code to generate event goes here - interaction.guild?.scheduledEvents.create(newEvent) + interaction.guild.scheduledEvents.create(newEventDetails) await interaction.followUp({ content: `OK! You've got a party coming up at `, From c2648f371b83f1bd8a3e8ae960eba830a6364a97 Mon Sep 17 00:00:00 2001 From: Janett Gerrard Date: Thu, 25 Apr 2024 16:45:24 +0100 Subject: [PATCH 3/3] bot posts a link to the event --- src/commandCenter/commands/Partify.ts | 41 ++++++++++++++------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/src/commandCenter/commands/Partify.ts b/src/commandCenter/commands/Partify.ts index 11bdbbe..b25b6e7 100755 --- a/src/commandCenter/commands/Partify.ts +++ b/src/commandCenter/commands/Partify.ts @@ -8,10 +8,10 @@ import { GuildScheduledEventPrivacyLevel, ChannelType, VoiceChannel, + GuildScheduledEvent, } from 'discord.js' import { Command } from '../../Command' import { stringToTime } from '../utils/stringToTime' -import dayjs from 'dayjs' import { fetchOpenAIChatCompletion } from '../../openai' const partySystemPrompt = @@ -41,39 +41,40 @@ export const Partify: Command = { const timeInput = interaction.options.get('when')?.value as string const targetTime = stringToTime(timeInput, interaction.createdAt) if (interaction.guild === null) { - throw new Error("can't get guild") + throw new Error("can't get guild") } const guild = interaction.guild const channels = await guild.channels.fetch() - let voiceChan = channels.find(chan => chan?.type == ChannelType.GuildVoice) as VoiceChannel + let voiceChan = channels.find( + (chan) => chan?.type == ChannelType.GuildVoice + ) as VoiceChannel if (voiceChan === undefined || voiceChan === null) { - voiceChan = await guild.channels.create({ - name: "party", - type: ChannelType.GuildVoice, - }) + voiceChan = await guild.channels.create({ + name: 'party', + type: ChannelType.GuildVoice, + }) } const generatedPartyIdea = await fetchOpenAIChatCompletion( interaction.options.get('theme')?.value as string, partySystemPrompt ) - const partyJson: {name: string; description: string;} = JSON.parse(generatedPartyIdea) - console.log(partyJson) + const partyJson: { name: string; description: string } = + JSON.parse(generatedPartyIdea) // this gives us an object to use in creating the event - // { name: string, description: string } const newEventDetails: GuildScheduledEventCreateOptions = { - ...partyJson, - scheduledStartTime: targetTime, - entityType: GuildScheduledEventEntityType.Voice, - privacyLevel: GuildScheduledEventPrivacyLevel.GuildOnly, - channel: voiceChan + ...partyJson, + scheduledStartTime: targetTime, + entityType: GuildScheduledEventEntityType.Voice, + privacyLevel: GuildScheduledEventPrivacyLevel.GuildOnly, + channel: voiceChan, } - interaction.guild.scheduledEvents.create(newEventDetails) - - await interaction.followUp({ - content: `OK! You've got a party coming up at `, - }) + const newEvent: GuildScheduledEvent = + await interaction.guild.scheduledEvents.create(newEventDetails) + interaction.followUp( + `OK! Here's what I came up with! 🎉 ${newEvent.url}` + ) }, }