Fix duplicate streamWatching, locale guild et console log/error
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 3m43s
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 3m43s
This commit is contained in:
@@ -9,6 +9,7 @@ import type {
|
||||
} from "@/types/freebox"
|
||||
import type { GuildFbx } from "@/types/schemas"
|
||||
import { t } from "@/utils/i18n"
|
||||
import { logConsole } from "@/utils/console"
|
||||
|
||||
const app: TokenRequest = {
|
||||
app_id: "fr.angels-dev.tamiseur",
|
||||
@@ -123,7 +124,7 @@ export const Timer = {
|
||||
// Stocker les références des timers
|
||||
activeTimers.set(guildId, { morning: morningTimer, night: nightTimer })
|
||||
|
||||
console.log(`[Freebox LCD] Timer programmé pour ${guildId} - Allumage: ${nextMorning.toLocaleString()}, Extinction: ${nextNight.toLocaleString()}`)
|
||||
logConsole('freebox', 'timer_scheduled', { guildId, nextMorning: nextMorning.toLocaleString(), nextNight: nextNight.toLocaleString() })
|
||||
},
|
||||
|
||||
// Fonction utilitaire pour calculer la prochaine occurrence d'une heure donnée
|
||||
@@ -131,10 +132,7 @@ export const Timer = {
|
||||
const target = new Date(now.getFullYear(), now.getMonth(), now.getDate(), hour, minute, 0, 0)
|
||||
|
||||
// Si l'heure cible est déjà passée aujourd'hui, programmer pour demain
|
||||
if (target <= now) {
|
||||
target.setDate(target.getDate() + 1)
|
||||
}
|
||||
|
||||
if (target <= now) target.setDate(target.getDate() + 1)
|
||||
return target
|
||||
},
|
||||
|
||||
@@ -145,7 +143,7 @@ export const Timer = {
|
||||
if (timers.morning) clearTimeout(timers.morning)
|
||||
if (timers.night) clearTimeout(timers.night)
|
||||
activeTimers.delete(guildId)
|
||||
console.log(`[Freebox LCD] Timers nettoyés pour ${guildId}`)
|
||||
logConsole('freebox', 'timers_cleaned', { guildId })
|
||||
}
|
||||
},
|
||||
|
||||
@@ -154,39 +152,36 @@ export const Timer = {
|
||||
for (const [guildId] of activeTimers) {
|
||||
Timer.clear(guildId)
|
||||
}
|
||||
console.log(`[Freebox LCD] Tous les timers ont été nettoyés`)
|
||||
logConsole('freebox', 'all_timers_cleaned')
|
||||
},
|
||||
|
||||
// Fonction pour contrôler les LEDs
|
||||
async controlLeds(guildId: string, dbDataFbx: GuildFbx, enabled: boolean) {
|
||||
if (!dbDataFbx.host || !dbDataFbx.appToken) {
|
||||
console.error(`[Freebox LCD] Configuration manquante pour le serveur ${guildId}`)
|
||||
return
|
||||
}
|
||||
if (!dbDataFbx.host || !dbDataFbx.appToken) { logConsole('freebox', 'missing_configuration', { guildId }); return }
|
||||
|
||||
try {
|
||||
// Obtenir le challenge
|
||||
const challengeData = await Login.Challenge(dbDataFbx.host) as APIResponseData<GetChallenge>
|
||||
if (!challengeData.success) { console.error(`[Freebox LCD] Erreur lors de la récupération du challenge pour ${guildId}`); return }
|
||||
if (!challengeData.success) { logConsole('freebox', 'challenge_error', { guildId }); return }
|
||||
|
||||
const challenge = challengeData.result.challenge
|
||||
if (!challenge) { console.error(`[Freebox LCD] Challenge introuvable pour ${guildId}`); return }
|
||||
if (!challenge) { logConsole('freebox', 'challenge_not_found', { guildId }); return }
|
||||
|
||||
// Créer la session
|
||||
const password = crypto.createHmac("sha1", dbDataFbx.appToken).update(challenge).digest("hex")
|
||||
const sessionData = await Login.Session(dbDataFbx.host, password) as APIResponseData<OpenSession>
|
||||
if (!sessionData.success) { console.error(`[Freebox LCD] Erreur lors de la création de la session pour ${guildId}`); return }
|
||||
if (!sessionData.success) { logConsole('freebox', 'session_error', { guildId }); return }
|
||||
|
||||
const sessionToken = sessionData.result.session_token
|
||||
if (!sessionToken) { console.error(`[Freebox LCD] Token de session introuvable pour ${guildId}`); return }
|
||||
if (!sessionToken) { logConsole('freebox', 'session_token_not_found', { guildId }); return }
|
||||
|
||||
// Contrôler les LEDs
|
||||
const lcdData = await Set.LcdConfig(dbDataFbx.host, sessionToken, { led_strip_enabled: enabled }) as APIResponseData<LcdConfig>
|
||||
if (!lcdData.success) { console.error(`[Freebox LCD] Erreur lors du contrôle des LEDs pour ${guildId}:`, lcdData); return }
|
||||
if (!lcdData.success) { logConsole('freebox', 'leds_control_error', { guildId }); return }
|
||||
|
||||
console.log(`[Freebox LCD] LEDs ${enabled ? 'allumées' : 'éteintes'} avec succès pour ${guildId}`)
|
||||
} catch (error) {
|
||||
console.error(`[Freebox LCD] Erreur lors du contrôle des LEDs pour ${guildId}:`, error)
|
||||
logConsole('freebox', 'leds_success', { status: enabled ? 'allumées' : 'éteintes', guildId })
|
||||
} catch {
|
||||
logConsole('freebox', 'leds_error', { guildId })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user