initial commit
This commit is contained in:
45
send_condition.go
Normal file
45
send_condition.go
Normal file
@ -0,0 +1,45 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"git.tordarus.net/nyaanime/model"
|
||||
"git.tordarus.net/tordarus/anilist"
|
||||
)
|
||||
|
||||
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")
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user