示例#1
0
async def decherulize_cheru(bot: Bot, event: Event, state: dict):
    msg = state['cheru']
    uid = event.user_id
    at = MessageSegment.at(uid)
    res = escape(cheru2str(msg))
    result = f'{at}的切噜噜是:\n{res}'
    await sv_cheru_to_txt.finish(result)
示例#2
0
async def _(bot: Bot, event: Event, state: dict):
    msg = state['msg']
    # 通过封装的函数获取机器人的回复
    reply = await call_tuling_api(event, msg)
    if reply:
        # 如果调用机器人成功,得到了回复,则转义之后发送给用户
        # 转义会把消息中的某些特殊字符做转换,以避免 酷Q 将它们理解为 CQ 码
        await robot_message.finish(escape(reply))

    reply = await call_tencent_api(event, msg)
    if reply:
        await robot_message.finish(escape(reply))

    # 如果调用失败,或者它返回的内容我们目前处理不了,发送无法获取回复时的「表达」
    # 这里的 render_expression() 函数会将一个「表达」渲染成一个字符串消息
    await robot_message.finish(render_expression(EXPR_DONT_UNDERSTAND))
示例#3
0
async def handle_tuling(bot: Bot, event: Event, state: dict):
    message = str(event.get_message())

    group_id = get_group_id(message)

    data = await get_data(group_id)
    if data and len(data):
        await tickets.finish(escape('\n---\n'.join(map(format_ticket, data))))
    else:
        await tickets.reject('票务查询失败')
示例#4
0
async def handle_tuling(bot: Bot, event: Event, state: dict):
    message = str(event.get_message())

    reply = await get_data(
        message, event.get_user_id(),
        event.group_id if isinstance(event, GroupMessageEvent) else None)
    if reply:
        await tuling.finish(escape(reply))
    else:
        # 如果调用失败,或者它返回的内容我们目前处理不了,发送无法获取图灵回复时的「表达」
        # 这里的 render_expression() 函数会将一个「表达」渲染成一个字符串消息
        await tuling.reject(render_expression(EXPR_DONT_UNDERSTAND))
示例#5
0
def render_expression(expr, *args, escape_args: bool = True, **kwargs) -> str:
    """
    Render an expression to message string.
    :param expr: expression to render
    :param escape_args: should escape arguments or not
    :param args: positional arguments used in str.format()
    :param kwargs: keyword arguments used in str.format()
    :return: the rendered message
    """
    result: str
    if callable(expr):
        result = expr(*args, **kwargs)
    elif isinstance(expr, Sequence) and not isinstance(expr, str):
        result = random.choice(expr)
    else:
        result = expr
    if escape_args:
        return result.format(
            *[escape(s) if isinstance(s, str) else s for s in args], **{
                k: escape(v) if isinstance(v, str) else v
                for k, v in kwargs.items()
            })
    return result.format(*args, **kwargs)
示例#6
0
async def _(bot: Bot, event: Event, state: dict):
    msg = state['msg']
    if state['info'] == 'texts':
        # 通过封装的函数获取机器人的回复
        reply = await txchat.anso(msg, TXAI_ID, TXAI_KEY)
        if reply:
            await chat.finish(escape(reply))
        # 如果调用失败,或者它返回的内容我们目前处理不了,发送无法获取回复时的「表达」
        # 这里的 render_expression() 函数会将一个「表达」渲染成一个字符串消息
        await chat.finish(expr(e.TXCHAT_NOANSWER))
    elif state['info'] == 'qqface':
        import chatsys
        q_dt, dt_st = await chatsys.req_dtb(state['msg'])
        if dt_st == True:
            await chat.finish(f'[CQ:image,file=https://image.dbbqb.com/' +
                              q_dt + ',type=show,id=40000]')
        else:
            print(q_dt)
            await chat.finish('小管家的智商对你的表情居然无言以对。。。。')
示例#7
0
async def decherulize(bot: Bot, event: Event, state: dict):
    s = event.raw_message
    if len(s) > 1501:
        await deqieqie.finish("切、切噜太长切不动勒切噜噜...", at_sender=True)
    msg = "的切噜噜是:\n" + escape(cheru2str(s)[3:])
    await deqieqie.send(msg, at_sender=True)
示例#8
0
async def format_combat_xml(combat: Combat) -> str:
    data = r'''
    <?xml version='1.0' encoding='UTF-8' standalone='yes' ?><msg serviceID="1" templateID="123" action="web" brief="[战斗] 战斗状态" sourceMsgId="0" url="https://www.epicteller.com/combat/{url_token}" flag="0" adverSign="0" multiMsgFlag="0"><item layout="2" advertiser_id="0" aid="0"><picture cover="https://ep-predict.epicteller.com/icon512.png" w="0" h="0" /><title>战斗状态</title><summary>战斗状态</summary></item><source name="" icon="" action="" appid="-1" /></msg>
        '''.format(url_token=combat.url_token)
    return escape(data)