Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup partify #17

Merged
merged 3 commits into from
Apr 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}`
)
},
}