Skip to content

Commit

Permalink
Update: new posts should start with embeds instead of show poster (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbackas committed Aug 4, 2023
1 parent 2da49d5 commit e4af50d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/commands/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export const command: CommandV2 = {

await channel.send({
content: `Linked \`${tvdbSeries.name}\` to <#${channel.id}>`,
embeds: [await buildShowEmbed(imdbId, tvdbSeries, show.destinations)]
embeds: [buildShowEmbed(imdbId, tvdbSeries, show.destinations)]
})

messages.push(`Linked show \`${tvdbSeries.name}\` (${imdbId})`)
Expand Down
27 changes: 14 additions & 13 deletions src/commands/post.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type Channel, type ChannelManager, ChannelType, type ChatInputCommandInteraction, Collection, PermissionFlagsBits, SlashCommandBuilder, type TextBasedChannel, type ThreadChannel } from 'discord.js'
import { type Channel, ChannelType, type ChatInputCommandInteraction, Collection, PermissionFlagsBits, SlashCommandBuilder, type TextBasedChannel, type ThreadChannel, type APIEmbed } from 'discord.js'
import client from '../lib/prisma'
import { type CommandV2 } from '../interfaces/command'
import { ProgressMessageBuilder } from '../lib/progressMessages'
Expand Down Expand Up @@ -97,8 +97,11 @@ export const command: CommandV2 = {
await progress.sendNextStep() // start step 3

for (const [imdbId, series] of seriesList) {
const embed = buildShowEmbed(imdbId, series.series)

try {
const newPost = await createForumPost(interaction.client.channels, series.series, tvForum)
const forumChannel = await interaction.client.channels.fetch(tvForum)
const newPost = await createForumPost(forumChannel, embed, series.series.name)
seriesList.set(imdbId, {
series: series.series,
post: newPost
Expand All @@ -122,10 +125,6 @@ export const command: CommandV2 = {

const show = await saveShowToDB(imdbId, tvDBSeries.id, tvDBSeries.name, post as TextBasedChannel)

await post.send({
embeds: [await buildShowEmbed(imdbId, tvDBSeries, show.destinations)]
})

await updateEpisodes(show.imdbId, show.tvdbId, series.series)

messages.push(`Created post for \`${tvDBSeries.name}\` (${imdbId}) - <#${post.id}>`)
Expand Down Expand Up @@ -200,21 +199,23 @@ async function checkForExistingPosts (imdbId: string, tvForum: string): Promise<
* @param tvForumId discord forum to create a post in
* @returns the created forum thread
*/
async function createForumPost (channels: ChannelManager, tvdbSeries: SeriesExtendedRecord, tvForumId: string): Promise<ThreadChannel<boolean>> {
const forumChannel = await channels.fetch(tvForumId)

if (forumChannel == null || !isForumChannel(forumChannel)) {
async function createForumPost (channel: Channel | null, embed: APIEmbed, seriesName: string): Promise<ThreadChannel<boolean>> {
if (channel == null || !isForumChannel(channel)) {
throw new ProgressError('No tv forum found')
}

// create the forum post
return await forumChannel.threads.create({
name: tvdbSeries.name,
const result = await channel.threads.create({
name: seriesName,
autoArchiveDuration: 10080,
message: {
content: `${tvdbSeries.image}`
embeds: [embed]
}
})

await result.lastMessage?.pin()

return result
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/commands/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const command: CommandV2 = {
}
})

return await interaction.editReply({ embeds: [await buildShowEmbed(imdbId, series, show?.destinations ?? [])] })
return await interaction.editReply({ embeds: [buildShowEmbed(imdbId, series, show?.destinations ?? [])] })
}

const series = await getSeriesByName(query)
Expand All @@ -49,7 +49,7 @@ export const command: CommandV2 = {

if (imdbId == null) return await interaction.editReply('Show not found')

return await interaction.editReply({ embeds: [await buildShowEmbed(imdbId, series, [])] })
return await interaction.editReply({ embeds: [buildShowEmbed(imdbId, series, [])] })
},
async executeAutoComplate (app: App, interaction: AutocompleteInteraction) {
await showSearchAutocomplete(interaction)
Expand Down
2 changes: 1 addition & 1 deletion src/lib/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { type Destination } from '@prisma/client'
import { type APIEmbed, type APIEmbedField } from 'discord.js'
import { type SeriesExtendedRecord } from '../interfaces/tvdb.generated'

export async function buildShowEmbed (imdbId: string, tvdbSeries: SeriesExtendedRecord, destinations: Destination[] = []): Promise<APIEmbed> {
export function buildShowEmbed (imdbId: string, tvdbSeries: SeriesExtendedRecord, destinations: Destination[] = []): APIEmbed {
// put together some basic data fields
const fields: APIEmbedField[] = [
{
Expand Down

0 comments on commit e4af50d

Please sign in to comment.