Skip to content

Commit

Permalink
更改 SGP Token 的获取方法
Browse files Browse the repository at this point in the history
  • Loading branch information
Zzaphkiel committed Nov 12, 2024
1 parent f0ee151 commit a0dbd34
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
17 changes: 8 additions & 9 deletions app/lol/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def __init__(self):
self.token = None
self.sgpToken = None
self.server = None
self.inMainLand = False
self.inTencent = False

self.manager = None
self.perksStyleCache = None
Expand Down Expand Up @@ -357,10 +357,10 @@ async def __initManager(self):

def __initPlatformInfo(self):
if self.server:
mainlandPlatforms = {'tj100', 'hn1', 'cq100',
'gz100', 'nj100', 'hn10', 'tj101', 'bgp2'}
platforms = {'tj100', 'hn1', 'cq100',
'gz100', 'nj100', 'hn10', 'tj101', 'bgp2'}

self.inMainLand = self.server.lower() in mainlandPlatforms
self.inTencent = self.server.lower() in platforms

async def __initRuneStyle(self):
res = {}
Expand Down Expand Up @@ -1083,8 +1083,7 @@ async def getReplayPath(self):

@retry()
async def getSGPtoken(self):
res = await self.__get("/entitlements/v1/token")
res = await res.json()
res = await self.__json_retry_get("/entitlements/v1/token")

if 'accessToken' not in res:
raise ReferenceError()
Expand Down Expand Up @@ -1143,8 +1142,8 @@ async def getSummonerByPuuidViaSGP(self, puuid):
res = await self.__sgp__get(url)
return await res.json()

def isInMainland(self):
return self.inMainLand
def isInTencent(self):
return self.inTencent

@needLcu()
async def __get(self, path, params=None):
Expand All @@ -1168,7 +1167,7 @@ async def __patch(self, path, data=None):
return await self.lcuSess.patch(path, json=data, ssl=False)

async def __sgp__get(self, path, params=None):
assert self.inMainLand
assert self.inTencent

headers = {
"Authorization": f"Bearer {self.sgpToken}"
Expand Down
4 changes: 2 additions & 2 deletions app/lol/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ async def parseAllyGameInfo(session, currentSummonerId, useSGP=False):
# 排位会有预选位
isRank = bool(session["myTeam"][0]["assignedPosition"])

if useSGP and connector.isInMainland():
if useSGP and connector.isInTencent():
# 如果是国服就优先尝试 SGP
try:
tasks = [getSummonerGamesInfoViaSGP(item, isRank, currentSummonerId)
Expand Down Expand Up @@ -866,7 +866,7 @@ async def parseGameInfoByGameflowSession(session, currentSummonerId, side, useSG
else:
team, _ = separateTeams(data, currentSummonerId)

if useSGP and connector.isInMainland():
if useSGP and connector.isInTencent():
# 如果是国服就优先尝试 SGP
try:
tasks = [getSummonerGamesInfoViaSGP(item, isRank, currentSummonerId)
Expand Down

0 comments on commit a0dbd34

Please sign in to comment.