Del: leftovers

This commit is contained in:
Óscar M. Lage 2024-11-28 23:24:17 +01:00
parent 503e8bf5b2
commit ae88ec1b9b

View File

@ -83,41 +83,3 @@ func ProcesarMensaje(update tgbotapi.Update, db *gorm.DB) {
log.Printf("Evento %s registrado con éxito para el %s", command, timestamp.Format("2006-01-02 15:04"))
}
func ProcesarMensaje2(update tgbotapi.Update, db *gorm.DB) {
if update.Message == nil || update.Message.Text == "" {
return
}
parts := strings.Fields(update.Message.Text)
command := strings.ToUpper(parts[0])
var timestamp time.Time
if len(parts) == 1 {
timestamp = update.Message.Time()
} else {
parsedTime, err := time.Parse("15:04", parts[1])
if err != nil {
log.Println("Formato de hora inválido:", parts[1])
return
}
now := time.Now()
timestamp = time.Date(now.Year(), now.Month(), now.Day(), parsedTime.Hour(), parsedTime.Minute(), 0, 0, now.Location())
}
if command != "ON" && command != "OFF" {
log.Println("Comando desconocido:", command)
return
}
event := HeatingEvent{
EventType: command,
Timestamp: timestamp,
}
if err := db.Create(&event).Error; err != nil {
log.Printf("Error al guardar el evento %s: %v", command, err)
return
}
log.Printf("Evento %s registrado con éxito a las %s", command, timestamp.Format("15:04"))
}