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) { if (label) {
db.insert(responses).values({ await db.insert(responses).values({
replyId: reply.id, replyId: reply.id,
channelId: reply.channel.id, channelId: reply.channel.id,
guildId: reply.guild!.id, guildId: reply.guild!.id,

View File

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