async def update_boss_handler(bot: cqhttp.Bot, event: cqhttp.GroupMessageEvent, state: typing.T_State): # Request valid confirmation for update while True: if str(event.get_message()).strip( ) not in InteractionMessage.CONFIRMATION_MESSAGE: await update_boss.reject(InteractionMessage.INVALID_ARG) else: break user_confirm = str(event.get_message()).strip() if user_confirm.startswith(InteractionMessage.CONFIRMATION_MESSAGE[1]): # Do not update await update_boss.finish(message=InteractionMessage.RECORD_CHANGE_ABORT ) else: new_info = { 'id': int(str(state['new_info'][0]).strip()), 'alias': str(state['new_info'][1]).strip(), 'health': int(str(state['new_info'][2]).strip()) } update_result = await boss_database.update(new_info) if update_result['status'] != DBStatusCode.UPDATE_SUCCESS: if bot.config.debug: await bot.send_private_msg(user_id=plugin_config.AUTHOR, message=str(update_result['error'])) await update_boss.finish('\n'.join([ InteractionMessage.RECORD_CHANGE_FAIL, InteractionMessage.ERROR_MESSAGE ])) else: await update_boss.finish( message=InteractionMessage.RECORD_CHANGE_SUCCESS)
async def remove_boss_handler(bot: cqhttp.Bot, event: cqhttp.GroupMessageEvent, state: typing.T_State): # Request valid confirmation for deletion while True: if str(event.get_message()).strip( ) not in InteractionMessage.CONFIRMATION_MESSAGE: await remove_boss.reject(InteractionMessage.INVALID_ARG) else: break user_confirm = str(event.get_message()).strip() if user_confirm.startswith(InteractionMessage.CONFIRMATION_MESSAGE[1]): # Do not delete await remove_boss.finish(message=InteractionMessage.RECORD_CHANGE_ABORT ) else: remove_result = await boss_database.remove(state['boss_id']) if remove_result['status'] != DBStatusCode.DELETE_SUCCESS: if bot.config.debug: await bot.send_private_msg(user_id=plugin_config.AUTHOR, message=str(remove_result['error'])) await remove_boss.finish('\n'.join([ InteractionMessage.RECORD_CHANGE_FAIL, InteractionMessage.ERROR_MESSAGE ])) else: await remove_boss.finish( message=InteractionMessage.RECORD_CHANGE_SUCCESS)
async def update_boss_first_receive(bot: cqhttp.Bot, event: cqhttp.GroupMessageEvent, state: typing.T_State): raw_args = str(event.get_message()).strip() if raw_args: arg_list = raw_args.split(plugin_config.separator) state['new_info'] = arg_list
async def search_boss_first_receive(bot: cqhttp.Bot, event: cqhttp.GroupMessageEvent, state: typing.T_State): raw_message = event.get_message() arg_list, prior_id = None, None if len(raw_message) != 0: for segment in raw_message: if segment['type'] == 'at': # checking for @message and extract qq_id from it as member_id prior_id = segment['data']['qq'] else: arg_list = list( map( lambda x: str(x).strip(), str(segment['data']['text']).strip().split( plugin_config.separator))) if len(arg_list) < 1 or len(arg_list) > 2: await add_team.finish(InteractionMessage.INVALID_ARG) elif len(arg_list) == 2: state['team_id'] = arg_list[1] state['member_id'] = arg_list[0] state['member_id'] = prior_id if (prior_id is not None) else (state.get( 'member_id', event.user_id))
async def _(bot: Bot, event: GroupMessageEvent): global cd if str(event.group_id) not in cd: cd[str(event.group_id)] = int(time.time()) ## 初始化cd if cd[str(event.group_id)] <= int(time.time()): keyword = event.get_message().__str__().strip() response = requests.get( "https://api.lolicon.app/setu/?apikey={0}&r18={1}&keyword={2}&num={3}&proxy=i.pixiv.cat&size1200=false" .format("698604975f3623bd7ed1d0", "2", keyword, 3)) data = json.loads(response.text) if data["code"] == 0: cd[str(event.group_id)] = int(time.time()) + 60 quota = data["quota"] if keyword == "": await setu.send("正在获取涩图,今日剩余可调用 {0} 次".format(quota)) else: await setu.send("正在获取 [{0}] 涩图,今日剩余可调用 {1} 次".format( keyword, quota)) for i in data["data"]: content = "\n标题: {0} (PID: {1})".format(i["title"], i["pid"]) content += "\n作者: {0} (UID: {1})".format(i["author"], i["uid"]) try: await setu.send(MessageSegment.image(i["url"]) + content) except Exception as e: print(e) elif data["code"] == 404: await setu.send("没有符合条件的涩图") else: await setu.send("获取失败") else: await setu.finish( Message(f"CD还剩 {cd[str(event.group_id)] - int(time.time())} 秒,请节制") )
async def remove_record_handler(bot: cqhttp.Bot, event: cqhttp.GroupMessageEvent, state: typing.T_State): raw_args = str(event.get_message()).strip() arg_list = list(map(str.strip, raw_args.split(plugin_config.separator))) if len(arg_list) != 3: # Not enough arguments have been provided await add_record.finish(InteractionMessage.INVALID_ARG_NUMBER) remove_identifiers = { 'member_id': arg_list[0], 'boss_id': arg_list[1], 'damage': arg_list[2] } remove_result = await record_database.remove(remove_identifiers) if remove_result['status'] == DBStatusCode.DELETE_SUCCESS: await remove_record.finish(InteractionMessage.RECORD_CHANGE_SUCCESS) else: if bot.config.debug: await bot.send_private_msg(user_id=plugin_config.AUTHOR, message=str(remove_result['error'])) await remove_record.finish('\n'.join([ InteractionMessage.RECORD_CHANGE_FAIL, InteractionMessage.ERROR_MESSAGE ]))
async def _(bot: Bot, event: GroupMessageEvent): keyword = event.get_message().__str__().strip() global cp if keyword in keywords: keywords.remove(keyword) Save_Config() await disable_monitor.send("成功将关键词 [{0}] 移除监控列表".format(keyword)) else: await disable_monitor.send("关键词 [{0}] 不在监控列表,无效操作".format(keyword))
async def _(bot: Bot, event: GroupMessageEvent): keyword = event.get_message().__str__().strip() print(keyword) global cp if keyword in keywords: await enable_monitor.send("关键词 [{0}] 已在监控列表, 请勿重复操作".format(keyword)) else: keywords.append(keyword) Save_Config() await enable_monitor.send("成功将关键词 [{0}] 添加到监控列表".format(keyword))
async def _(bot: Bot, event: GroupMessageEvent): tem = str(event.get_message()) qid = re.findall(r"\d+", tem)[0] try: mid = readJson()[qid][1] except Exception as e: print(e) await withdraw.finish(message=Message('只能撤回他最后一次涩图')) return await bot.delete_msg(message_id=mid)
async def _(bot: Bot, event: GroupMessageEvent): msg: Message = event.get_message() for item in msg: if item.type == 'text': group_id = str(event.group_id) with open(f'/var/www/chat_data/{group_id}_chat.log', 'a+') as file: if not await redis_client.exists(group_id): await redis_client.set(group_id, True) file.write("\n") file.write(f"{item.data.get('text')}\n") await redis_client.expire(group_id, 60)
async def _(bot: Bot, event: GroupMessageEvent): msg: MessageSegment = event.get_message().pop() if msg.type == "image": async with httpx.AsyncClient() as client: image = await client.get(msg.data['url']) im = Image.open(io.BytesIO(image.content)) pre: List[Dict[str, float]] = predict(im) if not pre: return elif pre[0]["score"] > 0.9: await recognition.finish(f" 一定是 {pre[0]['name']} 拉") return elif pre[0]["score"] > 0.7: await recognition.finish(f"我猜是 {pre[0]['name']} ")
async def _(bot: Bot, event: GroupMessageEvent): tem = str(event.get_message()) qid = re.findall(r"\d+", tem)[0] print(qid) if event.get_user_id() in nonebot.get_driver().config.superusers: try: mid = readJson()[qid][1] except Exception as e: print(e) await withdraw.finish('只能撤回他最后一次涩图') return await bot.delete_msg(message_id=mid) else: await withdraw.finish('你没有权利撤回哦')
async def add_team_handler(bot: cqhttp.Bot, event: cqhttp.GroupMessageEvent, state: typing.T_State): while True: action = str(event.get_message()).strip() if action == 'confirm': if not state['team_list']: await add_team.reject(prompt=InteractionMessage.NOT_ENOUGH_TEAM ) else: break elif action == 'abort': await add_team.finish(InteractionMessage.RECORD_CHANGE_ABORT) else: card = action.split(plugin_config.separator) if len(card) != 2: await add_team.reject( prompt=InteractionMessage.INVALID_ARG_NUMBER) else: state['team_list'].append(card[0]) state['us_list'].append(card[1]) await add_team.reject( prompt=InteractionMessage.REPEATE_ADD_TEAM_CARD) team_info = { 'member_id': state['member_id'], 'team_id': state['team_id'], 'team_list': ','.join(state['team_list']), 'us_list': ','.join(state['us_list']) } print(team_info) add_result = await ds.tc.add(team_info) print(add_result) if add_result['error'] is None: await add_team.finish(InteractionMessage.RECORD_CHANGE_SUCCESS) else: if bot.config.debug: await bot.send_private_msg(user_id=plugin_config.AUTHOR, message=add_result['func_info']) await bot.send_private_msg(user_id=plugin_config.AUTHOR, message=add_result['error']) await add_team.finish('\n'.join([ InteractionMessage.RECORD_CHANGE_FAIL, InteractionMessage.ERROR_MESSAGE ]))
async def add_record_first_receive(bot: cqhttp.Bot, event: cqhttp.GroupMessageEvent, state: typing.T_State): raw_args = str(event.get_message()).strip() arg_list = list(map(str.strip, raw_args.split(plugin_config.separator))) if len(arg_list) < 4 or len(arg_list) > 7: # Not enough arguments have been provided await add_record.finish(InteractionMessage.INVALID_ARG_NUMBER) elif len(arg_list) > 4: # turn, time, member_id might be provided for arg in arg_list[4:]: arg_check = _single_checker(arg) state[arg_check[0]] = arg_check[1] state['base_info'] = arg_list[0:4] state['turn'] = state.get('turn', plugin_config.default_revue_turn) state['time'] = state.get('time', int(time.time())) state['member_id'] = state.get('member_id', event.user_id)
async def add_team_first_receive(bot: cqhttp.Bot, event: cqhttp.GroupMessageEvent, state: typing.T_State): raw_message = event.get_message() arg_list, prior_id = None, None if len(raw_message) != 0: for segment in raw_message: if segment['type'] == 'at': # checking for @message and extract qq_id from it as member_id prior_id = segment['data']['qq'] else: arg_list = list( map( lambda x: str(x).strip(), str(segment['data']['text']).strip().split( plugin_config.separator))) if len(arg_list) < 1 or len(arg_list) > 2: await add_team.finish(InteractionMessage.INVALID_ARG) elif len(arg_list) == 2: state['member_id'] = arg_list[1] else: await add_team.reject(prompt=InteractionMessage.REQUEST_ARG) state['member_id'] = prior_id if (prior_id is not None) else (state.get( 'member_id', event.user_id)) state['team_id'] = int(arg_list[0]) # check if there is already a team belongs to the given member team_existence = await ds.tc.search_team(state['member_id'], state['team_id']) if team_existence['response']['result']: await add_team.finish(InteractionMessage.RECORD_ALREADT_EXIST) else: state['team_list'] = [] state['us_list'] = [] await add_team.pause(prompt=InteractionMessage.REPEATE_ADD_TEAM_CARD)
async def add_record_first_receive(bot: cqhttp.Bot, event: cqhttp.GroupMessageEvent, state: typing.T_State): raw_message = event.get_message() # received arguments, parsing arg_list, prior_id = None, None for segment in raw_message: if segment['type'] == 'at': # checking for @message and extract qq_id from it as member_id prior_id = segment['data']['qq'] else: # standard input arguments arg_list = list( map( lambda x: str(x).strip(), str(segment['data']['text']).strip().split( plugin_config.separator))) if len(arg_list) < 4 or len(arg_list) > 7: await add_record.finish(InteractionMessage.INVALID_ARG) elif len(arg_list) > 4: # turn, time, member_id might be provided for arg in arg_list: arg_check = _single_checker(arg) state[arg_check[0]] = arg_check[1] # No arguments received if len(raw_message) == 0 or arg_list is None: await add_record.reject(prompt=InteractionMessage.REQUEST_ARG) # all arguments should have been processed except the 4 basic ones # base_info[0:4] should be corresponds to sequence, boss_id, team, damage state['base_info'] = arg_list[0:4] state['turn'] = state.get('turn', plugin_config.default_revue_turn) state['date_time'] = state.get('date_time', int(time.time())) state['member_id'] = prior_id if (prior_id is not None) else (state.get( 'member_id', event.user_id))
async def _(bot: Bot, event: GroupMessageEvent): global last_message message = str(event.get_message()) # await bot.send(event, str(message)) # await bot.send(event, str("CQ:image" in message and "url=" in message)) if message == last_message: tem = "打断复读" + random.randint(1, 10) * '!' last_message = tem await block_repeat.finish(message=tem) elif "CQ:image" in message and "url=" in message and b64encode(requests.get(str(message) [str(message).find("url=") + 4:-1]).content) \ .decode() == last_message: tem = "打断复读" + random.randint(1, 10) * '!' last_message = tem await block_repeat.finish(message=tem) else: if "CQ:image" in message and "url=" in message: last_message = b64encode( requests.get(str(message)[str(message).find("url=") + 4:-1]).content).decode() else: last_message = message
async def remove_team_handler(bot: cqhttp.Bot, event: cqhttp.GroupMessageEvent, state: typing.T_State): raw_args = str(event.get_message()).strip() arg_list = list(map(str.strip, raw_args.split(plugin_config.separator))) remove_identifier = {'member_id': arg_list[0]} try: remove_identifier['team_id'] = int(arg_list[1]) except ValueError: await remove_team.finish(InteractionMessage.INVALID_ARG) remove_result = await ds.tc.delete(**remove_identifier) if remove_result['error'] is None: await remove_team.finish(InteractionMessage.RECORD_CHANGE_SUCCESS) else: if bot.config.debug: await bot.send_private_msg(user_id=plugin_config.AUTHOR, message=remove_result['func_info']) await bot.send_private_msg(user_id=plugin_config.AUTHOR, message=remove_result['error']) await remove_team.finish('\n'.join([ InteractionMessage.RECORD_CHANGE_FAIL, InteractionMessage.ERROR_MESSAGE ]))
async def update_boss_parser(bot: cqhttp.Bot, event: cqhttp.GroupMessageEvent, state: typing.T_State): state[state['_current_key']] = str(event.get_message()).strip().split( plugin_config.separator)
async def remove_boss_first_receive(bot: cqhttp.Bot, event: cqhttp.GroupMessageEvent, state: typing.T_State): raw_args = str(event.get_message()).strip() if raw_args: state['boss_id'] = int(raw_args)
async def remove_boss_parser(bot: cqhttp.Bot, event: cqhttp.GroupMessageEvent, state: typing.T_State): state[state['_current_key']] = int(str(event.get_message()).strip())
async def _(bot: Bot, event: GroupMessageEvent): if str(event.group_id) in [ "1098933683", "913211173", "993211173", "1124718762" ]: msg: Message = event.get_message() await chat.finish(predict(str(msg)))