def __find_number(self, message: MessageChain) -> T.Optional[int]: """ 找出消息中所指定的数字(随机多少张书签) :return: 数字。若未触发则为None,若未指定数字则为1 """ content = message.asDisplay() for x in self.trigger: result = match_groups(x, ["$number"], content) if result is None: continue number = result["$number"] if number is None or number == "": number = 1 elif number.isdigit(): number = int(number) else: number = decode_chinese_int(number) return number return None
def __find_attrs(self, message: MessageChain) -> T.Optional[T.Tuple[str, int]]: """ 找出消息中的搜索关键字 :return: 搜索关键字,若未触发则为None """ content = message_content(message) for x in self.trigger: result = match_groups(x, ["$illustrator", "$number"], content) if result is None: continue illustrator, number = result["$illustrator"], result["$number"] if number is None or number == "": number = 1 elif number.isdigit(): number = int(number) else: number = decode_chinese_int(number) return illustrator, number return None
def __find_attrs(self, message: MessageChain) -> T.Optional[T.Tuple[str, int]]: """ 找出消息中所指定的关键字和数字 :return: 关键字和数字。若未触发则为None,若未指定关键字则为"",若未指定数字则为1 """ content = message.asDisplay() for x in self.trigger: result = match_groups(x, ["$keyword", "$number"], content) if result is None: continue keyword, number = result["$keyword"], result["$number"] if keyword is None: keyword = "" if number is None or number == "": number = 1 elif number.isdigit(): number = int(number) else: number = decode_chinese_int(number) return keyword, number return None