AnnounceAppointmentSoon

This commit is contained in:
daru
2022-07-18 18:01:24 +02:00
parent ecba4d68e6
commit 10a563bb23
2 changed files with 49 additions and 1 deletions

View File

@@ -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 <t:%d:F> <t:%d:R>", 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<t:%d:F>\n<t:%d:R>", 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 <t:%d:R>!\n[%s](https://anime.hanami.family/anime/%d) at\n<t:%d:F>", 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())
}
}
}

View File

@@ -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 {