def throw_waterball(self, ptt_id, content) -> None: self._one_thread() if not self._login_status: raise exceptions.Requirelogin(i18n.Requirelogin) if self._unregistered_user: raise exceptions.UnregisteredUser(lib_util.get_current_func_name()) self.config.log_last_value = None check_value.check(self.config, str, 'ptt_id', ptt_id) check_value.check(self.config, str, 'content', content) if len(ptt_id) <= 2: raise ValueError( log.merge(self.config, ['ptt_id', i18n.ErrorParameter, ptt_id])) user = self._get_user(ptt_id) if '不在站上' in user.status: raise exceptions.UserOffline(ptt_id) try: from . import _api_waterball except ModuleNotFoundError: import _api_waterball return _api_waterball.throw_waterball(self, ptt_id, content)
def throw_waterball(api: object, target_id: str, content: str) -> None: max_length = 50 water_ball_list = list() temp_start_index = 0 temp_end_index = temp_start_index + 1 while temp_end_index <= len(content): temp = '' last_temp = None while len(temp.encode('big5uao', 'ignore')) < max_length: temp = content[temp_start_index:temp_end_index] if not len(temp.encode('big5uao', 'ignore')) < max_length: break elif content.endswith(temp) and temp_start_index != 0: break elif temp.endswith('\n'): break elif last_temp == temp: break temp_end_index += 1 last_temp = temp water_ball_list.append(temp.strip()) temp_start_index = temp_end_index temp_end_index = temp_start_index + 1 water_ball_list = filter(None, water_ball_list) for waterball in water_ball_list: if api._LastThrowWaterBallTime != 0: current_time = time.time() while (current_time - api._LastThrowWaterBallTime) < 3.2: time.sleep(0.1) current_time = time.time() log.show_value(api.config, log.level.INFO, i18n.WaterBall, waterball) target_list = [ connect_core.TargetUnit(i18n.SetCallStatus, '您的呼叫器目前設定為關閉', response='y' + command.Enter), # 對方已落跑了 connect_core.TargetUnit( i18n.SetCallStatus, '◆ 糟糕! 對方已落跑了', exceptions_=exceptions.UserOffline(target_id)), connect_core.TargetUnit([i18n.Throw, target_id, i18n.WaterBall], '丟 ' + target_id + ' 水球:', response=waterball + command.Enter * 2 + command.GoMainMenu), connect_core.TargetUnit([i18n.Throw, i18n.WaterBall, i18n.Success], screens.Target.MainMenu, break_detect=True) ] cmd_list = list() cmd_list.append(command.GoMainMenu) cmd_list.append('T') cmd_list.append(command.Enter) cmd_list.append('U') cmd_list.append(command.Enter) if '【好友列表】' in api.connect_core.get_screen_queue()[-1]: cmd_list.append('f') cmd_list.append('s') cmd_list.append(target_id) cmd_list.append(command.Enter) cmd_list.append('w') cmd = ''.join(cmd_list) api.connect_core.send(cmd, target_list, screen_timeout=api.config.screen_long_timeout) api._LastThrowWaterBallTime = time.time()