package main import ( "fmt" "strings" "github.com/bwmarrin/discordgo" "github.com/gookit/color" ) func SendAppointBroadcast(creator string, 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("🗓️ New appointment for [%s](https://anime.hanami.family/anime/%d) at ", anime.Title, app.Anime, app.Time.Unix(), app.Time.Unix()) msgc := discordgo.MessageSend{ Content: msgStart.String(), Embeds: []*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, }, }}, } user, _, err := GetUserData(creator) if err == nil { msgc.Embed.Author = &discordgo.MessageEmbedAuthor{ Name: user.Username, IconURL: user.ImageURL, URL: fmt.Sprintf("https://anime.hanami.family/user/%s", creator), } } _, err = discc.ChannelMessageSendComplex("998277590609559632", &msgc) if err != nil { color.Errorln(err.Error()) } } }