From 10a563bb2386b9f55c14e8a1ec8939e4de4e7b17 Mon Sep 17 00:00:00 2001 From: daru Date: Mon, 18 Jul 2022 18:01:24 +0200 Subject: [PATCH] AnnounceAppointmentSoon --- labersack.go | 47 ++++++++++++++++++++++++++++++++++++++++++++++- praktikant.go | 3 +++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/labersack.go b/labersack.go index 9a45682..d90b45a 100644 --- a/labersack.go +++ b/labersack.go @@ -30,7 +30,7 @@ func SendAppointBroadcast(creator string, app *Appointment) { msgStart.WriteString(fmt.Sprintf("<@%d>", uData.DiscordID)) } - msgs := fmt.Sprintf("🗓️ New appointment for [%s](https://anime.hanami.family/anime/%d) at ", anime.Title, app.Anime, app.Time.Unix(), app.Time.Unix()) + msgs := fmt.Sprintf("🗓️ New appointment for [%s](https://anime.hanami.family/anime/%d) at\n\n", anime.Title, app.Anime, app.Time.Unix(), app.Time.Unix()) msge := discordgo.MessageEmbed{ Description: msgs, URL: fmt.Sprintf("https://anime.hanami.family/anime/%d", app.Anime), @@ -61,3 +61,48 @@ func SendAppointBroadcast(creator string, app *Appointment) { } } } + +func AnnounceAppointmentSoon(app *Appointment) { + if app != nil && discc != nil { + watchData, err := GetAnimeWatchFromDb(app.Anime) + if err != nil { + color.Errorln(err.Error()) + return + } + anime, err := SearchAnime(app.Anime) + if err != nil { + color.Errorln(err.Error()) + return + } + + var msgStart strings.Builder + for _, u := range watchData.Users { + uData, err := ReadUser(u.Username) + if err != nil || uData.DiscordID == 0 { + continue + } + msgStart.WriteString(fmt.Sprintf("<@%d>", uData.DiscordID)) + } + + msgs := fmt.Sprintf("⏰ Appointment starting in !\n[%s](https://anime.hanami.family/anime/%d) at\n", app.Time.Unix(), anime.Title, app.Anime, app.Time.Unix()) + msge := discordgo.MessageEmbed{ + Description: msgs, + URL: fmt.Sprintf("https://anime.hanami.family/anime/%d", app.Anime), + Thumbnail: &discordgo.MessageEmbedThumbnail{URL: anime.ImageLargeURL}, + Color: 7187428, + Footer: &discordgo.MessageEmbedFooter{ + Text: "huso " + husoVersion, + }, + } + + msgc := discordgo.MessageSend{ + Content: msgStart.String(), + Embeds: []*discordgo.MessageEmbed{&msge}, + } + _, err = discc.ChannelMessageSendComplex("998277590609559632", &msgc) + + if err != nil { + color.Errorln(err.Error()) + } + } +} diff --git a/praktikant.go b/praktikant.go index f8c9774..9766561 100644 --- a/praktikant.go +++ b/praktikant.go @@ -38,6 +38,9 @@ func Arbeit() { } else { cleared++ } + } else if a.Time.Add(time.Hour).Before(time.Now()) { + // This is happening soon + AnnounceAppointmentSoon(&a) } } if cleared > 0 {