Skip to content

Commit

Permalink
Merge pull request #17 from fac31/cleanup-partify
Browse files Browse the repository at this point in the history
Cleanup partify
  • Loading branch information
sulphite authored Apr 30, 2024
2 parents 7f46b24 + c2648f3 commit 12c7fb9
Showing 1 changed file with 31 additions and 18 deletions.
49 changes: 31 additions & 18 deletions src/commandCenter/commands/Partify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import {
GuildScheduledEventCreateOptions,
GuildScheduledEventEntityType,
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 =
Expand All @@ -36,32 +38,43 @@ 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)
if (interaction.guild === null) {
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
if (voiceChan === undefined || voiceChan === null) {
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 newEvent: GuildScheduledEventCreateOptions = {
...partyJson,
scheduledStartTime: targetTime,
scheduledEndTime: dayjs(targetTime).add(1,"hour").toDate(),
entityType: GuildScheduledEventEntityType.External,
privacyLevel: GuildScheduledEventPrivacyLevel.GuildOnly,
entityMetadata: {location: "voice channel"}
}

// code to generate event goes here
interaction.guild?.scheduledEvents.create(newEvent)
const newEventDetails: GuildScheduledEventCreateOptions = {
...partyJson,
scheduledStartTime: targetTime,
entityType: GuildScheduledEventEntityType.Voice,
privacyLevel: GuildScheduledEventPrivacyLevel.GuildOnly,
channel: voiceChan,
}

await interaction.followUp({
content: `OK! You've got a party coming up at <t:${dayjs(targetTime).unix()}>`,
})
const newEvent: GuildScheduledEvent =
await interaction.guild.scheduledEvents.create(newEventDetails)
interaction.followUp(
`OK! Here's what I came up with! 🎉 ${newEvent.url}`
)
},
}

0 comments on commit 12c7fb9

Please sign in to comment.