2020-10-01 01:43:38 +03:00
|
|
|
import { SECONDS } from "../../../utils";
|
2020-07-08 02:53:44 +02:00
|
|
|
import { removeUserIdFromActiveAlerts } from "./removeUserIdFromActiveAlerts";
|
2020-10-01 01:43:38 +03:00
|
|
|
import { GuildPluginData } from "knub";
|
|
|
|
import { LocateUserPluginType } from "../types";
|
2020-07-08 02:53:44 +02:00
|
|
|
|
|
|
|
const ALERT_LOOP_TIME = 30 * SECONDS;
|
|
|
|
|
2020-10-01 01:43:38 +03:00
|
|
|
export async function outdatedAlertsLoop(pluginData: GuildPluginData<LocateUserPluginType>) {
|
2020-07-08 02:53:44 +02:00
|
|
|
const outdatedAlerts = await pluginData.state.alerts.getOutdatedAlerts();
|
|
|
|
|
|
|
|
for (const alert of outdatedAlerts) {
|
|
|
|
await pluginData.state.alerts.delete(alert.id);
|
|
|
|
await removeUserIdFromActiveAlerts(pluginData, alert.user_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pluginData.state.unloaded) {
|
2020-07-22 22:56:21 +03:00
|
|
|
pluginData.state.outdatedAlertsTimeout = setTimeout(() => outdatedAlertsLoop(pluginData), ALERT_LOOP_TIME);
|
2020-07-08 02:53:44 +02:00
|
|
|
}
|
|
|
|
}
|