foxwells.vinboard: figuring out why not getting from db properly

This commit is contained in:
Cynthia Foxwell 2022-12-02 23:42:42 -07:00
parent c02e85aafe
commit bb62bc8c0a

View file

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