package main import ( "errors" "strings" "git.milar.in/milarin/anilist" "git.milar.in/nyaanime/model" ) type SendCondition string var AllSendConditions = []SendCondition{SendConditionOnList, SendConditionAlways, SendConditionPlanned, SendConditionNotWatched} const ( SendConditionOnList = "ON_LIST" SendConditionAlways = "ALWAYS" SendConditionPlanned = "PLANNED" SendConditionNotWatched = "NOT_WATCHED" ) func SendConditionFromString(str string) (SendCondition, error) { str = strings.ToLower(str) for _, condition := range AllSendConditions { if str == strings.ToLower(string(condition)) { return condition, nil } } return SendCondition(""), errors.New("invalid message send condition") } func (c SendCondition) ShouldSend(animeEp model.AnimeEpisode, listEntry *anilist.MediaList) bool { switch c { case SendConditionOnList: return listEntry != nil case SendConditionPlanned: return listEntry != nil && listEntry.Status == anilist.MediaListStatusPlanning case SendConditionNotWatched: return listEntry != nil && listEntry.Progress < animeEp.Episode case SendConditionAlways: return true default: panic("invalid telegram message send condition") } }