thesadru / genshin.py

API wrapper for HoYoLAB/Miyoushe API built on asyncio and pydantic.
https://thesadru.github.io/genshin.py
MIT License
405 stars 74 forks source link

Support Honkai Impact daily sign-in #4

Closed thesadru closed 2 years ago

thesadru commented 3 years ago

Since honkai has its own daily sign-in rewards it'd be nice to support it in genshin.py.

The logic is the exact same, only the base url and act id differ. The biggest problem is figuring out how to properly implement it without much repetition.

Currently, users can use:

class HonkaiClient(GenshinClient):
    ACT_ID = "e202110291205111"
    REWARD_URL = "https://api-os-takumi.mihoyo.com/event/mani/"
client = HonkaiClient(...)
client.claim_daily_reward()
BobbyWibowo commented 2 years ago

Anyone else noticing that when using the temporary alternative above, client.claim_daily_rewards() will return reward data strings with Genshin-themed items instead? It will check-in Honkai just fine, just that name and amount parameters will be filled with Genshin-themed items for some reason, lmao

For example, back in March 5th, for me Honkai check-in returned Fine Enhancement Ore x 3 as the reward (Genshin's that day was Adventurer's Experience x 2, so there was seemingly no connection) Then the next day it was Mora for some reason..

I ended up relying on data from client.claimed_rewards(limit=1) as it happens to be always accurate on my case But yeah, it was pretty strange


EDIT:

I looked back into Genshin daily check-in page, and can confirm that the Genshin-themed items were related to my days of Honkai check-in March 5th was Fine Enhancement Ore x 3 because that was my Honkai's 2nd-day daily check-in, and that was indeed the item for day 2 for Genshin (but it was day 6 for my Genshin's hence Adventurer's Experience x 2) Same applied for the following day

So yeah, it seems reward data strings for client.claim_daily_rewards() will somehow use Genshin's, but client.claimed_rewards() will correctly use Honkai's

I also noticed that if you had already checked-in that day, client.claim_daily_rewards() would also correctly use Honkai's It'd just use Genshin's when you hadn't checked-in


Again, this only affect the reward data strings as returned by the function It will still check-in Honkai just fine regardless of what it returns

thesadru commented 2 years ago

Could you please enable debug mode to see the endpoints that are being requested?

BobbyWibowo commented 2 years ago

Turned it on earlier, and tried with just Honkai check-in, and it successfully used Honkai data strings (endpoints were correct)

Hmm, I think it must have been an error on my part I ran my Genshin and Honkai check-in concurrently , and Genshin's code was made to be called slightly earlier, so perhaps back then it was some racing something with Genshin endpoint url in the lib side maybe My bad, not too used to Python yet 🙏

BobbyWibowo commented 2 years ago

Here I am again.. 😅

But yeah, it apparently didn't seem to be caused by running both check-ins concurrently Even when running them in sequence, where a previous client.close() was also properly awaited before proceeding to init a new client, Honkai's rewards still go all funky Based on endpoint logging, nothing seemed out of place, but rewards data still go funky

Logs I didn't clean up unrelated lines to reflect the full timeline ``` 16:14:03 INFO Starting... 16:14:03 INFO You have 1 「thesadru/genshin.py」 account configured. 16:14:03 INFO Preparing to perform task for account 1... 16:14:03 INFO Preparing to get user game roles information... 16:14:03 DEBUG GET https://api-os-takumi.mihoyo.com/binding/api/getUserGameRolesByCookie 16:14:05 INFO Preparing to claim daily reward... 16:14:05 DEBUG POST https://hk4e-api-os.mihoyo.com/event/sol/sign?lang=en-us&act_id=e202102251931481 16:14:05 DEBUG GET https://hk4e-api-os.mihoyo.com/event/sol/info?lang=en-us&act_id=e202102251931481 16:14:06 INFO client.claim_daily_reward() => Fine Enhancement Ore x 5 16:14:06 INFO Preparing to get monthly rewards information... 16:14:06 DEBUG GET https://hk4e-api-os.mihoyo.com/event/sol/info?lang=en-us&act_id=e202102251931481 16:14:06 INFO Preparing to get traveler's diary... 16:14:06 DEBUG GET https://api-os-takumi.mihoyo.com/binding/api/getUserGameRolesByCookie 16:14:07 DEBUG GET https://hk4e-api-os.mihoyo.com/event/ysledgeros/month_info?uid=817303828®ion=os_asia&month=3&lang=en-us 16:14:08 INFO You have 1 「thesadru/genshin.py-honkai」 account configured. 16:14:08 INFO Preparing to perform task for account 1... 16:14:08 INFO Preparing to claim daily reward... 16:14:08 DEBUG POST https://api-os-takumi.mihoyo.com/event/mani/sign?lang=en-us&act_id=e202110291205111 16:14:09 DEBUG GET https://api-os-takumi.mihoyo.com/event/mani/info?lang=en-us&act_id=e202110291205111 16:14:09 INFO client.claim_daily_reward() => Fried Radish Balls x 3 16:14:09 INFO Preparing to get monthly rewards information... 16:14:09 DEBUG GET https://api-os-takumi.mihoyo.com/event/mani/info?lang=en-us&act_id=e202110291205111 ```

I let it run for 2 days in a row and data was funky for both days

thesadru commented 2 years ago

I think I have identified the issue. The monthly reward cache does not differentiate between different games.

For a temporary fix you can do:

class HonkaiClient(genshin.GenshinClient):
    ACT_ID = "e202110291205111"
    REWARD_URL = "https://api-os-takumi.mihoyo.com/event/mani/"

    async def get_monthly_rewards(self, *, lang: str = None) -> List[genshin.DailyReward]:
        data = await self.request_daily_reward("home", lang=lang)
        return [genshin.DailyReward(**i) for i in data["awards"]]
thesadru commented 2 years ago

This is now supported since 1.0.0