Просмотр исходного кода

Merge pull request #600 from ChengRanORZ/fix_switch_account

fix(Component/SwitchAccount):修复配置保存及登录逻辑
huangrunheng 1 год назад
Родитель
Сommit
042cf0a0fa

+ 4 - 4
tasks/Component/SwitchAccount/login_account.py

@@ -167,7 +167,7 @@ class LoginAccount(BaseTask, SwitchAccountAssets):
                 self.screenshot()
                 if self.appear(self.I_SA_ACCOUNT_DROP_DOWN_CLOSED):
                     if self.ocr_appear(self.O_SA_ACCOUNT_ACCOUNT_SELECTED):
-                        break
+                        return True
                     self.ui_click_until_disappear(self.I_SA_ACCOUNT_DROP_DOWN_CLOSED,
                                                   interval=1.5)
                     continue
@@ -253,7 +253,7 @@ class LoginAccount(BaseTask, SwitchAccountAssets):
 
             # 处于选择 苹果安卓界面
             if self.appear(self.I_SA_LOGIN_FORM_APPLE):
-                btn = self.I_SA_LOGIN_FORM_ANDROID if accountInfo.appleOrAndroid else self.I_SA_LOGIN_FORM_APPLE
+                btn = self.I_SA_LOGIN_FORM_ANDROID if accountInfo.apple_or_android else self.I_SA_LOGIN_FORM_APPLE
                 self.ui_click_until_disappear(btn)
                 isAccountLogon = True
                 continue
@@ -313,12 +313,12 @@ class LoginAccount(BaseTask, SwitchAccountAssets):
             # self.ui_click_until_disappear(self.C_SA_LOGIN_FORM_ENTER_GAME_BTN, stop=self.I_CHECK_LOGIN_FORM)
             logger.info("character %s-%s account:%s %s login Success", accountInfo.character, accountInfo.svr,
                         accountInfo.account,
-                        'Android' if accountInfo.appleOrAndroid else 'Apple')
+                        'Android' if accountInfo.apple_or_android else 'Apple')
             return True
 
         logger.error("character %s-%s account:%s %s login Failed", accountInfo.character, accountInfo.svr,
                      accountInfo.account,
-                     'Android' if accountInfo.appleOrAndroid else 'Apple')
+                     'Android' if accountInfo.apple_or_android else 'Apple')
         return False
 
     def ui_click_until_disappear(self, click, interval: float = 1, stop: RuleImage | RuleGif = None):

+ 7 - 7
tasks/Component/SwitchAccount/switch_account.py

@@ -29,11 +29,11 @@ class SwitchAccount(LoginAccount, ExitGame, GameUi, SwitchAccountAssets):
         @type frm:
         """
         super().__init__(config, device)
-        self.toAccountInfo = to
-        self.fromAccountInfo = frm
+        self.to_account_info = to
+        self.from_account_info = frm
 
     def switchAccount(self):
-        logger.info("start switchAccount %s-%s", self.toAccountInfo.character, self.toAccountInfo.svr)
+        logger.info("start switchAccount %s-%s", self.to_account_info.character, self.to_account_info.svr)
         # 判断所处界面
         curPage = self.ui_get_current_page()
 
@@ -44,12 +44,12 @@ class SwitchAccount(LoginAccount, ExitGame, GameUi, SwitchAccountAssets):
             self.exitGame()
 
         # 处于登录界面
-        if not self.login(self.toAccountInfo):
+        if not self.login(self.to_account_info):
             return False
-        logger.info("%s login suc", self.toAccountInfo.character)
+        logger.info("%s login suc", self.to_account_info.character)
         # 处理位于登录界面各种奇葩弹窗
         login_handler = LoginHandler(config=self.config, device=self.device)
-        login_handler.set_specific_usr(self.toAccountInfo.svr)
+        login_handler.set_specific_usr(self.to_account_info.svr)
         login_handler.app_handle_login()
 
         return True
@@ -58,6 +58,6 @@ class SwitchAccount(LoginAccount, ExitGame, GameUi, SwitchAccountAssets):
 if __name__ == '__main__':
     config = Config('oas1')
     device=Device()
-    toAccount=AccountInfo(account="email0@163.com",accountAlias="emailO#emailo",appleOrAndroid=True,character="粘贴",svr="立秋夕烛")
+    toAccount=AccountInfo(account="email0@163.com", account_alias="emailO#emailo", apple_or_android=True, character="粘贴", svr="立秋夕烛")
     sa=SwitchAccount(config,device,toAccount)
     sa.switchAccount()

+ 4 - 4
tasks/Component/SwitchAccount/switch_account_config.py

@@ -16,8 +16,8 @@ class AccountInfo(BaseModel):
     svr: str = Field(default="", description="svr_help")
     account: str = Field(default="", description="account_help")
     # 为防止ocr出错 暂定格式 字符串以#分割
-    accountAlias: str = Field(default="", description="account_alias_help")
-    appleOrAndroid: bool = Field(default=True, description="apple_or_android_help")
+    account_alias: str = Field(default="", description="account_alias_help")
+    apple_or_android: bool = Field(default=True, description="apple_or_android_help")
     # 上一次执行成功的时间 ,防止出错时重复登录浪费时间
     last_complete_time: DateTime = Field(default=DateTime.fromisoformat("2023-01-01 00:00:00"), description="last_complete_time_help")
 
@@ -25,9 +25,9 @@ class AccountInfo(BaseModel):
         tmp_account = AccountInfo.preprocessAccount(self.account)
         if ocr_account == self.account or ocr_account.startswith(tmp_account):
             return True
-        if not self.accountAlias:
+        if not self.account_alias:
             return False
-        _accountAliasList = self.accountAlias.split('#')
+        _accountAliasList = self.account_alias.split('#')
         for alias in _accountAliasList:
             if ocr_account.startswith(alias):
                 return True