wechat_group_bot.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:paperweekly_bot 作者: wwj718 项目源码 文件源码
def handle_text_msg(msg):
    global IN_ACTION
    # todo ?????? ???????
    username = msg['ActualNickName']  # ???,??
    content = msg['Text']
    userlogo = msg["UserImg"]
    # ??
    if username in setting.ACTION_ADMIN and setting.ACTION_KEYWORD in content:
        begin_action()
        response = "????! 2?????:)"
        return {'type': 'b', 'response': response}  # ???? ??
    if '[??]' in content and IN_ACTION:
        # ?? ????
        clean_content = re.split(r'\[??\]', content)[-1]
        if clean_content:
            # todo :???????? ???????
            clean_content = "<span class='api_icon'>![](" + userlogo + \
                ")</span><span class='api_nickname'>" + username + "</span>" + clean_content
            try:
                # ????? timeout
                plugin.msg_input(msg=clean_content)
            except Exception as e:
                logger.error(str(e))

            # ???????webhook
            # ?? forum_client.post_thread(username,clean_content)
            # ??username????????clean_content?????
            response = "@{} ??????".format(username)
            return {'type': 'q', 'response': response}
    # if '/bot/t' in content:
    '''
    if content.startswith('[??]'):
        #??
        #?????????
        thread_id,clean_content = re.split(r'\[??\].*?(?P<id>\d+)', content)[-2:]
        response = "????:)"
        return {'type':'t','response':response}
    '''
    # if '/bot/h' in content:
    if '[??]' in content:
        # help
        #response='Hi @{} ???????\n??:[??]\n??:[??] ????\n??:[??](id) ????\n??:[??] ????'.format(msg['ActualNickName'])
        response = 'Hi @{} ???????\n??:[??]\n??:[??] ????'.format(
            msg['ActualNickName'])
        return {'type': 'h', 'response': response}
    return {'type': None, 'response': None}  # ???


# ????
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号