Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
for cqcode in re.finditer(r'\[CQ:(?P[a-zA-Z0-9-_.]+)'
r'(?P'
r'(?:,[a-zA-Z0-9-_.]+=?[^,\]]*)*'
r'),?\]',
msg_str):
yield 'text', unescape(
msg_str[text_begin:cqcode.pos + cqcode.start()])
text_begin = cqcode.pos + cqcode.end()
yield cqcode.group('type'), cqcode.group('params').lstrip(',')
yield 'text', unescape(msg_str[text_begin:])
for function_name, extra in iter_function_name_and_extra():
if function_name == 'text':
if extra:
# only yield non-empty text segment
yield MessageSegment(type_=function_name,
data={'text': extra})
else:
data = {k: v for k, v in map(
lambda x: x.split('=', maxsplit=1),
filter(lambda x: x, (x.lstrip() for x in extra.split(',')))
)}
yield MessageSegment(type_=function_name, data=data)
def record(file: str, magic: bool = False):
return MessageSegment(type_='record',
data={'file': file, 'magic': _b2s(magic)})
def share(url: str, title: str, content: str = '', image_url: str = ''):
return MessageSegment(type_='share', data={
'url': url,
'title': title,
'content': content,
'image': image_url
})
result.extend(map(lambda d: MessageSegment(d), other))
elif isinstance(other, dict):
def __add__(self, other: Any):
result = Message(self)
try:
if isinstance(other, Message):
result.extend(other)
elif isinstance(other, MessageSegment):
result.append(other)
elif isinstance(other, list):
result.extend(map(lambda d: MessageSegment(d), other))
elif isinstance(other, dict):
result.append(MessageSegment(other))
elif isinstance(other, str):
result.extend(Message._split_iter(other))
return result
except:
pass
raise ValueError('the addend is not a valid message')
def music_custom(url: str, audio_url: str, title: str, content: str = '',
image_url: str = ''):
return MessageSegment(type_='music', data={
'type': 'custom',
'url': url,
'audio': audio_url,
'title': title,
'content': content,
'image': image_url
})
def at(user_id: int):
return MessageSegment(type_='at', data={'qq': str(user_id)})
def append(self, obj: Any) -> Any:
try:
if isinstance(obj, MessageSegment):
if self and self[-1].type == 'text' and obj.type == 'text':
self[-1].data['text'] += obj.data['text']
elif obj.type != 'text' or obj.data['text'] or not self:
super().append(obj)
else:
self.append(MessageSegment(obj))
return self
except:
pass
raise ValueError('the object is not a valid message segment')
def dice():
return MessageSegment(type_='dice')
def rps():
return MessageSegment(type_='rps')