def search_user(self, ptt_id: str, min_page: int = None, max_page: int = None) -> list: 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) if min_page is not None: check_value.check_index(self.config, 'min_page', min_page) if max_page is not None: check_value.check_index(self.config, 'max_page', max_page) if min_page is not None and max_page is not None: check_value.check_index_range(self.config, 'min_page', min_page, 'max_page', max_page) try: from . import _api_search_user except ModuleNotFoundError: import _api_search_user return _api_search_user.search_user(self, ptt_id, min_page, max_page)
def reply_post(self, reply_type: int, board: str, content: str, sign_file=0, post_aid: str = None, post_index: int = 0) -> None: self._one_thread() if not self._login_status: raise exceptions.Requirelogin(i18n.Requirelogin) self.config.log_last_value = None check_value.check(self.config, int, 'reply_type', reply_type, value_class=data_type.reply_type) check_value.check(self.config, str, 'Board', board) check_value.check(self.config, str, 'Content', content) if post_aid is not None: check_value.check(self.config, str, 'PostAID', post_aid) if post_index != 0: newest_index = self._get_newest_index(data_type.index_type.BBS, board=board) check_value.check_index(self.config, 'PostIndex', post_index, max_value=newest_index) sign_file_list = [str(x) for x in range(0, 10)] sign_file_list.append('x') if str(sign_file) not in sign_file_list: raise ValueError( log.merge(self.config, ['SignFile', i18n.ErrorParameter])) if post_aid is not None and post_index != 0: raise ValueError( log.merge(self.config, [ 'PostIndex', 'PostAID', i18n.ErrorParameter, i18n.BothInput ])) self._check_board(board) try: from . import _api_reply_post except ModuleNotFoundError: import _api_reply_post _api_reply_post.reply_post(self, reply_type, board, content, sign_file, post_aid, post_index)
def del_mail(self, index): 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 current_index = self.get_newest_index(data_type.index_type.MAIL) check_value.check_index(self.config, index, current_index) try: from . import _api_mail except ModuleNotFoundError: import _api_mail return _api_mail.del_mail(self, index)
def markPost(api, mark_type: int, board: str, post_aid: str, post_index: int, search_type: int, search_condition: str) -> None: log.show_value(api.config, log.level.INFO, [i18n.PTT, i18n.Msg], i18n.MarkPost) check_value.check(api.config, int, 'mark_type', mark_type, value_class=data_type.mark_type) check_value.check(api.config, str, 'Board', board) if post_aid is not None: check_value.check(api.config, str, 'PostAID', post_aid) check_value.check(api.config, int, 'PostIndex', post_index) check_value.check(api.config, int, 'SearchType', search_type, value_class=data_type.post_search_type) if search_condition is not None: check_value.check(api.config, str, 'SearchCondition', search_condition) if len(board) == 0: raise ValueError(log.merge([i18n.Board, i18n.ErrorParameter, board])) if mark_type != data_type.mark_type.DeleteD: if post_index != 0 and isinstance(post_aid, str): raise ValueError( log.merge(api.config, [ 'PostIndex', 'PostAID', i18n.ErrorParameter, i18n.BothInput ])) if post_index == 0 and post_aid is None: raise ValueError( log.merge(api.config, ['PostIndex', 'PostAID', i18n.ErrorParameter])) if search_condition is not None and search_type == 0: raise ValueError( log.merge(api.config, [ 'SearchType', i18n.ErrorParameter, ])) if search_type == data_type.post_search_type.PUSH: try: S = int(search_condition) except ValueError: raise ValueError( log.merge(api.config, [ 'SearchCondition', i18n.ErrorParameter, ])) if not (-100 <= S <= 110): raise ValueError( log.merge(api.config, [ 'SearchCondition', i18n.ErrorParameter, ])) if post_aid is not None and search_condition is not None: raise ValueError( log.merge(api.config, [ 'PostAID', 'SearchCondition', i18n.ErrorParameter, i18n.BothInput, ])) if post_index != 0: newest_index = api._get_newest_index(data_type.index_type.BBS, board=board, search_type=search_type, search_condition=search_condition) check_value.check_index(api.config, 'PostIndex', post_index, max_value=newest_index) if mark_type == data_type.mark_type.UNCONFIRMED: # 批踢踢兔沒有待證文章功能 QQ if api.config.host == data_type.host_type.PTT2: raise exceptions.HostNotSupport(lib_util.get_current_func_name()) api._check_board(board, check_moderator=True) cmd_list = [] cmd_list.append(command.GoMainMenu) cmd_list.append('qs') cmd_list.append(board) cmd_list.append(command.Enter) cmd = ''.join(cmd_list) target_list = [ connect_core.TargetUnit( i18n.AnyKeyContinue, '任意鍵', response=' ', ), connect_core.TargetUnit([ '動畫播放中', ], '互動式動畫播放中', response=command.Ctrl_C, log_level=log.level.DEBUG), connect_core.TargetUnit([ '進板成功', ], screens.Target.InBoard, break_detect=True, log_level=log.level.DEBUG), ] index = api.connect_core.send(cmd, target_list) cmd_list = [] if post_aid is not None: cmd_list.append('#' + post_aid) cmd_list.append(command.Enter) elif post_index != 0: if search_condition is not None: if search_type == data_type.post_search_type.KEYWORD: cmd_list.append('/') elif search_type == data_type.post_search_type.AUTHOR: cmd_list.append('a') elif search_type == data_type.post_search_type.PUSH: cmd_list.append('Z') elif search_type == data_type.post_search_type.MARK: cmd_list.append('G') elif search_type == data_type.post_search_type.MONEY: cmd_list.append('A') cmd_list.append(search_condition) cmd_list.append(command.Enter) cmd_list.append(str(post_index)) cmd_list.append(command.Enter) if mark_type == data_type.mark_type.S: cmd_list.append('L') elif mark_type == data_type.mark_type.D: cmd_list.append('t') elif mark_type == data_type.mark_type.DeleteD: cmd_list.append(command.Ctrl_D) elif mark_type == data_type.mark_type.M: cmd_list.append('m') elif mark_type == data_type.mark_type.UNCONFIRMED: cmd_list.append(command.Ctrl_E + 'S') cmd = ''.join(cmd_list) target_list = [ connect_core.TargetUnit([i18n.DelAllMarkPost], '刪除所有標記', response='y' + command.Enter, log_level=log.level.INFO), connect_core.TargetUnit([ i18n.Mark, i18n.Success, ], screens.Target.InBoard, break_detect=True, log_level=log.level.INFO), ] index = api.connect_core.send(cmd, target_list)
def push(self, board: str, push_type: int, push_content: str, post_aid: str = None, post_index: int = 0) -> None: self._one_thread() if not self._login_status: raise exceptions.Requirelogin(i18n.Requirelogin) self.config.log_last_value = None check_value.check(self.config, str, 'Board', board) check_value.check(self.config, int, 'push_type', push_type, value_class=data_type.push_type) check_value.check(self.config, str, 'PushContent', push_content) if post_aid is not None: check_value.check(self.config, str, 'PostAID', post_aid) check_value.check(self.config, int, 'PostIndex', post_index) if len(board) == 0: raise ValueError( log.merge(self.config, [i18n.Board, i18n.ErrorParameter, board])) if post_index != 0 and isinstance(post_aid, str): raise ValueError( log.merge(self.config, [ 'PostIndex', 'PostAID', i18n.ErrorParameter, i18n.BothInput ])) if post_index == 0 and post_aid is None: raise ValueError( log.merge(self.config, [ 'PostIndex', 'PostAID', i18n.ErrorParameter, i18n.NoInput ])) if post_index != 0: newest_index = self._get_newest_index(data_type.index_type.BBS, board=board) check_value.check_index(self.config, 'PostIndex', post_index, newest_index) self._check_board(board) max_push_length = 33 push_list = [] temp_start_index = 0 temp_end_index = temp_start_index + 1 while temp_end_index <= len(push_content): temp = '' last_temp = None while len(temp.encode('big5-uao', 'replace')) < max_push_length: temp = push_content[temp_start_index:temp_end_index] if not len(temp.encode('big5-uao', 'replace')) < max_push_length: break elif push_content.endswith(temp): break elif temp.endswith('\n'): break elif last_temp == temp: break temp_end_index += 1 last_temp = temp push_list.append(temp.strip()) temp_start_index = temp_end_index temp_end_index = temp_start_index + 1 push_list = filter(None, push_list) for push in push_list: log.show_value(self.config, log.level.INFO, i18n.Push, push) for _ in range(2): try: self._push(board, push_type, push, post_aid=post_aid, post_index=post_index) break except exceptions.NoFastPush: # screens.show(self.config, self.connect_core.getScreenQueue()) log.log(self.config, log.level.INFO, '等待快速推文') time.sleep(5.2)