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)
async def tweeallpushlist(session: CommandSession): if not headdeal(session): return await asyncio.sleep(0.1) page = 1 stripped_arg = session.current_arg_text.strip().lower() if stripped_arg != '': if not stripped_arg.isdecimal(): await session.send("参数似乎有点不对劲?请再次检查o( ̄▽ ̄)o") return page = int(stripped_arg) if page < 1: await session.send("参数似乎有点不对劲?请再次检查o( ̄▽ ̄)o") return s = get_tweeallpushlist(page) await session.send(s) logger.info(CQsessionToStr(session))
async def encodetweetid(session: CommandSession): if not headdeal(session): return await asyncio.sleep(0.2) stripped_arg = session.current_arg_text.strip() if stripped_arg == '': return if not stripped_arg.isdecimal(): await session.send("推特ID似乎搞错了呢( ̄▽ ̄)\"请仔细检查") return n = int(stripped_arg) if n < 1253881609540800000: await session.send("推特ID的值过小!") return res = encode_b64(n) logger.info(CQsessionToStr(session)) await session.send("推特ID压缩好了(o゚▽゚)o请使用:" + res)
async def mtrans(session: CommandSession): if not headdeal(session): return #message_type = session.event['message_type'] #group_id = (session.event['group_id'] if message_type == 'group' else None) user_id = session.event['user_id'] logger.info(CQsessionToStr(session)) user_id = str(user_id) if user_id in mtransopt_list: engine_func = engine_list[engine_nick[mtransopt_list[user_id] ['engine']]]['func'] res = engine_func(session.current_arg_text.strip(), mtransopt_list[user_id]['Source'], mtransopt_list[user_id]['Target']) else: res = default_engine(session.current_arg_text.strip()) await session.send("---翻译结果---\n" + res[1])
async def tweeallpushabout(session: CommandSession): if not headdeal(session): return logger.info(CQsessionToStr(session)) msg = '--转推帮助--' + "\n" + \ '!转推授权 -切换转推授权' + "\n" + \ '!addone 用户ID/UID -添加监测' + "\n" + \ '!delone 用户ID/UID -移除监测' + "\n" + \ '!DD列表 -监听列表' + "\n" + \ '!全局设置列表 无参数/基础/模版/智能/用户信息 -查看设置' + "\n" + \ '!对象设置列表 对象ID 无参数/基础/模版/智能/用户信息 -查看设置' + "\n" + \ '!全局设置 设置属性 值 -设置' + "\n" + \ '!对象设置 对象ID 设置属性 值 -设置' + "\n" + \ '!获取推文 推文ID -获取推文(仅检索缓存-待更新)' + "\n" + \ '!推文列表 无参数/#/用户ID/用户UID 无参数/页码' + "\n" + \ '注:推文列表仅读取缓存,#号标识默认用户(推送列表第一位)' + "\n" + \ '如果出现问题可以 !反馈 反馈内容 反馈信息' await session.send(msg)
async def delalltest(session: CommandSession): await asyncio.sleep(0.2) message_type = session.event['message_type'] sent_id = 0 if message_type == 'private': sent_id = session.event['user_id'] elif message_type == 'group': sent_id = session.event['group_id'] else: await session.send('未收录的消息类型:' + message_type) return sent_id = str(sent_id) res = push_list.delPushunitFromPushTo(message_type, int(sent_id), self_id=int( session.event['self_id'])) push_list.savePushList() logger.info(CQsessionToStr(session)) await session.send('已移除此地所有监测' if res[0] == True else res[1])
async def getpushlist(session: CommandSession): if not headdeal(session): return await asyncio.sleep(0.2) message_type = session.event['message_type'] group_id = (session.event['group_id'] if message_type == 'group' else None) user_id = session.event['user_id'] sent_id = 0 if message_type == 'private': sent_id = user_id elif message_type == 'group': sent_id = group_id else: await session.send('未收录的消息类型:' + message_type) return logger.info(CQsessionToStr(session)) arglimit = [{ 'name': 'page', #参数名 'des': '页码', #参数错误描述 'type': 'int', #参数类型int float str list dict (list与dict需要使用函数或正则表达式进行二次处理) 'strip': True, #是否strip 'lower': False, #是否转换为小写 'default': 1, #默认值 'func': None, #函数,当存在时使用函数进行二次处理 're': None, #正则表达式匹配(match函数) 'vlimit': { #参数限制表(限制参数内容,空表则不限制),'*':''表示匹配任意字符串,值不为空时任意字符串将被转变为这个值 } }] args = argDeal(session.current_arg_text.strip(), arglimit) if not args[0]: await session.send(args[1] + '=>' + args[2]) return args = args[1] page = args['page'] if page < 1: await session.send("页码不能为负") return s = get_pushTo_spylist(message_type, sent_id, page) await session.send(s)
async def getSetting(session: CommandSession): await asyncio.sleep(0.2) stripped_arg = session.current_arg_text.strip().lower() if stripped_arg == '': await session.send("缺少参数") return #处理用户ID tweet_user_id: int = -1 if stripped_arg.isdecimal(): tweet_user_id = int(stripped_arg) else: await session.send("用户ID错误") return res = getPushUnitSetting( session.event['message_type'], session.event[('group_id' if session.event['message_type'] == 'group' else 'user_id')], tweet_user_id) logger.info(CQsessionToStr(session)) await session.send(res[1])
async def setGroupSetting(session: CommandSession): if not headdeal(session): return await asyncio.sleep(0.2) logger.info(CQsessionToStr(session)) arglimit = [{ 'name': 'kind', #参数名 'des': 'kind', #参数错误描述 'type': 'str', #参数类型int float str list dict (list与dict需要使用函数或正则表达式进行二次处理) 'strip': True, #是否strip 'lower': False, #是否转换为小写 'default': 'basic', #默认值 'func': None, #函数,当存在时使用函数进行二次处理 're': None, #正则表达式匹配(match函数) 'vlimit': { #参数限制表(限制参数内容,空表则不限制),'*':''表示匹配任意字符串,值不为空时任意字符串将被转变为这个值 'basic': 'basic', '基础': 'basic', 'template': 'template', '模版': 'template', 'ai': 'ai', '智能': 'ai', '智能推送': 'ai', 'userinfo': 'userinfo', '用户信息': 'userinfo', '用户': 'userinfo', '个人资料': 'userinfo' } }] args = argDeal(session.current_arg_text.strip(), arglimit) if not args[0]: await session.send(args[1] + '=>' + args[2]) return args = args[1] res = getPushToSetting( session.event['message_type'], session.event[('group_id' if session.event['message_type'] == 'group' else 'user_id')], args['kind']) await session.send(res)
async def roll(session: CommandSession): if not headdeal(session): return stripped_arg = session.current_arg_text.strip() logger.info(CQsessionToStr(session)) event = session.event nick = event['user_id'] if hasattr(event, 'sender'): if 'card' in event.sender and event['sender']['card'] != '': nick = event['sender']['card'] elif 'nickname' in event.sender and event['sender']['nickname'] != '': nick = event['sender']['nickname'] #公式 res = stripped_arg.split('#', 1) #注释合成 addmsg = '' if len(res) == 2: stripped_arg = res[1] if len(res[0]) > 25: addmsg = "---{0}---\n".format(res[0]) else: addmsg = res[0] + '#' #Default if stripped_arg == '': stripped_arg = '1d100<50' elif stripped_arg[:1] in ('<', '>', '!'): stripped_arg = '1d100' + stripped_arg elif stripped_arg.isdecimal(): stripped_arg = '1d100<' + stripped_arg try: msg = match_roll(nick, stripped_arg) if msg == '': await session.send('参数不正确') return except: s = traceback.format_exc(limit=10) logger.error(s) await session.send("内部错误!") return await session.send(addmsg + msg)
async def translist(session: CommandSession): if not headdeal(session): return message_type = session.event['message_type'] group_id = (session.event['group_id'] if message_type == 'group' else None) #user_id = session.event['user_id'] if message_type != 'group': return if perm_check(session, '-switch', user=True): await session.send('操作被拒绝,权限不足(p)') return if not perm_check(session, 'trans'): await session.send('操作未授权') return logger.info(CQsessionToStr(session)) arglimit = [{ 'name': 'page', #参数名 'des': '页码', #参数错误描述 'type': 'int', #参数类型int float str list dict (list与dict需要使用函数或正则表达式进行二次处理) 'strip': True, #是否strip 'lower': False, #是否转换为小写 'default': 1, #默认值 'func': None, #函数,当存在时使用函数进行二次处理 're': None, #正则表达式匹配(match函数) 'vlimit': { #参数限制表(限制参数内容,空表则不限制),'*':''表示匹配任意字符串,值不为空时任意字符串将被转变为这个值 } }] args = argDeal(session.current_arg_text.strip(), arglimit) if not args[0]: await session.send(args[1] + '=>' + args[2]) return args = args[1] page = args['page'] if page < 1: await session.send("页码不能为负") return s = getlist(group_id, page) await session.send(s)
async def getpushlist(session: CommandSession): await asyncio.sleep(0.1) page = 1 stripped_arg = session.current_arg_text.strip().lower() if stripped_arg != '': if not stripped_arg.isdecimal(): await session.send("参数不正确") return page = int(stripped_arg) if page < 1: await session.send("参数不正确") return message_type = session.event['message_type'] sent_id = 0 if message_type == 'private': sent_id = session.event['user_id'] elif message_type == 'group': sent_id = session.event['group_id'] else: await session.send('未收录的消息类型:' + message_type) return s = get_pushTo_spylist(message_type, sent_id, page) await session.send(s) logger.info(CQsessionToStr(session))
async def transabout(session: CommandSession): if not headdeal(session): return message_type = session.event['message_type'] if message_type != 'group': return res = perm_check(session, 'trans') logger.info(CQsessionToStr(session)) msg = '当前版本为烤推机测试版V2.33' + "\n" + \ '授权状态:' + ("已授权" if res else "未授权") + "\n" + \ '!ts -切换烤推授权' + "\n" + \ '!t 推文ID 翻译 -合成翻译' + "\n" + \ '!tl -已翻译推文列表' + "\n" + \ '!gt 推文ID/推文标识 -获取最后翻译' + "\n" + \ '!tgt 任务标识 -获取指定翻译' + "\n" + \ '!gtt 推文ID/推文标识 -获取指定推文内容' + "\n" + \ '多层回复翻译:' + "\n" + \ '##1 第一层翻译' + "\n" + \ '#! 第一层层内推文(转推并评论类型里的内嵌推文)' + "\n" + \ '##2 第二层翻译' + "\n" + \ '##main 主翻译' + "\n" + \ '烤推支持换行参数,如有需要可以更换翻译自日文到任意图片或文字' + "\n" + \ '如果出现问题可以 !反馈 反馈内容 反馈信息' await session.send(msg)
async def gettrans(session: CommandSession): if not headdeal(session): return message_type = session.event['message_type'] #group_id = (session.event['group_id'] if message_type == 'group' else None) #user_id = session.event['user_id'] if message_type != 'group': return if perm_check(session, '-switch', user=True): await session.send('操作被拒绝,权限不足(p)') return if not perm_check(session, 'trans'): await session.send('操作未授权') return logger.info(CQsessionToStr(session)) def checkTweetId(a, ad): if a[:1] == '#': ta = a[1:] if not ta.isdecimal(): return None res = mintweetID.find(lambda item, val: item[1] == val, int(ta)) if res == None: return None return res[0] elif a.isdecimal() and int(a) > 1253881609540800000: return a else: res = decode_b64(a) if res == -1: return None return res arglimit = [{ 'name': 'tweet_id', #参数名 'des': '推特ID', #参数错误描述 'type': 'int', #参数类型int float str list dict (list与dict需要使用函数或正则表达式进行二次处理) 'strip': True, #是否strip 'lower': False, #是否转换为小写 'default': None, #默认值 'func': checkTweetId, #函数,当存在时使用函数进行二次处理 're': None, #正则表达式匹配(match函数) 'vlimit': { #参数限制表(限制参数内容,空表则不限制),'*':''表示匹配任意字符串,值不为空时任意字符串将被转变为这个值 } }] args = argDeal(session.current_arg_text.strip(), arglimit) if not args[0]: await session.send(args[1] + '=>' + args[2]) return args = args[1] tweet_id = args['tweet_id'] ttm = trans_tmemory.tm.copy() length = len(ttm) for i in range(length - 1, -1, -1): if ttm[i]['id'] == tweet_id: await session.send(trans_img_path + encode_b64(ttm[i]['group'],offset=0)+'-'+str(ttm[i]['tasktype']) + '.png' +"\n" + \ str('[CQ:image,timeout=' + config.img_time_out + \ ',file='+trans_img_path + encode_b64(ttm[i]['group'],offset=0)+'-'+str(ttm[i]['tasktype']) + '.png' + ']')) return await session.send("未查找到推文翻译")
async def trans(session: CommandSession): if not headdeal(session): return message_type = session.event['message_type'] #group_id = (session.event['group_id'] if message_type == 'group' else None) #user_id = session.event['user_id'] if message_type != 'group': return if perm_check(session, '-switch', user=True): await session.send('操作被拒绝,权限不足(p)') return if not perm_check(session, 'trans'): await session.send('操作未授权') return logger.info(CQsessionToStr(session)) if not rate_limit_bucket.consume(1): await session.send("烤推繁忙,请稍后再试") return def checkTweetId(a, ad): if a[:1] == '#': ta = a[1:] if not ta.isdecimal(): return None res = mintweetID.find(lambda item, val: item[1] == val, int(ta)) if res == None: return None return res[0] elif a.isdecimal() and int(a) > 1253881609540800000: return a else: res = decode_b64(a) if res == -1: return None return res arglimit = [ { 'name': 'tweet_id', #参数名 'des': '推特ID', #参数错误描述 'type': 'int', #参数类型int float str list dict (list与dict需要使用函数或正则表达式进行二次处理) 'strip': True, #是否strip 'lower': False, #是否转换为小写 'default': None, #默认值 'func': checkTweetId, #函数,当存在时使用函数进行二次处理 're': None, #正则表达式匹配(match函数) 'vlimit': { #参数限制表(限制参数内容,空表则不限制),'*':''表示匹配任意字符串,值不为空时任意字符串将被转变为这个值 } }, { 'name': 'trans', #参数名 'des': '翻译内容', #参数错误描述 'type': 'dict', #参数类型int float str list dict (list与dict需要使用函数或正则表达式进行二次处理) 'strip': True, #是否strip 'lower': False, #是否转换为小写 'default': { 'type_html': '', 'source': '', 'text': {} }, #默认值 'func': deal_trans, #函数,当存在时使用函数进行二次处理 're': None, #正则表达式匹配(match函数) 'vlimit': { #参数限制表(限制参数内容,空表则不限制),'*':''表示匹配任意字符串,值不为空时任意字符串将被转变为这个值 } } ] args = argDeal(session.current_arg_text.strip(), arglimit) if not args[0]: await session.send(args[1] + '=>' + args[2]) return pool.submit(send_res, session, args[1]) await session.send("图片合成中...")
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))
async def about(session: CommandSession): logger.info(CQsessionToStr(session)) msg = 'http://uee.me/dfRwA' await session.send(msg)
async def delOne(session: CommandSession): if not headdeal(session): return message_type = session.event['message_type'] #group_id = (session.event['group_id'] if message_type == 'group' else None) #user_id = session.event['user_id'] if perm_check(session,'-listener',user=True): await session.send('操作被拒绝,权限不足(p)') return if message_type == 'group': if not perm_check(session,'listener'): await session.send('操作被拒绝,权限不足(g)') return elif message_type != 'private': await session.send('未收录的消息类型:'+message_type) return logger.info(CQsessionToStr(session)) arglimit = [ { 'name':'tweet_user_id', #参数名 'des':'推特用户ID', #参数错误描述 'type':'str', #参数类型int float str list dict (list与dict需要使用函数或正则表达式进行二次处理) 'strip':True, #是否strip 'lower':False, #是否转换为小写 'default':None, #默认值 'func':None, #函数,当存在时使用函数进行二次处理 're':'[A-Za-z0-9_]+$', #正则表达式匹配(match函数) 're_error':'用户名/用户ID 只能包含字母、数字或下划线', 'vlimit':{ #参数限制表(限制参数内容,空表则不限制),'*':''表示匹配任意字符串,值不为空时任意字符串将被转变为这个值 } } ] args = argDeal(session.current_arg_text.strip(),arglimit) if not args[0]: await session.send(args[1] + '=>' + args[2]) return args = args[1] tweet_user_id = args['tweet_user_id'] app = ptwitterapps.getAllow('users_show') if app == None: await session.send("速率限制,请稍后再试") return if tweet_user_id.isdecimal(): res = tweetListener.tweet_event_deal.tryGetUserInfo(user_id=int(tweet_user_id)) if res == {}: res = app.users_show(user_id = int(tweet_user_id)) if res[0]: res = list(res) res[1] = tweetListener.tweet_event_deal.get_userinfo(res[1]) else: res = (True,res) else: res = tweetListener.tweet_event_deal.tryGetUserInfo(screen_name = tweet_user_id) if res == {}: res = app.users_show(screen_name = tweet_user_id) if res[0]: res = list(res) res[1] = tweetListener.tweet_event_deal.get_userinfo(res[1]) else: res = (True,res) if not res[0]: await session.send("查询不到这位V哦~复制都能弄歪来┐(゚~゚)┌") userinfo = res[1] #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] #'头像:' + '[CQ:image,timeout='+config.img_time_out+',file='+config.img_path+'userinfo/' + userinfo.screen_name + file_suffix + ']'+ "\n" + \ res = push_list.delPushunitFromPushToAndTweetUserID( session.event['message_type'], session.event[('group_id' if session.event['message_type'] == 'group' else 'user_id')], userinfo['id'] ) s = '用户UID:'+ str(userinfo['id']) + "\n" + \ '用户ID:' + userinfo['screen_name'] + "\n" + \ '用户昵称:' + userinfo['name'] + "\n" + \ '头像:' + '[CQ:image,timeout='+config.img_time_out+',file=' + userinfo['profile_image_url_https'] + ']'+ "\n" + \ ('已经从监听列表中叉出去了哦' if res[0] == True else '移除失败了Σ(゚д゚lll):'+res[1]) push_list.savePushList() await session.send(s)
async def dealfeedback(session: CommandSession): if not headdeal(session): return logger.info(CQsessionToStr(session)) arglimit = [ { 'name':'feedid', #参数名 'des':'反馈ID', #参数错误描述 'type':'int', #参数类型int float str list dict (list与dict需要使用函数或正则表达式进行二次处理) 'strip':True, #是否strip 'lower':False, #是否转换为小写 'default':None, #默认值 'func':None, #函数,当存在时使用函数进行二次处理 're':None, #正则表达式匹配(match函数) 'vlimit':{ #参数限制表(限制参数内容,空表则不限制),'*':''表示匹配任意字符串,值不为空时任意字符串将被转变为这个值 } }, { 'name':'text', #参数名 'des':'反馈内容', #参数错误描述 'type':'str', #参数类型int float str list dict (list与dict需要使用函数或正则表达式进行二次处理) 'strip':True, #是否strip 'lower':False, #是否转换为小写 'default':'', #默认值 'func':None, #函数,当存在时使用函数进行二次处理 're':None, #正则表达式匹配(match函数) 'vlimit':{ #参数限制表(限制参数内容,空表则不限制),'*':''表示匹配任意字符串,值不为空时任意字符串将被转变为这个值 } } ] args = argDeal(session.current_arg.strip(),arglimit) if not args[0]: await session.send(args[1] + '=>' + args[2]) return args = args[1] feedbackunit = feedbacktmemory.find((lambda item,val: item['id'] == val),args['feedid']) if feedbackunit == None: await session.send("未搜索到ID:" + str(args['feedid']) + " 的反馈记录") return if args['text'] == '': msg = "---历史反馈---\n" + "已处理:" + ("是" if feedbackunit['deal'] else "否") + "\n" msg = msg + "反馈ID:" + str(feedbackunit['id']) + "\n" if feedbackunit['message_type'] == 'group': msg = msg + '来自群聊 ' + feedbackunit['group_id'] + "\n" else: msg = msg + '来自私聊' + "\n" msg = msg + feedbackunit['nick'] + "(" + feedbackunit['user_id'] + ")" + "\n" msg = msg + "反馈了:" + feedbackunit['text'] await session.send(msg) return else: msg = "ID " + str(feedbackunit['id']) + " 的反馈回复:" + "\n" msg = msg + args['text'].replace('[','[').replace(']',']') try: if feedbackunit['message_type'] == 'group': await session.bot.send_msg_rate_limited( self_id=feedbackunit['self_id'], message_type=feedbackunit['message_type'], group_id=int(feedbackunit['group_id']), message=msg ) else: await session.bot.send_msg_rate_limited( self_id=feedbackunit['self_id'], message_type=feedbackunit['message_type'], user_id=int(feedbackunit['user_id']), message=msg ) except: await session.send("回复发送失败") return if not feedbackunit['deal']: feedbackunit['deal'] = True feedbacktmemory.save() await session.send("回复已发送")
async def getSetting(session: CommandSession): if not headdeal(session): return await asyncio.sleep(0.2) message_type = session.event['message_type'] group_id = (session.event['group_id'] if message_type == 'group' else None) user_id = session.event['user_id'] sent_id = 0 if message_type == 'private': sent_id = user_id elif message_type == 'group': sent_id = group_id else: await session.send('未收录的消息类型:' + message_type) return logger.info(CQsessionToStr(session)) arglimit = [ { 'name': 'tweet_user_id', #参数名 'des': '推特用户ID', #参数错误描述 'type': 'int', #参数类型int float str list dict (list与dict需要使用函数或正则表达式进行二次处理) 'strip': True, #是否strip 'lower': False, #是否转换为小写 'default': None, #默认值 'func': None, #函数,当存在时使用函数进行二次处理 're': None, #正则表达式匹配(match函数) 'vlimit': { #参数限制表(限制参数内容,空表则不限制),'*':''表示匹配任意字符串,值不为空时任意字符串将被转变为这个值 } }, { 'name': 'kind', #参数名 'des': 'kind', #参数错误描述 'type': 'str', #参数类型int float str list dict (list与dict需要使用函数或正则表达式进行二次处理) 'strip': True, #是否strip 'lower': False, #是否转换为小写 'default': 'basic', #默认值 'func': None, #函数,当存在时使用函数进行二次处理 're': None, #正则表达式匹配(match函数) 'vlimit': { #参数限制表(限制参数内容,空表则不限制),'*':''表示匹配任意字符串,值不为空时任意字符串将被转变为这个值 'basic': 'basic', '基础': 'basic', 'template': 'template', '模版': 'template', 'ai': 'ai', '智能': 'ai', '智能推送': 'ai', 'userinfo': 'userinfo', '用户信息': 'userinfo', '用户': 'userinfo', '个人资料': 'userinfo' } } ] args = argDeal(session.current_arg_text.strip(), arglimit) if not args[0]: await session.send(args[1] + '=>' + args[2]) return args = args[1] res = getPushUnitSetting(message_type, sent_id, args['tweet_user_id'], args['kind']) logger.info(CQsessionToStr(session)) await session.send(res[1])
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])
async def gettweetlist(session: CommandSession): if not headdeal(session): return await asyncio.sleep(0.2) message_type = session.event['message_type'] group_id = (session.event['group_id'] if message_type == 'group' else None) user_id = session.event['user_id'] if perm_check(session, '-listener', user=True): await session.send('操作被拒绝,权限不足(p)') return sent_id = 0 if message_type == 'private': sent_id = user_id elif message_type == 'group': if not perm_check(session, 'listener'): await session.send('操作被拒绝,权限不足(g)') return sent_id = group_id else: await session.send('未收录的消息类型:' + message_type) return logger.info(CQsessionToStr(session)) #ID为空或者#号时尝试使用默认ID def tryget(a, ad): tweet_user_id = a if tweet_user_id == '' or tweet_user_id == '#': l = push_list.getLitsFromPushTo(message_type, sent_id) if l == []: return (False, '监听列表无成员,无法置入默认值') tweet_user_id = str(l[0]['tweet_user_id']) if tweet_user_id.isdecimal(): res = tweetListener.tweet_event_deal.tryGetUserInfo( user_id=int(tweet_user_id)) if res == {}: res = (False, '缓存中不存在此用户!') else: res = (True, res) else: res = tweetListener.tweet_event_deal.tryGetUserInfo( screen_name=tweet_user_id) if res == {}: res = (False, '缓存中不存在此用户!') else: res = (True, res) return res arglimit = [ { 'name': 'userinfo', #参数名 'des': '推特用户ID', #参数错误描述 'type': 'dict', #参数类型int float str list dict (list与dict需要使用函数或正则表达式进行二次处理) 'strip': True, #是否strip 'lower': False, #是否转换为小写 'default': None, #默认值 'func': tryget, #函数,当存在时使用函数进行二次处理 'funcdealnull': True, #函数是否处理空值(控制默认值) 're': None, #正则表达式匹配(match函数) 're_error': '', 'vlimit': { #参数限制表(限制参数内容,空表则不限制),'*':''表示匹配任意字符串,值不为空时任意字符串将被转变为这个值 } }, { 'name': 'page', #参数名 'des': '页码', #参数错误描述 'type': 'int', #参数类型int float str list dict (list与dict需要使用函数或正则表达式进行二次处理) 'strip': True, #是否strip 'lower': False, #是否转换为小写 'default': 1, #默认值(不会进行二次类型转换) 'func': None, #函数,当存在时使用函数进行二次处理 're': None, #正则表达式匹配(match函数) 'vlimit': { #参数限制表(限制参数内容,空表则不限制),'*':''表示匹配任意字符串,值不为空时任意字符串将被转变为这个值 } }, ] args = argDeal(session.current_arg_text.strip(), arglimit) if not args[0]: await session.send(args[1] + '=>' + args[2]) return args = args[1] userinfo = args['userinfo'] page = args['page'] if page <= 0: await session.send("页码不正确!") return res = tweetListener.tweet_event_deal.getUserTSInCache(userinfo['id']) if res == None: await session.send("推文缓存中不存在此用户数据!") return tweets = res.tm ttr = { 'none': '发推', 'retweet': '转推', 'quoted': '转评', 'reply_to_status': '回复', 'reply_to_user': '******' } msg = userinfo['name'] + "(" + userinfo['screen_name'] + ")的推文列表" + "\n" msg = msg + "推文缩写ID,标识,推文简写内容" + "\n" unit_cout = 0 for i in range(len(tweets) - 1, -1, -1): if unit_cout >= (page - 1) * 5 and unit_cout < (page) * 5: msg = msg + ("被" if tweets[i]['trigger_remote'] else "") + ttr[ tweets[i]['type']] + ',' + encode_b64( tweets[i]['id']) + ',' + tweets[i]['text'][:20].replace( "\n", " ") + "\n" unit_cout = unit_cout + 1 totalpage = unit_cout // 5 + (0 if (unit_cout % 5 == 0) else 1) if unit_cout > 5 or page != 1: msg = msg + '页数:' + str(page) + '/' + str(totalpage) + ' ' msg = msg + '总推文缓存数:' + str(unit_cout) await session.send(msg)
async def gettweettext(session: CommandSession): if not headdeal(session): return message_type = session.event['message_type'] #group_id = (session.event['group_id'] if message_type == 'group' else None) #user_id = session.event['user_id'] if perm_check(session, '-listener', user=True): await session.send('操作被拒绝,权限不足(p)') return if message_type == 'group' and not perm_check(session, 'listener'): await session.send('操作被拒绝,权限不足(g)') return logger.info(CQsessionToStr(session)) def checkTweetId(a, ad): if a[:1] == '#': ta = a[1:] if not ta.isdecimal(): return None res = mintweetID.find(lambda item, val: item[1] == val, int(ta)) if res == None: return None return res[0] elif a.isdecimal() and int(a) > 1253881609540800000: return a else: res = decode_b64(a) if res == -1: return None return res arglimit = [{ 'name': 'tweet_id', #参数名 'des': '推特ID', #参数错误描述 'type': 'int', #参数类型int float str list dict (list与dict需要使用函数或正则表达式进行二次处理) 'strip': True, #是否strip 'lower': False, #是否转换为小写 'default': None, #默认值 'func': checkTweetId, #函数,当存在时使用函数进行二次处理 're': None, #正则表达式匹配(match函数) 'vlimit': { #参数限制表(限制参数内容,空表则不限制),'*':''表示匹配任意字符串,值不为空时任意字符串将被转变为这个值 } }] args = argDeal(session.current_arg_text.strip(), arglimit) if not args[0]: await session.send(args[1] + '=>' + args[2]) return args = args[1] tweet_id = args['tweet_id'] tweet = tweet_event_deal.tryGetTweet(tweet_id) if tweet == None: if ptwitter.ptwitterapps.hasApp(): app = ptwitter.ptwitterapps.getAllow('statuses_lookup') if app == None: await session.send("速率限制,请稍后再试!") return res = app.statuses_lookup(id=tweet_id) if not res[0] or res[1] == []: await session.send("未查找到该推文!") return tweet = ptwitter.tweet_event_deal.deal_tweet(res[1][0]) else: await session.send("未从缓存中查找到该推文!") return msg = "推文 " + encode_b64(tweet_id) + " 的内容如下:\n" msg = msg + tweet_event_deal.tweetToStr(tweet, '', 1, '') await session.send(msg)
async def setAttr(session: CommandSession): if not headdeal(session): return await asyncio.sleep(0.2) message_type = session.event['message_type'] group_id = (session.event['group_id'] if message_type == 'group' else None) user_id = session.event['user_id'] if perm_check(session, '-listener', user=True): await session.send('操作被拒绝,权限不足(p)') return sent_id = 0 if message_type == 'private': sent_id = user_id elif message_type == 'group': if not perm_check(session, 'listener'): await session.send('操作被拒绝,权限不足(g)') return sent_id = group_id else: await session.send('未收录的消息类型:' + message_type) return logger.info(CQsessionToStr(session)) arglimit = [ { 'name': 'tweet_user_id', #参数名 'des': '推特用户ID', #参数错误描述 'type': 'int', #参数类型int float str list dict (list与dict需要使用函数或正则表达式进行二次处理) 'strip': True, #是否strip 'lower': False, #是否转换为小写 'default': None, #默认值 'func': None, #函数,当存在时使用函数进行二次处理 're': None, #正则表达式匹配(match函数) 'vlimit': { #参数限制表(限制参数内容,空表则不限制),'*':''表示匹配任意字符串,值不为空时任意字符串将被转变为这个值 } }, { 'name': 'key', #参数名 'des': '设置名称', #参数错误描述 'type': 'str', #参数类型int float str list dict (list与dict需要使用函数或正则表达式进行二次处理) 'strip': True, #是否strip 'lower': False, #是否转换为小写 'default': None, #默认值 'func': None, #函数,当存在时使用函数进行二次处理 're': None, #正则表达式匹配(match函数) 'vlimit': { #参数限制表(限制参数内容,空表则不限制),'*':''表示匹配任意字符串,值不为空时任意字符串将被转变为这个值 #携带图片发送 'upimg': 'upimg', '图片': 'upimg', 'img': 'upimg', #描述设置 'des': 'des', '描述': 'des', #昵称设置 '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', 'none': 'none', '发推': 'none', #智能推送开关 'ai_retweet': 'ai_retweet', '智能转推': 'ai_retweet', 'ai_reply_to_status': 'ai_reply_to_status', '智能转发回复': 'ai_reply_to_status', 'ai_passive_reply_to_status': 'ai_passive_reply_to_status', '智能转发被回复': 'ai_passive_reply_to_status', 'ai_passive_quoted': 'ai_passive_quoted', '智能转发被转推并评论': 'ai_passive_quoted', 'ai_passive_reply_to_user': '******', '智能转发被提及': 'ai_passive_reply_to_user', #推特个人信息变动推送开关 '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_name', '昵称修改': 'change_name', 'change_description': 'change_description', '描述改变': 'change_description', '描述修改': 'change_description', 'change_headimgchange': 'change_headimgchange', '头像改变': 'change_headimgchange', '头像修改': 'change_headimgchange' } }, { 'name': 'value', #参数名 'des': '设置值', #参数错误描述 'type': 'str', #参数类型int float str list dict (list与dict需要使用函数或正则表达式进行二次处理) 'strip': True, #是否strip 'lower': False, #是否转换为小写 'default': '', #默认值 'func': None, #函数,当存在时使用函数进行二次处理 're': None, #正则表达式匹配(match函数) 'vlimit': { #参数限制表(限制参数内容,空表则不限制),'*':''表示匹配任意字符串,值不为空时任意字符串将被转变为这个值 'true': '1', '开': '1', '打开': '1', '开启': '1', 'false': '0', '关': '0', '关闭': '0', '*': '' } } ] args = argDeal(session.current_arg_text.strip(), arglimit) if not args[0]: await session.send(args[1] + '=>' + args[2]) return args = args[1] template_attr = ('retweet_template', 'quoted_template', 'reply_to_status_template', 'reply_to_user_template', 'none_template') tweet_user_id = args['tweet_user_id'] attr = args['key'] attrv = args['value'] if str(tweet_user_id) not in push_list.spylist: await session.send("用户不在监测列表内!") return if attr == 'des' or attr == 'nick' or attr in template_attr: res = push_list.setPushunitAttr(message_type, sent_id, tweet_user_id, attr, attrv) elif attrv in ('0', '1'): res = push_list.setPushunitAttr(message_type, sent_id, tweet_user_id, attr, int(attrv)) else: res = (False, '属性的值不合法!') return push_list.savePushList() await session.send(res[1])
async def permDel(session: CommandSession): message_type = session.event['message_type'] #group_id = (session.event['group_id'] if message_type == 'group' else None) user_id = session.event['user_id'] if message_type != 'private': return #if perm_check(session,'-listener',user = True): # await session.send('操作被拒绝,权限不足(p)') # return logger.info(CQsessionToStr(session)) arglimit = [ { 'name':'groupname', #参数名 'des':'权限组名', #参数错误描述 'type':'str', #参数类型int float str list dict (list与dict需要使用函数或正则表达式进行二次处理) 'strip':True, #是否strip 'lower':False, #是否转换为小写 'default':None, #默认值 'func':None, #函数,当存在时使用函数进行二次处理 're':None, #正则表达式匹配(match函数) 'vlimit':{ #参数限制表(限制参数内容,空表则不限制),'*':''表示匹配任意字符串,值不为空时任意字符串将被转变为这个值 } }, { 'name':'perm_unit', #参数名 'des':'权限组名', #参数错误描述 'type':'str', #参数类型int float str list dict (list与dict需要使用函数或正则表达式进行二次处理) 'strip':True, #是否strip 'lower':False, #是否转换为小写 'default':'', #默认值 'func':None, #函数,当存在时使用函数进行二次处理 're':None, #正则表达式匹配(match函数) 'vlimit':{ #参数限制表(限制参数内容,空表则不限制),'*':''表示匹配任意字符串,值不为空时任意字符串将被转变为这个值 } }, { 'name':'msgtype', #参数名 'des':'消息类型', #参数错误描述 'type':'str', #参数类型int float str list dict (list与dict需要使用函数或正则表达式进行二次处理) 'strip':True, #是否strip 'lower':True, #是否转换为小写 'default':message_type, #默认值 'func':None, #函数,当存在时使用函数进行二次处理 're':None, #正则表达式匹配(match函数) 'vlimit':{ #参数限制表(限制参数内容,空表则不限制),'*':''表示允许任意字符串,值不为空时任意字符串将被转变为这个值 '私聊':'private', 'private':'private', '群聊':'group', 'group':'group', '好友':'private', '群':'group', } }, { 'name':'send_id', #参数名 'des':'对象ID', #参数错误描述 'type':'int', #参数类型int float str list dict (list与dict需要使用函数或正则表达式进行二次处理) 'strip':True, #是否strip 'lower':False, #是否转换为小写 'default':user_id, #默认值 'func':None, #函数,当存在时使用函数进行二次处理 're':None, #正则表达式匹配(match函数) 'vlimit':{ #参数限制表(限制参数内容,空表则不限制),'*':''表示匹配任意字符串,值不为空时任意字符串将被转变为这个值 } } ] res = argDeal(session.current_arg_text.strip(),arglimit) if not res[0]: await session.send(res[1]+'=>'+res[2]) return args = res[1] if args['perm_unit'] == '': args['perm_unit'] = None if perm_check(args['msgtype'],args['send_id'],args['groupname'],args['perm_unit']): await session.send("该权限已存在!") return res = perm_del(args['msgtype'],args['send_id'],user_id,args['groupname'],args['perm_unit']) await session.send(res[1])
async def globalRemove(session: CommandSession): if not headdeal(session): return await asyncio.sleep(0.2) message_type = session.event['message_type'] #group_id = (session.event['group_id'] if message_type == 'group' else None) #user_id = session.event['user_id'] if perm_check(session, '-listener', user=True): await session.send('操作被拒绝,权限不足(p)') return if message_type == 'group' and not perm_check(session, 'listener'): await session.send('操作被拒绝,权限不足(g)') return logger.info(CQsessionToStr(session)) arglimit = [ { 'name': 'msgtype', #参数名 'des': '消息类型', #参数错误描述 'type': 'str', #参数类型int float str list dict (list与dict需要使用函数或正则表达式进行二次处理) 'strip': True, #是否strip 'lower': True, #是否转换为小写 'default': None, #默认值 'func': None, #函数,当存在时使用函数进行二次处理 're': None, #正则表达式匹配(match函数) 'vlimit': { #参数限制表(限制参数内容,空表则不限制),'*':''表示允许任意字符串,值不为空时任意字符串将被转变为这个值 '私聊': 'private', 'private': 'private', '群聊': 'group', 'group': 'group', '好友': 'private', '群': 'group', } }, { 'name': 'send_id', #参数名 'des': '对象ID', #参数错误描述 'type': 'int', #参数类型int float str list dict (list与dict需要使用函数或正则表达式进行二次处理) 'strip': True, #是否strip 'lower': False, #是否转换为小写 'default': None, #默认值 'func': None, #函数,当存在时使用函数进行二次处理 're': None, #正则表达式匹配(match函数) 'vlimit': { #参数限制表(限制参数内容,空表则不限制),'*':''表示匹配任意字符串,值不为空时任意字符串将被转变为这个值 } } ] res = argDeal(session.current_arg_text.strip(), arglimit) if not res[0]: await session.send(res[1] + '=>' + res[2]) return args = res[1] res = push_list.delPushunitFromPushTo(args['message_type'], args['send_id'], self_id=int( session.event['self_id'])) push_list.savePushList() await session.send(res[1])
async def addOne(session: CommandSession): if not headdeal(session): return message_type = session.event['message_type'] group_id = (session.event['group_id'] if message_type == 'group' else None) user_id = session.event['user_id'] if perm_check(session, '-listener', user=True): await session.send('操作被拒绝,权限不足(p)') return sent_id = 0 if message_type == 'private': sent_id = user_id elif message_type == 'group': if not perm_check(session, 'listener'): await session.send('操作被拒绝,权限不足(g)') return sent_id = group_id else: await session.send('未收录的消息类型:' + message_type) return logger.info(CQsessionToStr(session)) arglimit = [ { 'name': 'tweet_user_id', #参数名 'des': '推特用户ID', #参数错误描述 'type': 'str', #参数类型int float str list dict (list与dict需要使用函数或正则表达式进行二次处理) 'strip': True, #是否strip 'lower': False, #是否转换为小写 'default': None, #默认值 'func': None, #函数,当存在时使用函数进行二次处理 're': '[A-Za-z0-9_]+$', #正则表达式匹配(match函数) 'vlimit': { #参数限制表(限制参数内容,空表则不限制),'*':''表示匹配任意字符串,值不为空时任意字符串将被转变为这个值 } }, { 'name': 'nick', #参数名 'des': '昵称', #参数错误描述 'type': 'str', #参数类型int float str list dict (list与dict需要使用函数或正则表达式进行二次处理) 'strip': True, #是否strip 'lower': False, #是否转换为小写 'default': '', #默认值 'func': None, #函数,当存在时使用函数进行二次处理 're': r'[\s\S]{0,50}', #正则表达式匹配(match函数) 'vlimit': { #参数限制表(限制参数内容,空表则不限制),'*':''表示匹配任意字符串,值不为空时任意字符串将被转变为这个值 } }, { 'name': 'des', #参数名 'des': '描述', #参数错误描述 'type': 'str', #参数类型int float str list dict (list与dict需要使用函数或正则表达式进行二次处理) 'strip': True, #是否strip 'lower': False, #是否转换为小写 'default': '', #默认值 'func': None, #函数,当存在时使用函数进行二次处理 're': r'[\s\S]{0,100}', #正则表达式匹配(match函数) 'vlimit': { #参数限制表(限制参数内容,空表则不限制),'*':''表示匹配任意字符串,值不为空时任意字符串将被转变为这个值 } } ] args = argDeal(session.current_arg_text.strip(), arglimit) if not args[0]: await session.send(args[1] + '=>' + args[2]) return args = args[1] tweet_user_id = args['tweet_user_id'] #获取数据 res = tweetListener.tweet_event_deal.getUserInfo(tweet_user_id) if not res[0]: await session.send("查询不到信息,你D都能D歪来!?(・_・;?") return userinfo = res[1] nick = args['nick'] des = args['des'] if des == '': des = userinfo['name'] + '(' + userinfo['screen_name'] + ')' PushUnit = push_list.baleToPushUnit(session.event['self_id'], message_type, sent_id, userinfo['id'], user_id, user_id, des, nick=nick) res = push_list.addPushunit(PushUnit) s = '标识:'+ str(userinfo['id']) + "\n" + \ '用户ID:' + userinfo['screen_name'] + "\n" + \ '用户昵称:' + userinfo['name'] + "\n" + \ '头像:' + '[CQ:image,timeout='+config.img_time_out+',file=' + userinfo['profile_image_url_https'] + ']'+ "\n" + \ ('已经加入了DD名单了哦' if res[0] == True else '添加失败:'+res[1]) push_list.savePushList() await session.send(s)
async def getuserinfo(session: CommandSession): if not headdeal(session): return message_type = session.event['message_type'] #group_id = (session.event['group_id'] if message_type == 'group' else None) #user_id = session.event['user_id'] if perm_check(session,'-listener',user=True): await session.send('操作被拒绝,权限不足(p)') return if message_type == 'group': if not perm_check(session,'listener'): await session.send('操作被拒绝,权限不足(g)') return elif message_type != 'private': await session.send('未收录的消息类型:'+message_type) return logger.info(CQsessionToStr(session)) arglimit = [ { 'name':'tweet_user_id', #参数名 'des':'推特用户ID', #参数错误描述 'type':'str', #参数类型int float str list dict (list与dict需要使用函数或正则表达式进行二次处理) 'strip':True, #是否strip 'lower':False, #是否转换为小写 'default':None, #默认值 'func':None, #函数,当存在时使用函数进行二次处理 're':'[A-Za-z0-9_]+$', #正则表达式匹配(match函数) 're_error':'用户名/用户ID 只能包含字母、数字或下划线', 'vlimit':{ #参数限制表(限制参数内容,空表则不限制),'*':''表示匹配任意字符串,值不为空时任意字符串将被转变为这个值 } } ] args = argDeal(session.current_arg_text.strip(),arglimit) if not args[0]: await session.send(args[1] + '=>' + args[2]) return args = args[1] tweet_user_id = args['tweet_user_id'] app = ptwitterapps.getAllow('users_show') if app == None: await session.send("速率限制,请稍后再试") return if tweet_user_id.isdecimal(): res = app.users_show(user_id = int(tweet_user_id)) else: res = app.users_show(screen_name = tweet_user_id) if not res[0]: await session.send("查询不到这位V哦~复制都能弄歪来┐(゚~゚)┌") userinfo = res[1] #检测信息更新 tweetListener.tweet_event_deal.get_userinfo(userinfo,True) #tweetListener.tweet_event_deal.seve_image(userinfo.screen_name,userinfo.profile_image_url_https,'userinfo',canCover=True) #file_suffix = os.path.splitext(userinfo.profile_image_url_https)[1] #'头像:' + '[CQ:image,timeout='+config.img_time_out+',file='+config.img_path+'userinfo/' + userinfo.screen_name + file_suffix + ']'+ "\n" + \ s = '用户UID:'+ str(userinfo.id) + "\n" + \ '用户ID:' + userinfo.screen_name + "\n" + \ '用户昵称:' + userinfo.name + "\n" + \ '头像:' + '[CQ:image,timeout='+config.img_time_out+',file=' + userinfo.profile_image_url_https + ']'+ "\n" + \ '描述:' + userinfo.description + "\n" + \ '推文受保护:' + str(userinfo.protected) + "\n" + \ '被关注数:' + str(userinfo.followers_count) + "\n" + \ '关注数:' + str(userinfo.friends_count) + "\n" + \ '发推数(包括转发):' + str(userinfo.statuses_count) + "\n" + \ '账户创建时间:' + str(userinfo.created_at) logger.info(CQsessionToStr(session)) await session.send(s)