Exemplo n.º 1
0
async def addOne(session: CommandSession):
    stripped_arg = session.current_arg_text.strip()
    if stripped_arg == '':
        await session.send("缺少参数")
        return
    if stripped_arg == re.match('[A-Za-z0-9_]+', stripped_arg, flags=0):
        await session.send("用户名/用户ID 只能包含字母、数字或下划线")
        return
    cs = commandHeadtail(stripped_arg)
    try:
        if cs[0].isdecimal():
            userinfo = tweetListener.api.get_user(user_id=int(cs[0]))
        else:
            userinfo = tweetListener.api.get_user(screen_name=cs[0])
    except TweepError:
        s = traceback.format_exc(limit=5)
        logger.error('tweepy错误:' + s)
        await session.send("查询不到信息,你D都能D歪来")
        return
    tweetListener.tweet_event_deal.seve_image(userinfo.screen_name,
                                              userinfo.profile_image_url_https,
                                              'userinfo')
    file_suffix = os.path.splitext(userinfo.profile_image_url_https)[1]
    nick = ''
    des = ''
    if cs[2] != '':
        cs = commandHeadtail(cs[2])
        nick = cs[0]
        des = cs[2]
    if des == '':
        des = userinfo.name + '(' + userinfo.screen_name + ')'
    PushUnit = push_list.baleToPushUnit(
        session.event['self_id'],
        session.event['message_type'],
        session.event[('group_id' if session.event['message_type'] == 'group'
                       else 'user_id')],
        userinfo.id,
        des,
        nick=nick)
    res = push_list.addPushunit(PushUnit)
    s = '用户UID:'+ str(userinfo.id) + "\n" + \
        '用户ID:' + userinfo.screen_name + "\n" + \
        '用户昵称:' + userinfo.name + "\n" + \
        '头像:' + '[CQ:image,timeout='+config.img_time_out+',file='+config.img_path+'userinfo/' + userinfo.screen_name + file_suffix + ']'+ "\n" + \
        ('此用户已添加至监听列表' if res[0] == True else '添加失败:'+res[1])
    push_list.savePushList()
    logger.info(CQsessionToStr(session))
    await session.send(s)
Exemplo n.º 2
0
async def globalRemove(session: CommandSession):
    await asyncio.sleep(0.2)
    stripped_arg = session.current_arg_text.strip().lower()
    if stripped_arg == '':
        await session.send("缺少参数")
        return
    cs = commandHeadtail(stripped_arg)
    cs = {'messagetype': cs[0], 'pushto': cs[2].strip()}
    if cs['pushto'] == '' or cs['messagetype'] == '':
        await session.send("缺少参数")
        return
    if not cs['pushto'].isdecimal():
        await session.send("Q号或群号不合法:" + cs['pushto'])
        return
    messagetype_list = {
        '私聊': 'private',
        'private': 'private',
        '群聊': 'group',
        'group': 'group',
        '好友': 'private',
        '群': 'group',
    }
    if cs['messagetype'] in messagetype_list:
        res = push_list.delPushunitFromPushTo(
            messagetype_list[cs['messagetype']],
            int(cs['pushto']),
            self_id=int(session.event['self_id']))
        push_list.savePushList()
        logger.info(CQsessionToStr(session))
        await session.send(res[1])
    else:
        await session.send("此消息类型不支持:" + cs['messagetype'])
        return
Exemplo n.º 3
0
async def setAttr(session: CommandSession):
    await asyncio.sleep(0.2)
    stripped_arg = session.current_arg_text.strip().lower()
    if stripped_arg == '':
        await session.send("缺少参数")
        return
    cs = commandHeadtail(stripped_arg)
    cs = {0: cs[0], 1: cs[1], 2: cs[2].strip()}
    if cs[0] == '' or cs[2] == '':
        await session.send("缺少参数")
        return
    #处理用户ID
    tweet_user_id: int = -1
    if cs[0].isdecimal():
        tweet_user_id = int(cs[0])
    else:
        await session.send("用户ID错误")
        return
    if cs[2].strip() == '':
        await session.send("缺少参数")
        return
    tcs = commandHeadtail(cs[2])
    cs[2] = tcs[0]
    cs[3] = tcs[1]
    cs[4] = tcs[2].strip()
    PushTo: int = 0
    if session.event['message_type'] == 'group':
        PushTo = int(session.event['group_id'])
    elif session.event['message_type'] == 'private':
        PushTo = int(session.event['user_id'])
    else:
        await session.send('不支持的消息类型!')
        return
    Pushunit_allowEdit = {
        #携带图片发送
        'upimg': 'upimg',
        '图片': 'upimg',
        'img': 'upimg',
        #昵称设置
        'nick': 'nick',
        '昵称': 'nick',
        #描述设置
        'des': 'des',
        '描述': 'des',
        #消息模版
        'retweet_template': 'retweet_template',
        '转推模版': 'retweet_template',
        'quoted_template': 'quoted_template',
        '转推并评论模版': 'quoted_template',
        'reply_to_status_template': 'reply_to_status_template',
        '回复模版': 'reply_to_status_template',
        'reply_to_user_template': 'reply_to_user_template',
        '被提及模版': 'reply_to_user_template',
        'none_template': 'none_template',
        '发推模版': 'none_template',
        #推特转发各类型开关
        'retweet': 'retweet',
        '转推': 'retweet',
        'quoted': 'quoted',
        '转推并评论': 'quoted',
        'reply_to_status': 'reply_to_status',
        '回复': 'reply_to_status',
        'reply_to_user': '******',
        '被提及': 'reply_to_user_template',
        'none': 'none',
        '发推': 'none',
        #推特个人信息变动推送开关
        'change_id': 'change_ID',
        'ID改变': 'change_ID',
        'change_name': 'change_name',
        '名称改变': 'change_name',
        'change_description': 'change_description',
        '描述改变': 'change_description',
        'change_headimgchange': 'change_headimgchange',
        '头像改变': 'change_headimgchange'
    }
    template_attr = ('retweet_template', 'quoted_template',
                     'reply_to_status_template', 'reply_to_user_template',
                     'none_template')
    if str(tweet_user_id) not in push_list.spylist:
        await session.send("用户不在监测列表内!")
        return
    if cs[2] not in Pushunit_allowEdit:
        await session.send('属性值不存在!')
        return
    if Pushunit_allowEdit[cs[2]] == 'des' or Pushunit_allowEdit[
            cs[2]] == 'nick':
        res = push_list.setPushunitAttr(session.event['message_type'], PushTo,
                                        tweet_user_id,
                                        Pushunit_allowEdit[cs[2]], cs[4])
    elif cs[4] != '' and Pushunit_allowEdit[cs[2]] in template_attr:
        res = push_list.setPushunitAttr(session.event['message_type'], PushTo,
                                        tweet_user_id,
                                        Pushunit_allowEdit[cs[2]], cs[4])
    elif cs[4] in ('true', '开', '打开', '开启', '1'):
        res = push_list.setPushunitAttr(session.event['message_type'], PushTo,
                                        tweet_user_id,
                                        Pushunit_allowEdit[cs[2]], 1)
    elif cs[4] in ('false', '关', '关闭', '0'):
        res = push_list.setPushunitAttr(session.event['message_type'], PushTo,
                                        tweet_user_id,
                                        Pushunit_allowEdit[cs[2]], 0)
    else:
        res = (False, '属性的值不合法!')
        await session.send(res[1])
        return
    push_list.savePushList()
    await session.send(res[1])
    logger.info(CQsessionToStr(session))
Exemplo n.º 4
0
async def setGroupAttr(session: CommandSession):
    await asyncio.sleep(0.2)
    stripped_arg = session.current_arg_text.strip().lower()
    if stripped_arg == '':
        await session.send("缺少参数")
        return
    Pushunit_allowEdit = {
        #携带图片发送
        'upimg': 'upimg',
        '图片': 'upimg',
        'img': 'upimg',
        #昵称设置
        #'nick':'nick','昵称':'nick',
        #消息模版
        'retweet_template': 'retweet_template',
        '转推模版': 'retweet_template',
        'quoted_template': 'quoted_template',
        '转推并评论模版': 'quoted_template',
        'reply_to_status_template': 'reply_to_status_template',
        '回复模版': 'reply_to_status_template',
        'reply_to_user_template': 'reply_to_user_template',
        '被提及模版': 'reply_to_user_template',
        'none_template': 'none_template',
        '发推模版': 'none_template',
        #推特转发各类型开关
        'retweet': 'retweet',
        '转推': 'retweet',
        'quoted': 'quoted',
        '转推并评论': 'quoted',
        'reply_to_status': 'reply_to_status',
        '回复': 'reply_to_status',
        'reply_to_user': '******',
        '被提及': 'reply_to_user_template',
        'none': 'none',
        '发推': 'none',
        #推特个人信息变动推送开关
        'change_id': 'change_ID',
        'ID改变': 'change_ID',
        'ID修改': 'change_ID',
        'change_name': 'change_name',
        '名称改变': 'change_name',
        '名称修改': 'change_name',
        '名字改变': 'change_name',
        '名字修改': 'change_name',
        '昵称修改': 'change_name',
        'change_description': 'change_description',
        '描述改变': 'change_description',
        '描述修改': 'change_description',
        'change_headimgchange': 'change_headimgchange',
        '头像改变': 'change_headimgchange',
        '头像修改': 'change_headimgchange'
    }
    template_attr = ('retweet_template', 'quoted_template',
                     'reply_to_status_template', 'reply_to_user_template',
                     'none_template')
    cs = commandHeadtail(stripped_arg)
    cs = {0: cs[0], 1: cs[1], 2: cs[2].strip()}
    if cs[0] == '' or cs[2] == '':
        await session.send("缺少参数")
        return
    if cs[0] not in Pushunit_allowEdit:
        await session.send('属性值不存在!')
        return
    PushTo: int = 0
    if session.event['message_type'] == 'group':
        PushTo = int(session.event['group_id'])
    elif session.event['message_type'] == 'private':
        PushTo = int(session.event['user_id'])
    else:
        await session.send('不支持的消息类型!')
        return
    if cs[2] != '' and Pushunit_allowEdit[cs[0]] in template_attr:
        cs[2] = cs[2].replace("\\n", "\n")
        res = push_list.PushTo_setAttr(session.event['message_type'], PushTo,
                                       Pushunit_allowEdit[cs[0]], cs[2])
    elif cs[2] in ('true', '开', '打开', '开启', '1'):
        res = push_list.PushTo_setAttr(session.event['message_type'], PushTo,
                                       Pushunit_allowEdit[cs[0]], 1)
    elif cs[2] in ('false', '关', '关闭', '0'):
        res = push_list.PushTo_setAttr(session.event['message_type'], PushTo,
                                       Pushunit_allowEdit[cs[0]], 0)
    else:
        res = (False, '属性的值不合法!')
        await session.send(res[1])
        return
    push_list.savePushList()
    logger.info(CQsessionToStr(session))
    await session.send(res[1])