Fix all rooms being affected by speedbump

This commit is contained in:
Cadence Ember 2024-01-22 22:05:59 +13:00
parent 11864f80cf
commit 6a06dc14ce
3 changed files with 13 additions and 10 deletions

View file

@ -11,7 +11,7 @@ const speedbump = sync.require("./speedbump")
* @param {import("discord-api-types/v10").GatewayMessageDeleteDispatchData} data
*/
async function deleteMessage(data) {
const row = select("channel_room", ["room_id", "speedbump_id", "speedbump_checked"], {channel_id: data.channel_id}).get()
const row = select("channel_room", ["room_id", "speedbump_checked"], {channel_id: data.channel_id}).get()
if (!row) return
const eventsToRedact = select("event_message", "event_id", {message_id: data.id}).pluck().all()
@ -22,7 +22,7 @@ async function deleteMessage(data) {
await api.redactEvent(row.room_id, eventID)
}
speedbump.updateCache(data.channel_id, row.speedbump_id, row.speedbump_checked)
speedbump.updateCache(data.channel_id, row.speedbump_checked)
}
/**

View file

@ -15,12 +15,11 @@ const KNOWN_BOTS = new Set([
/**
* Fetch new speedbump data for the channel and put it in the database as cache
* @param {string} channelID
* @param {string?} speedbumpID
* @param {number?} speedbumpChecked
* @param {number?} lastChecked
*/
async function updateCache(channelID, speedbumpID, speedbumpChecked) {
async function updateCache(channelID, lastChecked) {
const now = Math.floor(Date.now() / 1000)
if (speedbumpChecked && now - speedbumpChecked < SPEEDBUMP_UPDATE_FREQUENCY) return
if (lastChecked && now - lastChecked < SPEEDBUMP_UPDATE_FREQUENCY) return
const webhooks = await discord.snow.webhook.getChannelWebhooks(channelID)
const found = webhooks.find(b => KNOWN_BOTS.has(b.application_id))
const foundApplication = found?.application_id