foxwells.vinboard: figuring out why not getting from db properly
This commit is contained in:
parent
c02e85aafe
commit
bb62bc8c0a
1 changed files with 32 additions and 18 deletions
|
@ -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,6 +313,8 @@ async function processReaction(_msg, user, reaction) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (dbEntry.board_id) {
|
if (dbEntry.board_id) {
|
||||||
|
const _boardMessage = await board_channel.getMessage(dbEntry.board_id);
|
||||||
|
if (_boardMessage) {
|
||||||
logger.verbose(
|
logger.verbose(
|
||||||
"vinboard",
|
"vinboard",
|
||||||
`Updating count for "${msg.id}" (${
|
`Updating count for "${msg.id}" (${
|
||||||
|
@ -308,7 +322,7 @@ async function processReaction(_msg, user, reaction) {
|
||||||
} -> ${trueCount})`
|
} -> ${trueCount})`
|
||||||
);
|
);
|
||||||
await webhook.editMessage(
|
await webhook.editMessage(
|
||||||
dbEntry.board_id,
|
_boardMessage.id,
|
||||||
await createBoardMessage(msg, trueCount)
|
await createBoardMessage(msg, trueCount)
|
||||||
);
|
);
|
||||||
await setBoardEntry(msg.id, trueCount, dbEntry.board_id);
|
await setBoardEntry(msg.id, trueCount, dbEntry.board_id);
|
||||||
|
@ -320,12 +334,12 @@ async function processReaction(_msg, user, reaction) {
|
||||||
await setBoardEntry(msg.id, trueCount, boardMessage.id);
|
await setBoardEntry(msg.id, trueCount, boardMessage.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
logger.verbose("vinboard", `Creating entry for "${msg.id}"`);
|
logger.verbose("vinboard", `Creating entry for "${msg.id}"`);
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue