def parse_chat_message(self, message):
"""Parse a game chat message, returning a tuple with the sender's
username and the chat text. HTML entities in the text are
decoded.
"""
if self.protocol_version <= 1:
# Remove html formatting
msg_pattern = r'<span[^>]+>([^<]+)</span>: <span[^>]+>([^<]+)</span>'
match = re.match(msg_pattern, message["content"])
if not match:
raise WebTilesError("Unable to parse chat message: %s",
message["content"])
sender = match.group(1)
chat_text = match.group(2)
else:
sender = message["sender"]
chat_text = message["text"]
return (sender, html.unescape(chat_text))
评论列表
文章目录