refactor: patcher + fullplay workflow

This commit is contained in:
2026-07-07 17:15:15 +08:00
parent 07e816bc83
commit 069e9aeae9

View File

@@ -1,6 +1,7 @@
import json import json
import asyncio import asyncio
import logging import logging
from typing import Callable
import httpx import httpx
@@ -23,12 +24,62 @@ logging.basicConfig(
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
async def run_workflow( def music_user_all_patcher(
self: MaimaiClient,
musicId: int, musicId: int,
unlock_music: bool = True, unlock_music: bool = True,
unlock_master: bool = False, unlock_master: bool = False,
unlock_remaster: bool = False, unlock_remaster: bool = False,
) -> Callable[[dict], None]:
userItemList = []
if unlock_music:
userItemList.append(
0,
{
"itemKind": 5, # MUSIC
"itemId": musicId,
"stock": 1,
"isValid": True,
},
)
if unlock_master:
userItemList.append(
0,
{
"itemKind": 6,
"itemId": musicId, # MASTER
"stock": 1,
"isValid": True,
},
)
if unlock_remaster:
userItemList.append(
{
"itemKind": 7,
"itemId": musicId, # RE: MASTER
"stock": 1,
"isValid": True,
}
)
def merge(d: dict):
d.update(
{
"userMusicDetailList": [musicData],
"isNewMusicDetailList": "1",
"userItemList": userItemList,
"isNewItemList": len(userItemList) * "1",
}
)
return merge
async def run_workflow(
self: MaimaiClient,
user_all_patcher: Callable[[dict], None],
): ):
async with httpx.AsyncClient(verify=False) as client: async with httpx.AsyncClient(verify=False) as client:
@@ -78,46 +129,7 @@ async def run_workflow(
loginId, loginDate, musicData, GeneralUserInfo loginId, loginDate, musicData, GeneralUserInfo
) )
userItemList = [] user_all_patcher(requestData_UserAll)
if unlock_music:
userItemList.append(
0,
{
"itemKind": 5, # MUSIC
"itemId": musicId,
"stock": 1,
"isValid": True,
},
)
if unlock_master:
userItemList.append(
0,
{
"itemKind": 6,
"itemId": musicId, # MASTER
"stock": 1,
"isValid": True,
},
)
if unlock_remaster:
userItemList.append(
{
"itemKind": 7,
"itemId": musicId, # RE: MASTER
"stock": 1,
"isValid": True,
}
)
requestData_UserAll |= {
"userMusicDetailList": [musicData],
"isNewMusicDetailList": "1",
"userItemList": userItemList,
"isNewItemList": len(userItemList) * "1",
}
await self.call_api(client, "UpsertUserAllApi", requestData_UserAll, userId) await self.call_api(client, "UpsertUserAllApi", requestData_UserAll, userId)
@@ -127,12 +139,16 @@ async def run_workflow(
if __name__ == "__main__": if __name__ == "__main__":
patcher = music_user_all_patcher(
musicId=834,
unlock_music=False,
# unlock_master=True,
unlock_remaster=True,
)
asyncio.run( asyncio.run(
run_workflow( run_workflow(
maimai, maimai,
musicId=834, user_all_patcher=patcher,
unlock_music=False,
# unlock_master=True,
unlock_remaster=True,
) )
) )