diff --git a/src/modules/foxwells.js b/src/modules/foxwells.js index ae238bb..febbcf0 100644 --- a/src/modules/foxwells.js +++ b/src/modules/foxwells.js @@ -243,6 +243,7 @@ async function createBoardMessage(msg, count) { username: msg.member?.displayName ?? msg.author.username, threadID: VINBOARD_THREAD_ID, embeds: [embed], + attachments: image.file ? [{filename: "thumb.jpg"}] : null, files: image.file ? [{file: image.file, filename: "thumb.jpg"}] : null, wait: true, }; @@ -250,6 +251,7 @@ async function createBoardMessage(msg, count) { let vinboard_webhook; let vin_channel; +let board_channel; async function processReaction(_msg, user, reaction) { if (_msg.guildID != FOXWELLS_GUILD_ID) return; if (_msg.channel.id != VINBOARD_CHANNEL_ID) return; @@ -267,6 +269,15 @@ async function processReaction(_msg, user, reaction) { return; } + if (!board_channel) { + vin_channel.threads.get(VINBOARD_THREAD_ID); + } + + if (!board_channel) { + logger.error("vinboard", "Failed to get thread."); + return; + } + const msg = vin_channel.messages.get(_msg.id) ?? (await vin_channel.getMessage(_msg.id)); @@ -289,6 +300,7 @@ async function processReaction(_msg, user, reaction) { ).length; const dbEntry = getBoardEntry(msg.id); + logger.debug("vinboard", JSON.stringify(dbEntry)); if (dbEntry) { if (trueCount == 0) { logger.verbose("vinboard", `Deleting entry for "${msg.id}"`); @@ -301,23 +313,26 @@ async function processReaction(_msg, user, reaction) { } } else { if (dbEntry.board_id) { - logger.verbose( - "vinboard", - `Updating count for "${msg.id}" (${ - dbEntry.count ?? 0 - } -> ${trueCount})` - ); - await webhook.editMessage( - dbEntry.board_id, - await createBoardMessage(msg, trueCount) - ); - await setBoardEntry(msg.id, trueCount, dbEntry.board_id); - } else { - logger.verbose("vinboard", `Creating entry for "${msg.id}"`); - const boardMessage = await vinboard_webhook.execute( - await createBoardMessage(msg, trueCount) - ); - await setBoardEntry(msg.id, trueCount, boardMessage.id); + const _boardMessage = await board_channel.getMessage(dbEntry.board_id); + if (_boardMessage) { + logger.verbose( + "vinboard", + `Updating count for "${msg.id}" (${ + dbEntry.count ?? 0 + } -> ${trueCount})` + ); + await webhook.editMessage( + _boardMessage.id, + await createBoardMessage(msg, trueCount) + ); + await setBoardEntry(msg.id, trueCount, dbEntry.board_id); + } else { + logger.verbose("vinboard", `Creating entry for "${msg.id}"`); + const boardMessage = await vinboard_webhook.execute( + await createBoardMessage(msg, trueCount) + ); + await setBoardEntry(msg.id, trueCount, boardMessage.id); + } } } } else { @@ -325,7 +340,6 @@ async function processReaction(_msg, user, reaction) { const boardMessage = await vinboard_webhook.execute( await createBoardMessage(msg, trueCount) ); - logger.debug("vinboard", JSON.stringfy(boardMessage)); await setBoardEntry(msg.id, trueCount, boardMessage.id); } }