Stop spamming notifications
This commit is contained in:
@@ -3,7 +3,7 @@ import { Pin, PlanetWithInfo, AccessToken } from '@/types';
|
||||
import { StorageInfo } from '@/types/planet';
|
||||
import { WebhookConfig, WebhookPayload } from '@/types/webhook';
|
||||
import { STORAGE_IDS, LAUNCHPAD_IDS, PI_TYPES_MAP, STORAGE_CAPACITIES, PI_PRODUCT_VOLUMES } from '@/const';
|
||||
import { shouldSendWebhook, markWebhookSent, resetExtractorWebhookStates } from './webhookTracker';
|
||||
import { shouldSendWebhook, markWebhookSent } from './webhookTracker';
|
||||
|
||||
const sendWebhook = async (payload: WebhookPayload): Promise<boolean> => {
|
||||
try {
|
||||
@@ -61,7 +61,8 @@ export const checkExtractorExpiry = async (
|
||||
// Check if extractor has expired
|
||||
if (expiryTime <= now) {
|
||||
console.log(`⏰ Extractor expired: ${extractorType} on ${planet.infoUniverse.name}`);
|
||||
if (shouldSendWebhook(character.character.characterId, planet.planet_id, 'extractor_expired', extractor.pin_id)) {
|
||||
const event = 'done';
|
||||
if (shouldSendWebhook(character.character.characterId, planet.planet_id, extractor.expiry_time, event)) {
|
||||
const payload: WebhookPayload = {
|
||||
type: 'extractor_expired',
|
||||
message: `Extractor producing ${extractorType} has expired on ${planet.infoUniverse.name}`,
|
||||
@@ -75,14 +76,15 @@ export const checkExtractorExpiry = async (
|
||||
};
|
||||
|
||||
if (await sendWebhook(payload)) {
|
||||
markWebhookSent(character.character.characterId, planet.planet_id, 'extractor_expired', extractor.pin_id);
|
||||
markWebhookSent(character.character.characterId, planet.planet_id, extractor.expiry_time, event);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Check if extractor is about to expire
|
||||
else if (timeUntilExpiry <= expiryThreshold) {
|
||||
console.log(`⚠️ Extractor expiring soon: ${extractorType} on ${planet.infoUniverse.name} (${hoursRemaining.toFixed(1)}h remaining)`);
|
||||
if (shouldSendWebhook(character.character.characterId, planet.planet_id, 'extractor_expiring', extractor.pin_id)) {
|
||||
const event = 'nearly done';
|
||||
if (shouldSendWebhook(character.character.characterId, planet.planet_id, extractor.expiry_time, event)) {
|
||||
const payload: WebhookPayload = {
|
||||
type: 'extractor_expiring',
|
||||
message: `Extractor producing ${extractorType} will expire in ${hoursRemaining.toFixed(1)} hours on ${planet.infoUniverse.name}`,
|
||||
@@ -96,14 +98,10 @@ export const checkExtractorExpiry = async (
|
||||
};
|
||||
|
||||
if (await sendWebhook(payload)) {
|
||||
markWebhookSent(character.character.characterId, planet.planet_id, 'extractor_expiring', extractor.pin_id);
|
||||
markWebhookSent(character.character.characterId, planet.planet_id, extractor.expiry_time, event);
|
||||
}
|
||||
}
|
||||
}
|
||||
// If extractor has been reset (duration is "full" again), reset webhook states
|
||||
else if (timeUntilExpiry > expiryThreshold.plus({ hours: 1 })) {
|
||||
resetExtractorWebhookStates(character.character.characterId, planet.planet_id, extractor.pin_id);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user