How to use aiocqhttp - 10 common examples

To help you get started, we’ve selected a few aiocqhttp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github richardchien / python-aiocqhttp / aiocqhttp / message.py View on Github external
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)
github richardchien / python-aiocqhttp / aiocqhttp / message.py View on Github external
def record(file: str, magic: bool = False):
        return MessageSegment(type_='record',
                              data={'file': file, 'magic': _b2s(magic)})
github richardchien / python-aiocqhttp / aiocqhttp / message.py View on Github external
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
        })
github richardchien / python-aiocqhttp / aiocqhttp / message.py View on Github external
                result.extend(map(lambda d: MessageSegment(d), other))
            elif isinstance(other, dict):
github richardchien / python-aiocqhttp / aiocqhttp / message.py View on Github external
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')
github richardchien / python-aiocqhttp / aiocqhttp / message.py View on Github external
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
        })
github richardchien / python-aiocqhttp / aiocqhttp / message.py View on Github external
def at(user_id: int):
        return MessageSegment(type_='at', data={'qq': str(user_id)})
github richardchien / python-aiocqhttp / aiocqhttp / message.py View on Github external
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')