async def _(session: CommandSession): if not u.check_zhuanfa(session): return bot = nonebot_local.get_bot() mongo_db = bot.config.mongo_db['keientist'] if not u.check_1st_control(session): return argv = session.args['argv'] try: qq = int(argv[0]) except ValueError: await session.send('请输入正确的QQ号') return filter_ = {'qq': qq} qq_data = await u.db_executor(mongo_db.zhuanfa_user.find_one, filter_) if qq_data: av_dict = { av['av']: av['title'] for av in list(await u.db_executor(mongo_db.zhuanfa_list.find, {})) } msg = '转发明细:\n' msg += '\n'.join([ '标题: {}\n转发次数: {}'.format(av_dict[key], qq_data['data'][key]['count']) for key in qq_data['data'].keys() ]) msg += '\n本机器人替小妹谢谢你的支持' else: msg = '要么是QQ号输错了,要么是目前还木有转发记录' await session.send(msg)
async def _(): bot = nonebot_local.get_bot() mongo_db = bot.config.mongo_db['keientist'] data = await u.web_get( 'https://api.bilibili.com/x/relation/stat?vmid=364225566') follower = str(data['data']['follower']) now = datetime.datetime.now() insert_data = {'t': now.strftime("%Y-%m-%d %H"), 'count': int(follower)} await u.db_executor(mongo_db.fans_count.insert, insert_data) last_hour = now - datetime.timedelta(hours=1) filter_ = {'t': last_hour.strftime("%Y-%m-%d %H")} hours = 0 while True: hours += 1 check_last_hour = await u.db_executor(mongo_db.fans_count.find_one, filter_) if check_last_hour: break else: last_hour -= datetime.timedelta(hours=1) filter_ = {'t': last_hour.strftime("%Y-%m-%d %H")} fans_update = (int(follower) - check_last_hour["count"]) / hours message = f'现在{now.hour}点整啦!\n此时小妹拥有了{follower}个粉丝\n' + \ f'较上一个小时{"涨" if fans_update >= 0 else "掉"}粉{int(abs(fans_update))}' if now.hour == 0: last_day = now - datetime.timedelta(days=1) filter_ = {'t': last_day.strftime("%Y-%m-%d %H")} check_last_day = await u.db_executor(mongo_db.fans_count.find_one, filter_) fans_update = int(follower) - check_last_day["count"] message += f'\n较昨天相比{"涨" if fans_update >= 0 else "掉"}粉{int(abs(fans_update))}' if random.randint(1, 3) == 1 or now.hour == 0: await u.batch_send_msg(bot.config.report_time_list, message)
async def _(session: CommandSession): bot = nonebot_local.get_bot() if session.ctx['user_id'] not in bot.config.settle_list: return mongo_db = bot.config.mongo_db['keientist'] await u.db_executor(mongo_db.zhuanfa_user.remove, {}) msg = '本月转发数据已初始化' await session.send(msg)
async def _(): bot = nonebot_local.get_bot() mongo_db = bot.config.mongo_db['keientist'] data = await u.web_get( 'https://api.bilibili.com/x/tag/detail?pn=1&ps=20&tag_id=8402119') data_revdol = await u.web_get( 'https://api.bilibili.com/x/web-interface/search/type?page=1&order=pubdate&keyword=战' '斗吧歌姬&duration=0&__refresh__=true&search_type=video&tids=0&highlight=1&single_col' 'umn=0') for archive in data['data']['news']['archives']: if int(archive['owner']['mid']) in bot.config.black_list: continue if archive.get('aid'): av_id = 'av' + str(archive['aid']) else: av_id = '-1' bv_id = archive['bvid'] filter_ = {'av': av_id} check_data = await u.db_executor(mongo_db.bili_av.find_one, filter_) check_data_bv = await u.db_executor(mongo_db.bili_av.find_one, {'bv': bv_id}) if check_data or check_data_bv: pass else: msg = await get_msg(archive['owner']['mid'], archive['owner']['name'], archive['title'], av_id, bot, bv_id) await u.batch_send_msg(bot.config.check_status_list, msg) if av_id != '-1': insert_data = {'av': av_id, 'read': True, 'bv': bv_id} else: insert_data = {'read': True, 'bv': bv_id} await u.db_executor(mongo_db.bili_av.insert, insert_data) for result in data_revdol['data']['result']: if int(result['mid']) in bot.config.black_list: continue if result.get('aid'): av_id = 'av' + str(result['aid']) else: av_id = '-1' filter_ = {'av': av_id} bv_id = result['bvid'] check_data = await u.db_executor(mongo_db.bili_av.find_one, filter_) check_data_bv = await u.db_executor(mongo_db.bili_av.find_one, {'bv': bv_id}) if check_data or check_data_bv: pass else: msg = await get_msg(result['mid'], result['author'], result['title'], av_id, bot, bv_id) await u.batch_send_msg(bot.config.check_status_list, msg) if av_id != '-1': insert_data = {'av': av_id, 'read': True, 'bv': bv_id} else: insert_data = {'read': True, 'bv': bv_id} await u.db_executor(mongo_db.bili_av.insert, insert_data)
async def _(session: CommandSession): if not u.check_zhuanfa(session): return bot = nonebot_local.get_bot() content = str(session.ctx['message']) try: title = content.split('text=')[1].split('…,url=')[0] await send_feedback(session, title.strip(), content, bot, type=2) except IndexError: print('type_hd') print(content)
async def _(session: CommandSession): if not u.check_zhuanfa(session): return bot = nonebot_local.get_bot() content = session.ctx['message'][0]['data']['content'] try: title = content.split('"title":"')[1].split('"')[0] await send_feedback(session, title, content, bot, type=2) except IndexError: print('111111111111111111111111111') print(content)
async def _(session: CommandSession): if not u.check_zhuanfa(session): return msgs = session.ctx['message'] for msg in msgs: if msg['type'] == 'image': mongo_db = nonebot_local.get_bot().config.mongo_db['keientist'] now = datetime.datetime.now() insert_data = {'t': now.strftime("%Y-%m-%d %H:%M:%S"), 'file': msg['data']['file'], 'url': msg['data']['url'], 'qq': session.ctx['user_id']} await u.db_executor(mongo_db.img_status.insert, insert_data) print(insert_data)
async def _(session: CommandSession): bot = nonebot_local.get_bot() if session.ctx['user_id'] not in bot.config.settle_list: return mongo_db = bot.config.mongo_db['keientist'] rank_data = list(await u.db_executor(mongo_db.zhuanfa_user.find, {})) rank_list = [{ 'qq': rank['qq'], 'count': sum([rank['data'][key]['count'] for key in rank['data'].keys()]) } for rank in rank_data] rank_list.sort(key=lambda x: x['count'], reverse=True) msg = '\n'.join([ 'QQ: {}, 转发数: {}'.format(rank['qq'], rank['count']) for rank in rank_list ]) await session.send(msg)
async def _(session: CommandSession): if not u.check_1st_control(session): return mongo_db = nonebot_local.get_bot().config.mongo_db['keientist'] data = list(await u.db_executor(mongo_db.img_status.find, {})) cal = dict() url = dict() for img_ in data: cal[img_['file']] = cal.get(img_['file'], 0) + 1 url[img_['file']] = img_['url'] img_list = [{'file': k, 'cal': v, 'url': url[k]} for k, v in cal.items()] img_list.sort(key=lambda x: x['cal'], reverse=True) if len(img_list) > 5: img_list = img_list[:5] msg = '当前使用数量排名前{}的表情包\n'.format(len(img_list)) msg += '\n'.join(['MD5: {}, 使用数: {}{}'.format(img_['file'].split('.')[0], img_['cal'], '[CQ:image,file={},url={}]'.format(img_['file'], img_['url'])) for img_ in img_list]) await session.send(msg)
async def _(session: CommandSession): bot = nonebot_local.get_bot() if not u.check_zhuanfa(session): return content = session.ctx['message'][0]['data']['content'] try: av = content.split('www.bilibili.com/video/')[1].split('/?p=')[0] data = await u.web_get( 'https://api.bilibili.com/x/web-interface/view?bvid={}'.format( av[2:])) mid = data['data']['owner']['mid'] if mid in bot.config.zhuanfa: await send_feedback(session, data['data']['title'], content, bot) except Exception: try: title = content.split('"desc":"')[1].split('"')[0] await send_feedback(session, title, content, bot, type=1) except IndexError: print('111111111111111111111111111') print(content)
async def _(session: CommandSession): if not u.check_zhuanfa(session): return bot = nonebot_local.get_bot() mongo_db = bot.config.mongo_db['keientist'] rank_data = list(await u.db_executor(mongo_db.zhuanfa_user.find, {})) rank_list = [{ 'qq': rank['qq'], 'count': sum([rank['data'][key]['count'] for key in rank['data'].keys()]) } for rank in rank_data] rank_list.sort(key=lambda x: x['count'], reverse=True) if len(rank_list) > 10: rank_list = rank_list[:10] msg = '当前转发数排名前{}用户\n'.format(len(rank_list)) msg += '\n'.join([ 'QQ: {}, 转发数: {}'.format(rank['qq'], rank['count']) for rank in rank_list ]) msg += '\n每个视频每天只会记录一次转发哦~~各位再接再厉\n转发群: 228415488' await session.send(msg)
import requests import asyncio import json import nonebot_local from bs4 import BeautifulSoup from aiocqhttp.exceptions import Error as CQHttpError bot = nonebot_local.get_bot() async def web_get(url): loop = asyncio.get_running_loop() text = await loop.run_in_executor(None, requests.get, url) if '</html>' in text.text: soup = BeautifulSoup(text.text, 'lxml') data = soup.pre.contents else: data = text.text return json.loads(data) async def db_executor(method, data): loop = asyncio.get_running_loop() return await loop.run_in_executor(None, method, data) async def batch_send_msg(groups, msg): for group in groups: try: await bot.send_group_msg(group_id=group, message=msg) except CQHttpError:
async def _(session: CommandSession): bot = nonebot_local.get_bot() argv = session.args['argv'] if len(argv) == 0: await session.send('缺少参数') return cmd = argv[0] argv = argv[1:] if cmd == 'new': # 限制少数人拥有权限才可开启 if not check_swiss_control(session, bot): await session.send('您并不能开启一个新比赛,如有需要请联系超管开通权限') return swiss = await get_swiss(session, bot) if swiss: await session.send('当前群内已有开启状态的比赛\nID:{}\n名称:{}'.format( str(swiss['_id']), swiss['name'])) return if len(argv) < 1: await session.send('缺少比赛名称') return swiss = new_swiss(session, argv[0]) await save_swiss(bot, swiss) await session.send('创建成功,名称:{}'.format(swiss['name'])) return elif cmd == 'add': # 由加入选手输入,swiss add 11111,由发起人输入+qq号 swiss = await get_swiss(session, bot) if not swiss: await session.send('当前群内无开启状态的比赛') return if len(argv) == 0: qq = session.ctx['user_id'] swiss['player'][str(qq)] = new_player( qq, session.ctx['sender']['card']) await session.send("选手已登记\nQQ:{}\n昵称:{}".format( qq, session.ctx['sender']['card'])) await save_swiss(bot, swiss) return elif len(argv) == 2: if session.ctx['user_id'] != swiss['qq']: await session.send('当前群内比赛并不是您主持的') else: swiss['player'][str(argv[0])] = new_player(argv[0], argv[1]) await session.send("选手已登记\nQQ:{}\n昵称:{}".format( argv[0], argv[1])) await save_swiss(bot, swiss) return else: await session.send('参数数量错误') return elif cmd == 'next': # todo 由发起人输入,进入下一轮,输出排表 swiss = await get_swiss(session, bot) if session.ctx['user_id'] != swiss['qq']: await session.send('当前群内比赛并不是您主持的') else: check_scb_next, result = check_swiss_can_be_next(swiss) if not check_scb_next: msg = '当前以下桌次未完成比赛:\n' msg += '\n'.join([ 'No.{},{} vs {}'.format( table['index'], swiss['player'][str(table['left'])]['name'], swiss['player'][str(table['right'])]['name']) for table in result ]) await session.send(msg) else: swiss = next_swiss(swiss) await print_game_status(swiss, session) await save_swiss(bot, swiss) return elif cmd == 'game_status': # todo 由选手和发起人输入,显示排表,第几轮,比分输入情况 success, err, swiss = await check_swiss_all(session, bot) if not success: await session.send(err) return print(1) await print_game_status(swiss, session) return elif cmd == 'player_status': # todo 由选手和发起人输入,显示选手积分小分对手胜率等等 success, err, swiss = await check_swiss_all(session, bot) if not success: await session.send(err) return if swiss['round'] == 0 or swiss['round'] == 1: await session.send('当前比赛并没有具体比分') return players = get_players_status(swiss) await print_players_status(swiss, players, session) return elif cmd == 'result': # todo swiss result qq11111 2 1或者swiss result no22 2 success, err, swiss = await check_swiss_owner(session, bot) if not success: await session.send(err) return if len(argv) != 3: await session.send('参数数量不对') return try: left = int(argv[1]) right = int(argv[2]) no = int(argv[0][2:]) except ValueError: await session.send('参数类型不对') return final_score_left, final_score_right = -1, -1 if argv[0][:2] == 'qq': zhuo = -1 for index, table in enumerate(swiss['table_rank'][swiss['round'] - 1]): if table['left'] == no: table['result'] = [left, right] final_score_left, final_score_right = left, right zhuo = index break if table['right'] == no: table['result'] = [right, left] final_score_left, final_score_right = right, left zhuo = index break if zhuo == -1: await session.send('该QQ未找到对应桌次') return elif argv[0][:2] == 'no': try: swiss['table_rank'][swiss['round'] - 1][no - 1]['result'] = [left, right] final_score_left, final_score_right = left, right except IndexError: await session.send('该No未找到对应桌次') return zhuo = no - 1 else: await session.send('参数格式不对') return table = swiss['table_rank'][swiss['round'] - 1][zhuo] await session.send('第{}桌,{} VS {},比分:{}:{},已记录'.format( zhuo + 1, swiss['player'][str(table['left'])]['name'], swiss['player'][str(table['right'])]['name'] if table['right'] != 0 else '轮空', final_score_left, final_score_right)) await save_swiss(bot, swiss) elif cmd == 'cancel': # todo 取消比分:swiss cancel qq11111 或者swiss cancel no22 success, err, swiss = await check_swiss_owner(session, bot) if not success: await session.send(err) return if len(argv) != 1: await session.send('参数数量不对') return try: no = int(argv[0][2:]) except ValueError: await session.send('参数类型不对') return if argv[0][:2] == 'qq': for table in swiss['table_rank'][swiss['round'] - 1]: if table['left'] == no or table['right'] == no: table['result'] = [-1, -1] break elif argv[0][:2] == 'no': swiss['table_rank'][swiss['round'] - 1][no - 1]['result'] = [-1, -1] else: await session.send('参数格式不对') return await save_swiss(bot, swiss) elif cmd == 'delete': # todo 选手退出比赛:swiss delete 11111,由发起人输入,仅限第一轮之前 success, err, swiss = await check_swiss_owner(session, bot) if not success: await session.send(err) return if len(argv) != 1: await session.send('参数数量不对') return try: no = int(argv[0]) except ValueError: await session.send('参数类型不对') return swiss['player'].pop(str(no)) await save_swiss(bot, swiss) elif cmd == 'end': # todo 比赛结束:swiss end,由发起人输入 success, err, swiss = await check_swiss_owner(session, bot) if not success: await session.send(err) return swiss['open'] = Code.SWISS_CLOSE await save_swiss(bot, swiss) await session.send('{}比赛已关闭 at {}'.format( swiss['name'], datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))) elif cmd == 'help': # todo 帮助 msg = "1,新建比赛:swiss new,限制少数人拥有权限才可开启\n" \ "2,加入比赛:swiss add,由加入选手输入,swiss add 11111,由发起人输入+qq号\n" \ "3,进入下一轮:swiss next 由发起人输入,进入下一轮,输出排表\n" \ "4,状态1:swiss game_status 由选手,发起人输入,显示排表,第几轮,比分输入情况\n" \ "5,状态2:swiss player_status 由选手,发起人输入,显示选手积分小分对手胜率等等\n" \ "6,输入比分:swiss result qq11111 2 1或者swiss result no22 2 1,\n" \ "由发起人输入,表示qq号11111的选手2比1赢,或者第22桌前者2比后者1赢。每输入一桌会显示还剩几桌\n" \ "7,取消比分:swiss cancel qq11111 或者swiss cancel no22\n" \ "8,选手退出比赛:swiss delete 11111,由发起人输入,仅限第一轮之前\n" \ "9,比赛结束:swiss end,由发起人输入\n" \ "10,返回上一轮`:swiss back" await session.send(msg) elif cmd == 'back': # todo 上一轮 success, err, swiss = await check_swiss_owner(session, bot) if not success: await session.send(err) return if swiss['round'] == 0: await session.send('已经是第一轮了') return swiss['round'] -= 1 swiss['table_rank'] = swiss['table_rank'][:-1] await save_swiss(bot, swiss) await session.send('已退回上一轮,当前轮数:{}'.format(swiss['round'])) else: await session.send('“{}”命令不能识别'.format(cmd)) return
async def _(session: NoticeSession): bot = nonebot_local.get_bot() if session.ctx['group_id'] not in bot.config.new_number_list: return await session.send('欢迎新战姬众~[CQ:at,qq={}]\n请认真看完置顶的群公告'.format( session.ctx['user_id']))