fix(bots/discord): await when putting entries into db

This commit is contained in:
PalmDevs
2024-08-04 02:51:49 +07:00
parent d90ad5c955
commit 4da6175cf5
2 changed files with 11 additions and 14 deletions

View File

@@ -40,7 +40,7 @@ withContext(on, 'messageCreate', async (context, msg) => {
})
if (label) {
db.insert(responses).values({
await db.insert(responses).values({
replyId: reply.id,
channelId: reply.channel.id,
guildId: reply.guild!.id,

View File

@@ -20,7 +20,8 @@ const PossibleReactions = Object.values(Reactions) as string[]
withContext(on, 'messageReactionAdd', async (context, rct, user) => {
if (user.bot) return
await rct.users.remove(user.id)
const { database: db, logger, config } = context
const { messageScan: msConfig } = config
@@ -35,10 +36,7 @@ withContext(on, 'messageReactionAdd', async (context, rct, user) => {
if (!isAdmin(reactionMessage.member || reactionMessage.author)) {
// User is in guild, and config has member requirements
if (
reactionMessage.inGuild() &&
(msConfig.humanCorrections.allow?.members || msConfig.humanCorrections.allow?.users)
) {
if (reactionMessage.inGuild() && msConfig.humanCorrections.allow) {
const {
allow: { users: allowedUsers, members: allowedMembers },
} = msConfig.humanCorrections
@@ -54,20 +52,19 @@ withContext(on, 'messageReactionAdd', async (context, rct, user) => {
)
)
return
} else if (allowedUsers) {
if (!allowedUsers.includes(user.id)) return
} else {
return void logger.warn(
'No member or user requirements set for human corrections, all requests will be ignored',
)
}
}
} else if (!allowedUsers?.includes(user.id)) return
} else
return void logger.warn(
'No member or user requirements set for human corrections, all requests will be ignored',
)
}
// Sanity check
const response = await db.query.responses.findFirst({ where: eq(responses.replyId, rct.message.id) })
if (!response || response.correctedById) return
logger.debug(`User ${user.id} is trying to correct the response ${rct.message.id}`)
const handleCorrection = (label: string) =>
handleUserResponseCorrection(context, response, reactionMessage, label, user)