コード例 #1
0
		if method not in all_method:
			raise ValueError('Unsupport method')
		return all_method[method]

	@staticmethod
	def json_msg(string: str) -> MessageChain:
		result = []
		for match in regex.split(r'(\[json_element:.+?\])', string):
			if element := regex.fullmatch(r'(\[json_element:(.+?)\])', match):
				try:
					result.append(json.loads(base64.b64decode(element.group(2))))
				except:
					result.append({'type': 'Plain', 'text': match})
			elif match:#去除空字符串
				result.append({'type': 'Plain', 'text': match})
		return MessageChain.parse_obj(result)

	@staticmethod
	def pickle_msg(string: str) -> MessageChain:
		result = []
		for match in regex.split(r'(\[pickle_element:.+?\])', string):
			if element := regex.fullmatch(r'(\[pickle_element:(.+?)\])', match):
				try:
					result.append(pickle.loads(base64.b64decode(element.group(2))))
				except:
					result.append(Plain(match))
			elif match:#去除空字符串
				result.append(Plain(match))
		return MessageChain.create(result)

	@staticmethod