From e9499382632c05974b0656ea61fd0dd172b14c01 Mon Sep 17 00:00:00 2001 From: ninemine <1371605831@qq.com> Date: Tue, 11 Nov 2025 19:28:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=96=B0=E5=A2=9E=E7=82=BC?= =?UTF-8?q?=E9=87=91=E7=B3=BB=E7=BB=9F=E6=97=B6=E5=87=BA=E7=8E=B0=E7=9A=84?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Plugins/WPSAlchemyGame.py | 79 +++++++++++++++------------------------ 1 file changed, 30 insertions(+), 49 deletions(-) diff --git a/Plugins/WPSAlchemyGame.py b/Plugins/WPSAlchemyGame.py index 71f24a2..2c919f4 100644 --- a/Plugins/WPSAlchemyGame.py +++ b/Plugins/WPSAlchemyGame.py @@ -11,6 +11,7 @@ from PWF.Convention.Runtime.Architecture import Architecture from PWF.Convention.Runtime.GlobalConfig import ConsoleFrontColor, ProjectConfig from PWF.CoreModules.database import get_db, STATUS_COMPLETED from PWF.CoreModules.plugin_interface import DatabaseModel +from PWF.CoreModules.flags import get_internal_debug from .WPSAPI import WPSAPI from .WPSBackpackSystem import ( @@ -25,6 +26,7 @@ from .WPSFortuneSystem import WPSFortuneSystem logger: ProjectConfig = Architecture.Get(ProjectConfig) FORTUNE_COEFF:float = logger.FindItem("alchemy_fortune_coeff", 0.03) +COOLDOWN_MINUTES:int = logger.FindItem("alchemy_cooldown_minutes", 2) logger.SaveProperties() @@ -64,12 +66,8 @@ class WPSAlchemyGame(WPSAPI): self._fail_index: Dict[str, Set[Tuple[str, str, str]]] = defaultdict(set) self._fortune_coeff = FORTUNE_COEFF # 从配置读取冷却时间(分钟) - from PWF.CoreModules.flags import get_internal_debug - cooldown_minutes = logger.FindItem("alchemy_cooldown_minutes", 2) - if get_internal_debug(): - cooldown_minutes = 0 - self._cooldown_minutes = cooldown_minutes - self._cooldown_ms = int(cooldown_minutes * 60 * 1000) + self._cooldown_minutes = 0 if get_internal_debug() else COOLDOWN_MINUTES + self._cooldown_ms = int(self._cooldown_minutes * 60 * 1000) logger.SaveProperties() @override @@ -322,9 +320,7 @@ class WPSAlchemyGame(WPSAPI): ) # 注册定时任务 - task_id = None - if self._cooldown_ms > 0: - task_id = self.register_clock( + task_id = self.register_clock( self._settle_alchemy_callback, self._cooldown_ms, kwargs={ @@ -332,18 +328,14 @@ class WPSAlchemyGame(WPSAPI): "user_id": user_id, "chat_id": chat_id, }, - ) - # 更新记录的任务ID - cursor = get_db().conn.cursor() - cursor.execute( + ) + # 更新记录的任务ID + cursor = get_db().conn.cursor() + cursor.execute( "UPDATE alchemy_records SET scheduled_task_id = ? WHERE alchemy_id = ?", (task_id, alchemy_id), - ) - get_db().conn.commit() - else: - # Debug模式,立即结算 - success, msg, rewards = self.settle_alchemy(alchemy_id) - return msg + ) + get_db().conn.commit() # 计算预计完成时间 cursor = get_db().conn.cursor() @@ -354,7 +346,6 @@ class WPSAlchemyGame(WPSAPI): record = cursor.fetchone() expected_end_time = datetime.fromisoformat(record["expected_end_time"]) - from PWF.CoreModules.flags import get_internal_debug debug_hint = " **[DEBUG模式]**" if get_internal_debug() else "" time_str = "立即结算" if self._cooldown_minutes == 0 else f"{self._cooldown_minutes} 分钟" @@ -430,28 +421,22 @@ class WPSAlchemyGame(WPSAPI): ) # 注册定时任务 - task_id = None - if self._cooldown_ms > 0: - task_id = self.register_clock( - self._settle_alchemy_callback, - self._cooldown_ms, - kwargs={ - "alchemy_id": alchemy_id, - "user_id": user_id, - "chat_id": chat_id, - }, - ) - # 更新记录的任务ID - cursor = get_db().conn.cursor() - cursor.execute( + task_id = self.register_clock( + self._settle_alchemy_callback, + self._cooldown_ms, + kwargs={ + "alchemy_id": alchemy_id, + "user_id": user_id, + "chat_id": chat_id, + }, + ) + # 更新记录的任务ID + cursor = get_db().conn.cursor() + cursor.execute( "UPDATE alchemy_records SET scheduled_task_id = ? WHERE alchemy_id = ?", (task_id, alchemy_id), - ) - get_db().conn.commit() - else: - # Debug模式,立即结算 - success, msg, rewards = self.settle_alchemy(alchemy_id) - return msg + ) + get_db().conn.commit() # 计算预计完成时间 cursor = get_db().conn.cursor() @@ -462,7 +447,6 @@ class WPSAlchemyGame(WPSAPI): record = cursor.fetchone() expected_end_time = datetime.fromisoformat(record["expected_end_time"]) - from PWF.CoreModules.flags import get_internal_debug debug_hint = " **[DEBUG模式]**" if get_internal_debug() else "" time_str = "立即结算" if self._cooldown_minutes == 0 else f"{self._cooldown_minutes} 分钟" @@ -580,12 +564,14 @@ class WPSAlchemyGame(WPSAPI): def settle_alchemy(self, alchemy_id: int) -> Tuple[bool, str, Optional[Dict]]: """结算炼金""" + import sqlite3 + cursor = get_db().conn.cursor() cursor.execute( "SELECT * FROM alchemy_records WHERE alchemy_id = ?", (alchemy_id,), ) - record = cursor.fetchone() + record: sqlite3.Row = cursor.fetchone() if not record: return False, "❌ 炼金记录不存在", None @@ -738,14 +724,9 @@ class WPSAlchemyGame(WPSAPI): ) # 更新定时任务状态 - scheduled_task_id = record.get("scheduled_task_id") + scheduled_task_id: int = record["scheduled_task_id"] if scheduled_task_id: - try: - get_db().update_task_status(int(scheduled_task_id), STATUS_COMPLETED) - except Exception: - pass - - get_db().conn.commit() + get_db().update_task_status(scheduled_task_id, STATUS_COMPLETED) return True, "".join(message_lines), result_data