From a3429db1c987b5f4ab79e6728b78b2ff710b6757 Mon Sep 17 00:00:00 2001 From: Yudaotor Date: Wed, 21 Feb 2024 12:16:56 +0800 Subject: [PATCH] fix: not update todayDrop bug && sometimes miss drop bug --- EsportsHelper/GUIThread.py | 24 ++++++++++++------------ EsportsHelper/Rewards.py | 2 +- EsportsHelper/Utils.py | 10 +++++++--- EsportsHelper/Webdriver.py | 6 +++--- 4 files changed, 23 insertions(+), 19 deletions(-) diff --git a/EsportsHelper/GUIThread.py b/EsportsHelper/GUIThread.py index 6913e0b..de7889b 100644 --- a/EsportsHelper/GUIThread.py +++ b/EsportsHelper/GUIThread.py @@ -16,7 +16,7 @@ from EsportsHelper.Stats import stats from EsportsHelper.Utils import colorFlicker, getWebhookInfo, \ getConfigInfo, getLiveRegionsInfo, getNextMatchTimeInfo, \ - getDropInfo, getSleepBalloonsInfo, cleanBriefInfo, \ + getSessionDropInfo, getSleepBalloonsInfo, cleanBriefInfo, \ getLiveInfo, getInfo, getWarningInfo, formatExc, getSleepPeriodInfo _ = i18n.getText @@ -87,7 +87,7 @@ def run(self): ) is_dockerized = config.isDockerized - dropInfo = getDropInfo() + sessionDropInfo = getSessionDropInfo() configInfo = getConfigInfo() webhookInfo = getWebhookInfo() sleepPeriodInfo = getSleepPeriodInfo() @@ -97,7 +97,7 @@ def run(self): style="bold yellow", title_align="left", title=_('电竞助手', color="bold blue") + str(config.version) + " " + sleepPeriodInfo, subtitle_align="right", subtitle=configInfo)), - Layout(name="drop", renderable=Panel(dropInfo, + Layout(name="drop", renderable=Panel(sessionDropInfo, title=_('运行期间掉宝', color="bold yellow"), title_align="left", style="bold yellow", subtitle=webhookInfo + " 一 " + todayDropsInfo, subtitle_align="right")) ) @@ -133,16 +133,14 @@ def run(self): frameCount = 0 with Live(layout, auto_refresh=False, console=console) as live: while True: - drops = "" - if stats.sessionDropsDict: - for key in stats.sessionDropsDict: - drops += f"{key}: {stats.sessionDropsDict.get(key)}\t" - dropInfo = drops if drops else _("暂无掉落", "bold yellow") + sessionDropInfo = getSessionDropInfo() webhookInfo = getWebhookInfo() sessionDropNumber = len(stats.currentDropsList) - len(stats.initDropsList) - Layout(name="drop", renderable=Panel(dropInfo, - title=_('运行期间掉宝', color="bold yellow"), - title_align="left", style="bold yellow", subtitle=webhookInfo + " " + todayDropsInfo, subtitle_align="right")) + todayDropsInfo = _("今日掉宝", "bold yellow") + f":{stats.todayDrops}" + layout["upper"]["banner"]["drop"].update(Panel(sessionDropInfo, + title=_('运行期间掉宝', color="bold yellow"), + title_align="left", style="bold yellow", + subtitle=webhookInfo + " 一 " + todayDropsInfo, subtitle_align="right")) layout["upper"]["table"].update(setAccountTable(frameCount)) cleanBriefInfo() @@ -167,7 +165,9 @@ def run(self): title_align="left", style="bold yellow")) layout["lower"]["live2"].update(Panel("\n".join(liveInfo2), style="bold yellow", title_align="left", title=modeInfo, subtitle=_("请我喝一杯咖啡", "bold cyan") + ":https://github.com/Yudaotor", subtitle_align="right")) - layout["lower"]["info1"].update(Panel("\n".join(info1), subtitle=_("观看属地", "bold yellow") + ":" + watchRegion, subtitle_align="right", title=_("简略日志", "bold yellow"), title_align="left", style="bold yellow")) + layout["lower"]["info1"].update( + Panel("\n".join(info1), subtitle=_("观看属地", "bold yellow") + ":" + watchRegion, subtitle_align="right", title=_("简略日志", "bold yellow"), + title_align="left", style="bold yellow")) layout["lower"]["info2"].update( Panel("\n".join(info2), subtitle=_("(详细请见log文件)", "bold yellow"), subtitle_align="right", style="bold yellow", title_align="right", title=_("代挂:闲鱼店铺搜Khalilc", "bold yellow"))) diff --git a/EsportsHelper/Rewards.py b/EsportsHelper/Rewards.py index cb9aa50..4a50c9f 100644 --- a/EsportsHelper/Rewards.py +++ b/EsportsHelper/Rewards.py @@ -541,7 +541,7 @@ def checkNewDrops(self): with open(f'./dropsHistory/{strftime("%Y%m%d-")}drops.txt', "a+"): pass stats.todayDrops = 0 - newDropList = [drop for drop in stats.currentDropsList if stats.lastDropCheckTime <= drop.get("unlockedDateMillis", -1)] + newDropList = [drop for drop in stats.currentDropsList if (stats.lastDropCheckTime - 6000) <= drop.get("unlockedDateMillis", -1)] # newDropList = [drop for drop in stats.currentDropsList if drop.get("cappedDrop", False)] if len(newDropList) > 0: newDrops = parseDropList(newDropList) diff --git a/EsportsHelper/Utils.py b/EsportsHelper/Utils.py index e55673e..8738dc8 100644 --- a/EsportsHelper/Utils.py +++ b/EsportsHelper/Utils.py @@ -504,6 +504,7 @@ def checkRewardPage(driver, isInit=False): getRewardByLog(driver, isInit) if isInit: log.info(_log("初始化reward网站成功")) + setTodayDropsNumber(isInit=True) if config.exportDrops: try: log.info(_log("总掉落文件生成中...")) @@ -831,7 +832,7 @@ def getNextMatchTimeInfo(): return nextMatchTime -def getDropInfo(): +def getSessionDropInfo(): """ Retrieves information about dropped rewards during the current session. @@ -1101,14 +1102,17 @@ def debugScreen(driver, lint="normal"): log.error(formatExc(format_exc())) -def setTodayDropsNumber(): +def setTodayDropsNumber(isInit=False): """ Set the number of drops for today. This function retrieves all drop items from the current drop list (stats.currentDropsList) that have a drop time after midnight today and sets the count as stats.todayDrops. """ - dropsList = stats.currentDropsList + if isInit: + dropsList = stats.initDropsList + else: + dropsList = stats.currentDropsList currentTime = datetime.now() midnightTime = currentTime.replace(hour=0, minute=0, second=0, microsecond=0) midnightMillis = midnightTime.timestamp() * 1000 diff --git a/EsportsHelper/Webdriver.py b/EsportsHelper/Webdriver.py index cd2cdf7..4fe8c57 100644 --- a/EsportsHelper/Webdriver.py +++ b/EsportsHelper/Webdriver.py @@ -61,7 +61,7 @@ def addWebdriverOptions(options): - None """ if checkPort("localhost", 9222): - log.error(_log("检测到端口9222被占用")) + log.info(_log("检测到端口9222被占用")) if checkPort("localhost", 9229): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.bind(("localhost", 0)) @@ -78,10 +78,10 @@ def addWebdriverOptions(options): stats.debugPort = port else: stats.debugPort = 9229 - log.error(_log("使用默认端口9229")) + log.info(_log("使用默认端口9229")) else: stats.debugPort = 9222 - log.error(_log("使用默认端口9222")) + log.info(_log("使用默认端口9222")) options.add_argument("--disable-extensions") options.add_argument('--disable-audio-output') options.add_argument('--autoplay-policy=no-user-gesture-required')