mirror of
https://github.com/ultrasn0w/huso.git
synced 2025-12-13 17:29:54 +01:00
Delete on completed and fetch on hold
This commit is contained in:
8
ober.go
8
ober.go
@@ -549,7 +549,13 @@ func processUpdateReq(ctx *fasthttp.RequestCtx, update bool) {
|
||||
if update {
|
||||
// anime exitsts => save
|
||||
// get watch progress
|
||||
progress, updated, _ := FetchProgress(anime.Anime, userId, username, 0)
|
||||
progress, updated, listState, _ := FetchProgress(anime.Anime, userId, username, 0)
|
||||
// anime is already completed big baka user
|
||||
if listState == malApiStatusC {
|
||||
ctx.WriteString("Du hast schon fertig geschaut bro")
|
||||
ctx.SetStatusCode(fasthttp.StatusConflict)
|
||||
return
|
||||
}
|
||||
animeData, err = AddUserToAnime(username, userId, anime.Anime, progress, updated)
|
||||
} else {
|
||||
// anime exitsts => delete
|
||||
|
||||
@@ -30,7 +30,7 @@ func Arbeit() {
|
||||
for _, a := range animesUsers {
|
||||
// iterate users
|
||||
for _, u := range a.Users {
|
||||
newProgress, updated, err := FetchProgress(a.Anime, u.MalID, u.Username, u.Progress)
|
||||
newProgress, updated, listState, err := FetchProgress(a.Anime, u.MalID, u.Username, u.Progress)
|
||||
if err != nil {
|
||||
color.Errorln(err.Error())
|
||||
logOut.WriteError(err)
|
||||
@@ -41,21 +41,17 @@ func Arbeit() {
|
||||
}
|
||||
color.Infof("%s progress von %d: %d -> %d\n", u.Username, a.Anime, u.Progress, newProgress)
|
||||
logOut.WriteLine(fmt.Sprintf("📜 %s progress von %d: %d -> %d", u.Username, a.Anime, u.Progress, newProgress))
|
||||
animeData, err := SearchAnime(a.Anime)
|
||||
if err != nil {
|
||||
color.Errorln(err.Error())
|
||||
logOut.WriteError(err)
|
||||
} else {
|
||||
if animeData.Episodes != 0 && newProgress >= animeData.Episodes {
|
||||
color.Infof("%s finished %d\n", u.Username, a.Anime)
|
||||
logOut.WriteLine(fmt.Sprintf("📜 %s finished %d !", u.Username, a.Anime))
|
||||
_, err = DeleteUserFromAnime(u.Username, u.MalID, a.Anime)
|
||||
if err != nil {
|
||||
color.Errorln(err.Error())
|
||||
logOut.WriteError(err)
|
||||
}
|
||||
continue
|
||||
// check if user set anime as completed
|
||||
if listState == malApiStatusC {
|
||||
color.Infof("%s finished %d\n", u.Username, a.Anime)
|
||||
logOut.WriteLine(fmt.Sprintf("📜 %s finished %d !", u.Username, a.Anime))
|
||||
// delete user from anime
|
||||
_, err = DeleteUserFromAnime(u.Username, u.MalID, a.Anime)
|
||||
if err != nil {
|
||||
color.Errorln(err.Error())
|
||||
logOut.WriteError(err)
|
||||
}
|
||||
continue
|
||||
}
|
||||
// update db
|
||||
err = UpdateUserAnimeProgress(a.Anime, u.MalID, newProgress, updated)
|
||||
|
||||
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