async def do_tweet_update_fetch(): logger.info('Automatically fetching tweet info...') diff_dict = await tweet.check_update() if diff_dict: bot = nonebot.get_bot() for ch_name in diff_dict: group_id_list = tweet.get_tweet_config()[ch_name]['group'] message = diff_dict[ch_name] if message[0:2] == 'RT': message = f'=== {ch_name}转发推文说 ===\n' + message elif message[0] == '@': message = f'=== {ch_name}回了一条推 ===\n' + message else: message = f'=== {ch_name}发了一条推 ===\n' + message nonebot.logger.warning(f'发现新推!来自{ch_name}:\n' f'{message}') for element in group_id_list: sanity_meter.set_user_data(0, 'tweet', 1, True) await bot.send_group_msg(group_id=element, message=message) await bot.send_private_msg( user_id=SUPER_USER, message=f'[{datetime.now().strftime("%Y-%m-%d %H:%M:%S")}] ' f'A message was sent to group: {element}\n' f'The group belongs to: {ch_name}')
async def russianRoulette(session: nonebot.CommandSession): ctx = session.ctx.copy() id_num = ctx['group_id'] if 'group_id' in ctx else ctx['user_id'] user_id = ctx['user_id'] if 'group_id' in ctx: if admin_control.get_data(ctx['group_id'], 'banned'): await session.send('已设置禁止该群的娱乐功能。如果确认这是错误的话,请联系bot制作者') return else: await session.finish('这是群组游戏!') if id_num not in game.game_dict: game.setUpDictByGroup(id_num) if user_id not in game.game_dict[id_num]["playerDict"]: game.add_player_in(group_id=id_num, user_id=user_id) else: game.add_player_play_time(group_id=id_num, user_id=user_id) play_time = game.get_play_time_with_user_id(group_id=id_num, user_id=user_id) message_id = ctx['message_id'] if not game.get_result(id_num): await session.send(f'[CQ:reply,id={message_id}]咔') else: death = game.get_death(id_num) if get_privilege(user_id, perm.OWNER): await session.send( f'[CQ:reply,id={message_id}] sv_cheats 1 -> 成功触发免死\n' '本应中枪几率为:%.2f' % (1 / (7 - death))) return await session.send( f'[CQ:reply,id={message_id}]boom!你死了。这是第%d枪,理论几率为:%.2f' % (death, (1 / (7 - death)))) sanity_meter.set_user_data(user_id, 'roulette') bot = nonebot.get_bot() if id_num == user_id: return if play_time < 3: low = 1 high = 2 else: low = 1 + play_time high = 2 + play_time rand_num = randint(low, high) if rand_num > 10: rand_num = 10 await bot.set_group_ban(group_id=id_num, user_id=user_id, duration=60 * rand_num)
async def nico_send(session: nonebot.CommandSession): ctx = session.ctx.copy() if user_control_module.get_user_privilege(ctx['user_id'], perm.BANNED): await session.finish('略略略,我主人把你拉黑了。哈↑哈↑哈') keyWord = session.get('keyWord', prompt='歪?我的关键字呢?') api = youdao.Nicowiki(keyWord=keyWord) await session.send(api.__str__()) if 'group_id' in ctx: sanity_meter.set_user_data(ctx['user_id'], 'nico')
async def can_you_be_fucking_normal(session: nonebot.CommandSession): start_time = time.time() ctx = session.ctx.copy() key_word = session.get('key_word', prompt='请输入一个关键词!') key_word = str(key_word) try: await session.send(await hhsh(key_word) + '\n本次查询耗时: %.2fs' % (time.time() - start_time)) if 'group_id' in ctx: sanity_meter.set_user_data(ctx['user_id'], 'hhsh') except Exception as e: logger.debug('Something went wrong %s' % e)
async def horseRace(session: nonebot.CommandSession): winner = session.get('winner', prompt='请输入一个胜方编号进行猜测(1-6)') race = horseRacing(winner) ctx = session.ctx.copy() user_id = ctx['user_id'] if race.ifPlay(): while not race.ifWin(): await session.send(race.getPlayResult()) await asyncio.sleep(2) if race.playerWin(): await session.send("恭喜你猜赢啦!") if 'group_id' in ctx: sanity_meter.set_user_data(user_id, 'horse_race') else: await session.send(f"啊哦~猜输了呢!其实是{race.whoWin()}号赢了哦")
async def the_poker_game(session: nonebot.CommandSession): ctx = session.ctx.copy() user_id = ctx['user_id'] if 'group_id' in ctx: if admin_control.get_data(ctx['group_id'], 'banned'): await session.send('已设置禁止该群的娱乐功能。如果确认这是错误的话,请联系bot制作者') return else: await session.finish('抱歉哦这是群组游戏。') if get_privilege(user_id, perm.OWNER): drawed_card, time_seed = poker.get_random_card(user_id, str(ctx['group_id']), rigged=10) else: drawed_card, time_seed = poker.get_random_card(user_id, str(ctx['group_id'])) stat, response = poker.compare_two(str(ctx['group_id'])) if not stat and response == -1: GLOBAL_STORE.set_store(drawed_card, ctx['group_id']) await session.send( f"玩家[CQ:at,qq={user_id}]拿到了加密过的卡:{encrypt_card(drawed_card, time_seed)}\n" f"有来挑战一下的么?\n" f"本次游戏随机种子:{time_seed}") else: if not stat and response == -2: await session.send( f"玩家[CQ:at,qq={user_id}]抓到了{drawed_card}。咳咳虽然斗争很激烈,但是平局啦!!") else: await session.send( f"玩家[CQ:at,qq={user_id}]抓到了{drawed_card}\n" f"玩家1的加密卡为:{GLOBAL_STORE.getStore(ctx['group_id'])}。\n" f"玩家[CQ:at,qq={response}]获胜!") sanity_meter.set_user_data(response, 'poker') poker.clear_result(str(ctx['group_id']))
async def sendAnswer(session: nonebot.CommandSession): start_time = time() question = session.get('question', prompt='啊?你要问我什么?') question = str(question).lower() ctx = session.ctx.copy() if get_privilege(ctx['user_id'], perm.BANNED): await session.finish() sanity_meter.set_user_data(ctx['user_id'], 'question') if match('.*?你.*?(名字|叫什么|是谁|什么东西)', question): await session.finish( f'我叫{ctx["sender"]["nickname"]}\n' f'回答用时:{(time() - start_time):.2f}s' ) # pre-processing response = _prefetch(question, ctx['user_id']) if response: await session.send( response + '\n' f'回答用时:{(time() - start_time):.2f}s' ) else: # math processing try: response = _math_fetch(question, ctx['user_id']) except Exception as err: await session.send('计算时遇到了问题,本事件已上报bot主人进行分析。') bot = nonebot.get_bot() await bot.send_private_msg( user_id=config.SUPER_USER, message=f'[{datetime.now().strftime("%Y-%m-%d %H:%M:%S")}] ' f'可能的高危行为汇报:\n' f'使用命令:!问题\n' f'错误:{err}\n' f'使用人:{ctx["user_id"]}\n' f'来自群:{ctx["group_id"] if "group_id" in ctx else -1}\n' ) return if response: await session.send( response + '\n' f'回答用时:{(time() - start_time):.2f}s' ) bot = nonebot.get_bot() await bot.send_private_msg( user_id=config.SUPER_USER, message=f'[{datetime.now().strftime("%Y-%m-%d %H:%M:%S")}] ' f'风险控制\n' f'使用命令:!问题\n' f'我的回复:\n{response}\n' f'使用人:{ctx["user_id"]}\n' f'来自群:{ctx["group_id"] if "group_id" in ctx else -1}' ) else: nonebot.logger.info(msg="It is not a normal question.") ai_process = _simple_ai_process(question, ctx) if question == ai_process: response = await _request_api_response(question) await session.send( response + f'\n' f'回答用时:{(time() - start_time):.2f}s' ) else: await session.send( ai_process + f'\n' f'回答用时:{(time() - start_time):.2f}s' )