Skip to content

Commit

Permalink
Catch more errors when broadcasting follows
Browse files Browse the repository at this point in the history
  • Loading branch information
Tibowl committed Apr 12, 2021
1 parent e1ddf54 commit 3abf4a1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/utils/FollowManager.ts
Expand Up @@ -111,11 +111,15 @@ export default class FollowManager {
channels = channels.filter((val, ind) => channels.indexOf(val) === ind)

Logger.info(`Sending ${category} to ${channels.length} channels: ${content}`)
const messages = (await sendToChannels(channels, content, embed)).flat()
const messages = (await sendToChannels(channels, content, embed)).filter((x): x is PromiseFulfilledResult<Message | Message[]> => x.status == "fulfilled").map(x => x.value).flat()

for (const message of messages)
if (message instanceof Message && message.channel.type === "news")
await message.crosspost()
try {
await message.crosspost()
} catch (error) {
Logger.error(`Unable to publish to ${message.channel.id} from ${message.guild?.id}: `, error)
}

return messages
}
Expand Down
8 changes: 4 additions & 4 deletions src/utils/Utils.ts
Expand Up @@ -14,7 +14,7 @@ const Logger = log4js.getLogger("Utils")
* @param embed Possible embed/attachment to send
* @returns All the messages send
*/
export async function sendToChannels(channels: string[] | undefined, content: StringResolvable, embed?: MessageEmbed | MessageAttachment): Promise<(Message | Message[])[]> {
export async function sendToChannels(channels: string[] | undefined, content?: StringResolvable, embed?: MessageEmbed | MessageAttachment): Promise<PromiseSettledResult<Message | Message[]>[]> {
const messages = []
if (!channels) return Promise.all([])

Expand All @@ -33,7 +33,7 @@ export async function sendToChannels(channels: string[] | undefined, content: St
}
}

return Promise.all(messages)
return Promise.allSettled(messages)
}

/**
Expand All @@ -42,9 +42,9 @@ export async function sendToChannels(channels: string[] | undefined, content: St
* @param embed Possible embed/attachment to send
* @returns List of messages
*/
export async function sendError(content: StringResolvable, embed?: MessageEmbed | MessageAttachment): Promise<(Message | Message[])[]> {
export async function sendError(content: StringResolvable, embed?: MessageEmbed | MessageAttachment): Promise<Message[]> {
Logger.error(content)
return sendToChannels(config.errorLog, content, embed)
return (await sendToChannels(config.errorLog, content, embed)).filter((x): x is PromiseFulfilledResult<Message | Message[]> => x.status == "fulfilled").map(x => x.value).flat()
}

export const PAD_START = 0
Expand Down

0 comments on commit 3abf4a1

Please sign in to comment.