2024-11-17 23:27:56 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-11-18 00:45:26 +00:00
|
|
|
"fmt"
|
2024-11-17 23:27:56 +00:00
|
|
|
"log"
|
2024-11-18 00:45:26 +00:00
|
|
|
"net/http"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"gitea.dmz.rs/txrpe/event-bot/chatbot"
|
|
|
|
"github.com/apognu/gocal"
|
2024-11-17 23:27:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2024-11-18 00:45:26 +00:00
|
|
|
resp, err := http.Get("https://dmz.rs/events.ical")
|
|
|
|
if err != nil {
|
|
|
|
// handle err
|
|
|
|
// todo add log
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
defer resp.Body.Close()
|
|
|
|
cal := gocal.NewParser(resp.Body)
|
|
|
|
|
|
|
|
start, end := time.Now(), time.Now().Add(24*time.Hour)
|
|
|
|
cal.Start = &start
|
|
|
|
cal.End = &end
|
|
|
|
|
|
|
|
cal.Parse()
|
|
|
|
if len(cal.Events) == 0 {
|
|
|
|
// Maybe change this to some kind of logs
|
|
|
|
fmt.Printf("No events today :(")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
e := cal.Events[0]
|
|
|
|
message := fmt.Sprint("Veceras u decentrali:\n", e.Summary, "\n", e.URL, "\n", e.Location, " ", e.Start.Format(time.Kitchen))
|
|
|
|
|
2024-11-17 23:27:56 +00:00
|
|
|
nkbot, err := chatbot.NewEventBot()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2024-11-18 00:45:26 +00:00
|
|
|
nkbot.SendMessage(message)
|
2024-11-17 23:27:56 +00:00
|
|
|
}
|