mirror of
https://github.com/ultrasn0w/huso.git
synced 2025-12-14 06:29:53 +01:00
Delete on completed and fetch on hold
This commit is contained in:
48
schaffer.go
48
schaffer.go
@@ -145,24 +145,37 @@ func SearchAnime(animeId int64) (*Anime, error) {
|
||||
return anime, err
|
||||
}
|
||||
|
||||
func FetchProgress(animeId, userId int64, username string, progress int) (int, time.Time, error) {
|
||||
func FetchProgress(animeId, userId int64, username string, progress int) (int, time.Time, string, error) {
|
||||
// check watching first
|
||||
list, _, err := GetUserAnimeListData(username, malApiStatusW)
|
||||
newProgress, updated, err := fetchProgressOnState(animeId, userId, progress, username, malApiStatusW)
|
||||
if err != nil {
|
||||
return 0, time.Time{}, err
|
||||
return newProgress, updated, "", err
|
||||
}
|
||||
for _, a := range list.Data {
|
||||
// check if found
|
||||
if a.Node.ID == animeId {
|
||||
// check if progress changed
|
||||
if progress != a.ListStatus.NumEpisodesWatched {
|
||||
return a.ListStatus.NumEpisodesWatched, a.ListStatus.UpdatedAt, nil
|
||||
}
|
||||
return progress, a.ListStatus.UpdatedAt, nil
|
||||
}
|
||||
if newProgress != -1 {
|
||||
return newProgress, updated, malApiStatusW, err
|
||||
}
|
||||
// check on hold
|
||||
newProgress, updated, err = fetchProgressOnState(animeId, userId, progress, username, malApiStatusH)
|
||||
if err != nil {
|
||||
return newProgress, updated, "", err
|
||||
}
|
||||
if newProgress != -1 {
|
||||
return newProgress, updated, malApiStatusH, err
|
||||
}
|
||||
// check completed
|
||||
list, _, err = GetUserAnimeListData(username, malApiStatusC)
|
||||
newProgress, updated, err = fetchProgressOnState(animeId, userId, progress, username, malApiStatusC)
|
||||
if err != nil {
|
||||
return newProgress, updated, "", err
|
||||
}
|
||||
if newProgress != -1 {
|
||||
return newProgress, updated, malApiStatusC, err
|
||||
}
|
||||
// has no progress or dropped
|
||||
return 0, updated, "", nil
|
||||
}
|
||||
|
||||
func fetchProgressOnState(animeId, userId int64, progress int, username, malStatus string) (int, time.Time, error) {
|
||||
list, _, err := GetUserAnimeListData(username, malStatus)
|
||||
if err != nil {
|
||||
return 0, time.Time{}, err
|
||||
}
|
||||
@@ -170,14 +183,11 @@ func FetchProgress(animeId, userId int64, username string, progress int) (int, t
|
||||
// check if found
|
||||
if a.Node.ID == animeId {
|
||||
// check if progress changed
|
||||
if progress != a.ListStatus.NumEpisodesWatched {
|
||||
return a.ListStatus.NumEpisodesWatched, a.ListStatus.UpdatedAt, nil
|
||||
}
|
||||
return progress, a.ListStatus.UpdatedAt, nil
|
||||
return a.ListStatus.NumEpisodesWatched, a.ListStatus.UpdatedAt, nil
|
||||
}
|
||||
}
|
||||
// has no progress or dropped/hold
|
||||
return 0, time.Now(), nil
|
||||
// no progess found
|
||||
return -1, time.Now(), nil
|
||||
}
|
||||
|
||||
func AddToChat(old, new, user string) string {
|
||||
|
||||
Reference in New Issue
Block a user