def wechat_text_msg(self, msg: wxpy.Message) -> Optional[Message]: if msg.chat.user_name == "newsapp" and msg.text.startswith("<mmreader>"): return self.wechat_newsapp_msg(msg) if msg.text.startswith("http://weixin.qq.com/cgi-bin/redirectforward?args="): return self.wechat_location_msg(msg) chat, author = self.get_chat_and_author(msg) if self.channel.flag("text_post_processing"): text = ews_utils.wechat_string_unescape(msg.text) else: text = msg.text or "" efb_msg = Message( chat=chat, author=author, text=text, type=MsgType.Text ) if msg.is_at and chat.self: found = False for i in re.finditer(r"@([^@\s]*)(?=\u2005|$|\s)", msg.text): if i.groups()[0] in (self.bot.self.name, msg.chat.self.display_name): found = True efb_msg.substitutions = Substitutions({ i.span(): chat.self }) if not found: append = "@" + self.bot.self.name efb_msg.substitutions = Substitutions({ (len(msg.text) + 1, len(msg.text) + 1 + len(append)): chat.self }) efb_msg.text += " " + append return efb_msg
def qq_text_simple_wrapper(self, text: str, ats: dict): # This cute function only accepts string! efb_msg = Message() efb_msg.type = MsgType.Text efb_msg.text = text if ats: # This is used to replace specific text with @blahblah # And Milkice really requires a brain check efb_msg.substitutions = Substitutions(ats) return efb_msg
def attach_message_properties(self, message: Message, reactions: bool, commands: bool, substitutions: bool) -> Message: reactions_val = self.build_reactions(message.chat) if reactions else {} commands_val = self.build_message_commands() if commands else None substitutions_val = self.build_substitutions( message.text, message.chat) if substitutions else None message.reactions = reactions_val message.commands = commands_val message.substitutions = substitutions_val return message
def process_message(self, message: Message) -> Optional[Message]: if message.type == MsgType.Text and \ message.author.module_id.startswith("blueset.wechat") and \ type(message.chat) == GroupChat and \ self.match_list(message.text): x: int = 0 message.text = "@ME " + message.text message.substitutions = Substitutions({}) message.substitutions[(x, x + 3)] = message.chat return message