async def default(session: CommandSession): message_type = session.ctx['message_type'] if message_type == 'private': if not os.path.getsize('./function/data/self_number.txt')\ or not os.path.getsize('./function/data/group_number.txt'): G_N = str( session.get( 'G_N', prompt='请初始化你要管理的一个QQ群号', arg_filters=[controllers.handle_cancellation(session)])) G_N += ' ' S_N = str( session.get( 'S_N', prompt='请输入你自己的QQ号', arg_filters=[controllers.handle_cancellation(session)])) with open('./function/data/group_number.txt', 'a') as all_group: all_group.write(G_N) with open('./function/data/self_number.txt', 'a') as self_qq: self_qq.write(S_N) await session.send('初始化设置成功') else: await session.send('不可以重复初始化')
async def free_group(session: CommandSession): number_of_group = function.plugins.report.number_of_group() your_qq_num = function.plugins.report.your_qq_num() message_type = session.ctx['message_type'] user_id = session.ctx['user_id'] if function.plugins.report.check_default(): if message_type == 'private' and user_id == int(your_qq_num[0]): duration = str( session.get( 'duration', prompt='什么时候解除禁言呀?例如7-45', arg_filters=[controllers.handle_cancellation(session)])) duration = duration.split('-') if not duration[0].isdigit() and not duration[1].isdigit(): await session.pause('时间应该是数字,例如:7,8,9') notice_of_free = session.get( 'notice_of_free', prompt='解除禁言后你想通知什么内容?', arg_filters=[controllers.handle_cancellation(session)]) notice_of_free += '[CQ:at,qq=all]' await session.send('定时解除设置成功') duration_hours = int(duration[0]) - int( time.strftime("%H", time.localtime())) duration_mins = int(duration[1]) - int( time.strftime("%M", time.localtime())) #触发器 delta = datetime.timedelta(minutes=(duration_mins + duration_hours * 60)) trigger = DateTrigger(run_date=datetime.datetime.now() + delta) for i in range(len(number_of_group)): #添加任务 scheduler.add_job( func=session.bot.send_group_msg, trigger=trigger, kwargs={ 'group_id': int(number_of_group[i]), 'message': notice_of_free }, misfire_grace_time=60, ) scheduler.add_job(func=session.bot.set_group_whole_ban, trigger=trigger, kwargs={ 'group_id': int(number_of_group[i]), 'enable': False }) else: await session.send('请先初始化')
async def add_my_skill(session: CommandSession): group_id = session.event.group_id session_type = session.event.detail_type if session_type == 'group': if not has_command_permissions(group_id): await session.send('本群组没有执行命令的权限呢QAQ') log.logger.info(f'{__name__}: 群组: {group_id} 没有命令权限, 已中止命令执行') return elif session_type == 'private': await session.send('本命令不支持在私聊中使用QAQ') log.logger.info( f'{__name__}: 用户: {session.event.user_id} 在{session_type}中使用了命令, 已中止命令执行' ) return else: log.logger.info( f'{__name__}: 用户: {session.event.user_id} 在{session_type}环境中使用了命令, 已中止命令执行' ) return __user_qq = session.event.user_id __skill_list = await query_skill_list() skill_name = session.get('skill_name', prompt='请输入你想设置的技能名称: ', arg_filters=[ controllers.handle_cancellation(session), validators.not_empty('输入不能为空') ]) if skill_name not in __skill_list: session.finish('没有这个技能哦, 请重新设置~') skill_level = session.get('skill_level', prompt='请输入你想设置的技能等级: \n可设置等级有"普通"、"熟练"、"专业"', arg_filters=[ controllers.handle_cancellation(session), validators.not_empty('输入不能为空'), validators.match_regex(r'^(普通|熟练|专业)$', '没有这个技能等级, 请重新输入~', fullmatch=True) ]) try: __result = await add_user_skill_in_db(user_qq=__user_qq, skill_name=skill_name, skill_level=skill_level) if __result: await session.send(f'为你新增了技能: 【{skill_name}/{skill_level}】') log.logger.info( f'{__name__}: 群组: {group_id}, 用户: {__user_qq} 成功新增了自己的技能') else: await session.send('添加失败, 发生了意外的错误QAQ') log.logger.info( f'{__name__}: 群组: {group_id}, 用户: {__user_qq} 新增技能失败, add_user_skill_in_db错误' ) except Exception as e: log.logger.warning( f'{__name__}: 群组: {group_id}, 用户: {__user_qq} 试图使用命令add_my_skill时发生了错误: {e}' )
async def announce(session: CommandSession): __group_id = session.get('group_id', prompt='请输入你想通知的群号: ', arg_filters=[controllers.handle_cancellation(session), validators.not_empty('输入不能为空'), validators.match_regex(r'^\d+$', '格式不对, 请重新输入~', fullmatch=True)]) __group_id = int(__group_id) if __group_id == 0: __announce_text = session.get('announce_text', prompt='【全局公告】请输入你想发布的公告内容: ', arg_filters=[controllers.handle_cancellation(session), validators.not_empty('输入不能为空')]) for group_id in query_all_notice_groups(): try: await session.bot.send_group_msg(group_id=group_id, message=__announce_text) log.logger.info(f'{__name__}: 已向群组: {__group_id} 发送通知') except Exception as e: log.logger.error(f'{__name__}: 向群组: {__group_id} 发送通知失败, error info: {e}') continue return elif __group_id == 1: __announce_text = session.get('announce_text', prompt='【命令组公告】请输入你想发布的公告内容: ', arg_filters=[controllers.handle_cancellation(session), validators.not_empty('输入不能为空')]) for group_id in query_all_command_groups(): try: await session.bot.send_group_msg(group_id=group_id, message=__announce_text) log.logger.info(f'{__name__}: 已向群组: {__group_id} 发送通知') except Exception as e: log.logger.error(f'{__name__}: 向群组: {__group_id} 发送通知失败, error info: {e}') continue return elif __group_id == 9: __announce_text = session.get('announce_text', prompt='【管理组公告】请输入你想发布的公告内容: ', arg_filters=[controllers.handle_cancellation(session), validators.not_empty('输入不能为空')]) for group_id in query_all_admin_groups(): try: await session.bot.send_group_msg(group_id=group_id, message=__announce_text) log.logger.info(f'{__name__}: 已向群组: {__group_id} 发送通知') except Exception as e: log.logger.error(f'{__name__}: 向群组: {__group_id} 发送通知失败, error info: {e}') continue return elif __group_id not in query_all_notice_groups(): log.logger.info(f'{__name__}: 群组: {__group_id} 没有通知权限, 无法发送通知') await session.send('群组未配置通知权限!') return __announce_text = session.get('announce_text', prompt='请输入你想发布的公告内容: ', arg_filters=[controllers.handle_cancellation(session), validators.not_empty('输入不能为空')]) try: await session.bot.send_group_msg(group_id=__group_id, message=__announce_text) log.logger.info(f'{__name__}: 已向群组: {__group_id} 发送通知') except Exception as e: log.logger.error(f'{__name__}: 向群组: {__group_id} 发送通知失败, error info: {e}')
async def add_skill(session: CommandSession): group_id = session.event.group_id session_type = session.event.detail_type if session_type == 'group': if not has_command_permissions(group_id): await session.send('本群组没有执行命令的权限呢QAQ') log.logger.info(f'{__name__}: 群组: {group_id} 没有命令权限, 已中止命令执行') return elif session_type == 'private': await session.send('本命令不支持在私聊中使用QAQ') log.logger.info( f'{__name__}: 用户: {session.event.user_id} 在{session_type}中使用了命令, 已中止命令执行' ) return else: log.logger.info( f'{__name__}: 用户: {session.event.user_id} 在{session_type}环境中使用了命令, 已中止命令执行' ) return # 从会话状态(session.state)中获取信息, 如果当前不存在, 则询问用户 skill_name = session.get('skill_name', prompt='即将向可用技能列表中添加技能, 开始新增技能向导~\n请输入技能名称: ', arg_filters=[ controllers.handle_cancellation(session), validators.not_empty('输入不能为空') ]) skill_description = session.get( 'skill_description', prompt='请输入技能描述: ', arg_filters=[ controllers.handle_cancellation(session), validators.not_empty('输入不能为空') ]) try: __result = await add_skill_to_db(skill_name, skill_description) if __result: await session.send( f'已添加技能【{skill_name}】\n\n技能描述: \n{skill_description}') log.logger.info( f'{__name__}: 群组: {group_id}, 用户: {session.event.user_id} 添加技能成功' ) else: await session.send('添加失败, 这个技能好像已经在技能列表中了~') log.logger.info( f'{__name__}: 群组: {group_id}, 用户: {session.event.user_id} 试图添加技能失败, 技能已在技能列表中' ) except Exception as e: log.logger.warning( f'{__name__}: 群组: {group_id}, 用户: {session.event.user_id} 试图使用命令add_skill时发生了错误: {e}' )
async def trace_moe(session: CommandSession): url = session.get('url', prompt='请提供番剧截图哦', arg_filters=[ handle_cancellation(session), extract_image_urls, not_empty('没收到图片哦,再发一次') ]) # 获取信息 await session.send("开始搜索咯,稍等哦", at_sender=True) try: success, Fan_drama_info = await fan_search(url) except Exception: print( "/////////////////////////\n{}\n/////////////////////////".format( traceback.format_exc())) await session.send("搜索过程出现问题,错误报告已打印", at_sender=True) else: if success: # 向用户发送结果 await session.finish( "\n相似度:{0[0]:.2%}\n原名:{0[1]}\n中文译名:{0[2]}\n中文别名:{0[3]}\n匹配画面出于第 {0[4]} 番\nAnilist站ID:{0[5]}\nMyanimelist站ID:{0[6]}\n首发时间:{0[7]}\n是否完结:{0[8]}" .format(Fan_drama_info), at_sender=True) else: await session.finish(Fan_drama_info, at_sender=True)
async def unsubscribe(session: CommandSession): subs = await get_subs(session.event) logger.info(f"subs: {subs}", ) index: Optional[str] = session.state.get("index") logger.info(f"session.state: {session.state}", ) if index is None: session.state["subs"] = subs await call_command( session.bot, session.ctx, ("subscribe", "show"), args={"subs": subs}, disable_interaction=True, ) if not subs: session.finish() index = session.get( "index", prompt="你想取消哪一个订阅呢?(请发送序号,或者 `取消`)", arg_filters=[ extractors.extract_text, controllers.handle_cancellation(session), ], ) if index: await handle_rm(session.event, index)
async def unsubscribe(session: CommandSession): jobs = session.state.get('jobs') or \ await get_subscriptions(session.ctx) index = session.state.get('index') if index is None: session.state['jobs'] = jobs await call_command(session.bot, session.ctx, ('subscribe', 'show'), args={'jobs': jobs}, disable_interaction=True) if not jobs: session.finish() index = session.get('index', prompt='你想取消哪一个订阅呢?(请发送序号)', arg_filters=[ extractors.extract_text, controllers.handle_cancellation(session), validators.ensure_true(str.isdigit, '请输入序号哦~'), int, ]) index = index - 1 if not (0 <= index < len(jobs)): session.finish('没有找到你输入的序号哦') job = jobs[index] if await scheduler.remove_job(job.id): session.finish('取消订阅成功') else: session.finish('出了点问题,请稍后再试吧')
async def unsubscribe(session: CommandSession): subs = await SubWrapper.get_user_sub(session.event) key: Optional[str] = session.state.get("key") if key is None: session.state["subs"] = subs await call_command( session.bot, session.ctx, ("subscribe", "show"), args={"subs": subs}, disable_interaction=True, ) if not subs: session.finish() key = session.get( "key", prompt="你想取消哪一个订阅呢?(请发送序号,或者 `取消`)", arg_filters=[ extractors.extract_text, controllers.handle_cancellation(session), ], ) if key: SubC = judge_sub(key) if not SubC: session.finish("输入序号有误!") _, msg = await SubC.del_sub(session.event, key) session.finish(msg)
async def rm(session: CommandSession): jobs = session.state.get("jobs") or await get_push_jobs(session.event) index = session.state.get("index") if index is None: session.state["jobs"] = jobs await call_command( session.bot, session.ctx, (PLUGIN_NAME, "show"), args={"jobs": jobs}, disable_interaction=True, ) if not jobs: session.finish() index = session.get( "index", prompt="你想取消哪一个提醒呢?(请发送序号)", arg_filters=[ extractors.extract_text, controllers.handle_cancellation(session), validators.ensure_true(str.isdigit, "请输入序号哦~"), int, ], ) index = index - 1 if not (0 <= index < len(jobs)): session.finish("没有找到你输入的序号哦") job = jobs[index] if await remove_job(job.id): session.finish("取消提醒成功") else: session.finish("出了点问题,请稍后再试吧")
async def _(session: CommandSession): # 去掉消息首尾的空白符 stripped_arg = session.current_arg_text.strip() handle_cancellation(session)(stripped_arg) if session.is_first_run: if stripped_arg: langunges, *code_list = stripped_arg.split(maxsplit=1) if langunges in LANGUAGES_LIST: session.state["langunges"] = langunges if code_list: code = code_list[0].strip() if code: session.state['code'] = code return if not stripped_arg: return
async def lmbtfy(session: CommandSession): keyword = session.get( 'keyword', prompt="请输入关键词", arg_filters=[handle_cancellation(session), extract_text]) await session.send("你的问题很简单,让我告诉你:\n" 'http://tool.mkblog.cn/lmbtfy/?q=' + str(base64.b64encode(keyword.encode('utf-8')))[2:-1])
async def search_pic(session: CommandSession): img_url: str = session.get('img_url', prompt='请发送要搜索的图片', arg_filters=[ controllers.handle_cancellation(session), extractors.extract_image_urls, validators.not_empty('请发送图片') ])[0] await session.send(await do_search(img_url), at_sender=True)
async def reimu(session: CommandSession): await session.send( "【隐藏插件】ReimuSearch\n" "若不清楚此模块的作用,请输入'/kill'结束命令进程\n" "本模块修改自 Angel-Hair/XUN_Bot\n\n" "[Note]\n - 大部分资源解压密码为⑨\n - 标准码使用方式请自行Google\n - 小心社会性死亡[Doge]") key_word = await session.aget('key_word', prompt='请输入搜索关键词', arg_filters=[handle_cancellation(session)]) await session.send("正在搜索,请稍后......") search_result = await get_search_result(session, key_word) logger.debug(f"Search result: {search_result}") if search_result: msg = "找到 %d 结果: \n" % len(search_result) for i, r in enumerate(search_result): msg += " 【%s】%s\n\n" % (i + 1, r[0]) msg_ret = await session.send(msg) idx = int(await session.aget( 'idx', prompt='请输入希望查看的结果序号', arg_filters=[ handle_cancellation(session), ensure_true(str.isdigit, message="无效的序号,请重新输入!(输入'取消'可终止)"), int, between_inclusive(start=1, end=len(search_result), message="序号范围错误!请重新输入~(输入'取消'可终止)") ])) try: await session.bot.delete_msg(message_id=msg_ret['message_id']) except (aiocqhttp.exceptions.ActionFailed, TypeError, KeyError): logger.warning(f"Failed to rewind msg.") downlinks = await get_download_links(session, search_result[idx - 1][1]) if downlinks: await session.send("下载链接:\n\n%s" % downlinks) else: await session.send("在本贴中未找到下载链接")
async def tips_submit(session: CommandSession): sub_tips = session.get('sub_tips', prompt='请输入你要提交的tips', arg_filters=[controllers.handle_cancellation(session)]) user_id = session.ctx['sender']['user_id'] if already_exists(sub_tips): msg = await submit_ust(sub_tips, user_id) coin = await get_cuprum(user_id) await session.send(msg + f' 当前铜币:{coin}') else: session.finish('该tips已存在')
async def subscribe(session: CommandSession): message = session.get( "message", prompt=f"你想订阅什么内容呢?(请输入序号,也可输入 `取消、不` 等语句取消):\n{get_subscribe_lst()}", arg_filters=[ controllers.handle_cancellation(session), str.lstrip, validators.not_empty("请输入有效内容哦~"), ], ) await handle_message(session.event, message)
async def couplet(session: CommandSession): input_couplet = session.get('input_couplet', prompt="请输入对联上联", arg_filters=[ handle_cancellation(session), extract_text, fit_size(max_length=20, message="您输入的上联太长了!请重新输入") ]) output_couplet = await call_api(session, input_couplet) if output_couplet: await session.send(f"上联:「{input_couplet}」\n下联:「{output_couplet}」")
async def pixivision_sub(session: CommandSession): group_id = session.event.group_id session_type = session.event.detail_type if session_type == 'group': if not has_command_permissions(group_id): await session.send('本群组没有执行命令的权限呢QAQ') log.logger.info(f'{__name__}: 群组: {group_id} 没有命令权限, 已中止命令执行') return elif session_type == 'private': await session.send('本命令不支持在私聊中使用QAQ') log.logger.info( f'{__name__}: 用户: {session.event.user_id} 在{session_type}中使用了命令, 已中止命令执行' ) return else: log.logger.info( f'{__name__}: 用户: {session.event.user_id} 在{session_type}环境中使用了命令, 已中止命令执行' ) return mode = session.get('mode', prompt='Pixivision\n【订阅】or【取消订阅】?', arg_filters=[ controllers.handle_cancellation(session), validators.not_empty('输入不能为空'), validators.match_regex(r'^(订阅|取消订阅)$', '指令不对哦, 请重新输入~', fullmatch=True) ]) if mode == '订阅': __is_success = await add_pixivsion_sub_to_db(group_id=group_id) if not __is_success: await session.send('发生了意料之外的错误QAQ') log.logger.warning( f'{__name__}: 群组: {group_id}, 用户: {session.event.user_id} ' f'试图订阅pixivision时发生了错误, 向数据库写入群组订阅失败.') return await session.send(f'已订阅Pixivision!') log.logger.info( f'{__name__}: 群组: {group_id}, 用户: {session.event.user_id} 订阅了pixivision.' ) elif mode == '取消订阅': __is_success = await clean_group_pixivsion_sub_in_db(group_id=group_id) if not __is_success: await session.send('发生了意料之外的错误QAQ') log.logger.warning( f'{__name__}: 群组: {group_id}, 用户: {session.event.user_id} ' f'试图取消订阅pixivision时发生了错误, 向数据库写入群组订阅失败.') return await session.send(f'已取消Pixivision订阅!') log.logger.info( f'{__name__}: 群组: {group_id}, 用户: {session.event.user_id} 取消了pixivision订阅.' )
async def this_is_wisdom(session: CommandSession): url = session.get('url', prompt='请提供图片素材哦', arg_filters=[ handle_cancellation(session), extract_image_urls, not_empty('没收到图片哦,再发一次') ]) text = session.get('text', prompt='请输入文案文本', arg_filters=[ handle_cancellation(session), extract_text, not_empty('没收到文案哦,再发一次') ]) # 获取信息 await session.send("稍等哦,正在生成", at_sender=True) img = await getimg(url[0]) if img: photo = await Wisdom(img, text) info = await up_img(photo) else: info = "图片下载失败" await session.finish(info, at_sender=True)
async def weather(session: CommandSession): stu_msg = await session.aget( 'stu_msg', prompt='你想让他记录的句子是?', arg_filters=[ str.strip, # 去掉两边空白字符 controllers.handle_cancellation(session), # 处理用户可能的取消指令 ]) # source = data_source.findSource(stu_msg) # if(source!=None): # session.state.pop("stu_msg") # session.pause('这句话我已经知道怎么回复了哦') stu_anwser = await session.aget( 'stu_anwser', prompt='你想让他回复的的句子是?', arg_filters=[ str.strip, # 去掉两边空白字符 controllers.handle_cancellation(session), # 处理用户可能的取消指令 ]) one = data_source.insert_one(stu_msg, stu_anwser, session.event.user_id) await session.send("俺知道了", at_sender=True)
async def enter_phantom(session: CommandSession): url_A = session.get('url_A', prompt='请提供第一张图片', arg_filters=[ handle_cancellation(session), extract_image_urls, not_empty('没收到图片哦,再发一次') ]) url_B = session.get('url_B', prompt='请提供第二张图片', arg_filters=[ handle_cancellation(session), extract_image_urls, not_empty('没收到图片哦,再发一次') ]) await session.send("开始生成咯,稍等呢", at_sender=True) # 获取信息 img_A, img_B = await getimg(url_A[0]), await getimg(url_B[0]) if img_A and img_B: photo = await phantom(img_A, img_B) info = await up_img(photo) else: info = "图片下载失败" await session.finish(info, at_sender=True)
async def img_saucenao(session: CommandSession): url = session.get('url', prompt='要识别的图片是哪张呢?', arg_filters=[ handle_cancellation(session), extract_image_urls, not_empty('没收到图片哦,再发一次') ]) # 获取信息 success, info = await QRCode_decoding(url) if success: await session.finish("识别成功\n{}\n{}\n{}\n{}\n{}".format(*info), at_sender=True) else: await session.finish(info, at_sender=True)
async def vision_porn(session: CommandSession): url = session.get( 'url', prompt='要鉴定的图片是哪张呢?', arg_filters=[ handle_cancellation(session), extract_image_urls, not_empty('没收到图片哦,再发一次') ] ) # 获取信息 comment = await vision_img(url) await session.finish(comment, at_sender=True)
async def set_my_status(session: CommandSession): group_id = session.event.group_id session_type = session.event.detail_type if session_type == 'group': if not has_command_permissions(group_id): await session.send('本群组没有执行命令的权限呢QAQ') log.logger.info(f'{__name__}: 群组: {group_id} 没有命令权限, 已中止命令执行') return elif session_type == 'private': await session.send('本命令不支持在私聊中使用QAQ') log.logger.info( f'{__name__}: 用户: {session.event.user_id} 在{session_type}中使用了命令, 已中止命令执行' ) return else: log.logger.info( f'{__name__}: 用户: {session.event.user_id} 在{session_type}环境中使用了命令, 已中止命令执行' ) return __user_qq = session.event.user_id __status = session.get('status', prompt='请输入你想设置的状态: \n可选"空闲"、"工作"', arg_filters=[ controllers.handle_cancellation(session), validators.not_empty('输入不能为空'), validators.match_regex(r'^(空闲|工作)$', '没有这个状态, 请重新输入~', fullmatch=True) ]) if __status == '空闲': __status = 0 elif __status == '工作': __status = 2 try: __result = await set_my_status_in_db(user_qq=__user_qq, user_status=__status) if __result: await session.send(f'为你设置了状态: 【{session.state["status"]}】') log.logger.info( f'{__name__}: 群组: {group_id}, 用户: {__user_qq} 为自己更新了状态') else: await session.send(f'添加失败, 发生了意外的错误QAQ\n您可能不在用户列表中, 请联系管理员处理') log.logger.info( f'{__name__}: 群组: {group_id}, 用户: {__user_qq} 设置状态失败, 用户不在用户列表中' ) except Exception as e: log.logger.warning( f'{__name__}: 群组: {group_id}, 用户: {__user_qq} 试图使用命令set_my_status时发生了错误: {e}' )
async def subscribe(session: CommandSession): message = session.get( "message", prompt=f"你想订阅什么内容呢?(请输入序号,也可输入 `取消、不` 等语句取消):\n{get_subscribe_str()}", arg_filters=[ controllers.handle_cancellation(session), str.strip, validators.not_empty("请输入有效内容哦~"), ], ) SubC = judge_sub(message) if not SubC: session.finish("输入序号有误!") _, msg = await SubC.add_sub(session.event, message) session.finish(msg)
async def rm(session: CommandSession, args: str): group_id = session.event.group_id if not group_id: logger.debug("Group only cmd is called in private chat!") session.finish("请在群组中使用本命令!") group_id = str(group_id) rules = load_rules(force_reload=True) if not args.split(): logger.debug(f"Got an empty arg!") await session.finish("无效的参数!\n" "使用方法: /keyword rm [触发词]\n" "示例: /keyword rm 笨蛋") return if not group_id in rules: logger.debug(f"No trigger words have been set for group {group_id}.") session.finish("本群组尚未设置关键词触发规则,请使用 '/keyword add' 命令添加") group_rules = rules[group_id] m = [k for k in group_rules.keys() if args in k] if m: msg = f"匹配 '{args}' 的触发词: \n" + '\n'.join( [F' »【{i+1}】{t}' for i, t in enumerate(m)]) await session.send(msg) idx = int(await session.aget( 'idx', prompt="请输入要删除的触发关键词序号 (输入'取消'可终止命令)", arg_filters=[ handle_cancellation(session), ensure_true(str.isdigit, message="无效的序号!请重输 (输入'取消'可终止命令)"), int, between_inclusive(start=1, end=len(m), message="序号范围错误!请重输 (输入'取消'可终止命令)") ])) del rules[group_id][m[idx - 1]] if not rules[group_id]: del rules[group_id] dump_rules(rules) logger.info(f"Removed trigger word '{args}' for group {group_id}.") await session.send("删除成功!") else: logger.debug(f"Trigger word '{args}' not found!") await session.send(f"未找到匹配 '{args}' 的触发词! 请使用 '/keyword ls' 查看所有触发词")
async def gomoku(session: CommandSession): if not __enabled__: logger.warning("Gomoku plugin is disabled due to the failure of loading clib. See https://233a344a455.github.io/DeltaBot/setup.html#gomoku%E6%A8%A1%E5%9D%97-%E4%BA%94%E5%AD%90%E6%A3%8B-%E5%AE%89%E8%A3%85.") await session.send('插件未启用!') return await session.send("游戏开始!\n" "玩家黑棋,机器人白棋\n" "落子格式: 例如'e9'或'E9'\n" "字母在前数字在后,不分大小写") g = GomokuGame(clib, context_id(session.ctx, use_hash=True)) await session.send(MessageSegment.image(g.get_img())) await asyncio.sleep(0.5) while True: inp = await session.aget('input', force_update=True, prompt="请玩家落子", arg_filters=[ str.strip, not_empty(message="输入不能为空!请重新输入"), handle_cancellation(session), match_regex(r'[a-oA-O](1[0-5]|[1-9])', fullmatch=True, message="无效的输入!请重新输入\n落子格式: 例如'e9'或'E9'," "字母在前数字在后,不分大小写\n【发送'取消'结束游戏】")]) x, y = re.match(r'([a-oA-O])(1[0-5]|[1-9])', inp).groups() x, y = ALPHABET.index(x.upper()), int(y) - 1 if not g.set_chess(x, y, USER): await session.send(f"位置'{inp}'已存在旗子,请重新输入") continue sco = -g.estimate() g.update_display() if sco > 1e6: await session.send("恭喜!你赢了" + MessageSegment.image(g.get_img())) return x, y = g.search() g.set_chess(x, y, BOT) g.display.draw_chess(x, y, BOT, high_lighted=True) sco = -g.estimate() if sco < -1e6: await session.send("你输啦 ~\(≧▽≦)/~" + MessageSegment.image(g.get_img())) return await session.send(f"估计分数: {sco}" + MessageSegment.image(g.get_img())) await asyncio.sleep(0.8)
async def couplet(session: CommandSession): qqnum = str(session.ctx['user_id']) global BLACK_LIST if qqnum in BLACK_LIST: return global AVAILABLE if not AVAILABLE: return input_couplet = session.get('input_couplet', prompt="请输入对联上联", arg_filters=[ handle_cancellation(session), extract_text, fit_size(max_length=20, message="上联太长了!重新输入吧") ]) output_couplet = await call_api(session, input_couplet) if output_couplet: await session.send(f"上联:「{input_couplet}」\n下联:「{output_couplet}」")
async def MurphyisLaw(session: CommandSession): buildnum = session.get_optional('num', default=1) buildtype = session.get('type', prompt='要建造哪个类型呢?', arg_filters=[ match_regex( pattern=r'轻|轻型|重|重型|特|特型|限|限时|[a-dA-D1-4]', message='格式不正确,请重输', fullmatch=True), handle_cancellation(session), ]) for i in TYPE: if buildtype in TYPE[i]: if buildnum > 10: buildnum = 10 buildresult = await startshipbuilding(i, buildnum) break await session.finish("\n建造类型:{}\n建造次数:{}\n{}".format( buildtype, buildnum, buildresult), at_sender=True)
async def img_saucenao(session: CommandSession): url = session.get( 'url', prompt='要搜索的图片是哪张呢?', arg_filters=[ handle_cancellation(session), extract_image_urls, not_empty('没收到图片哦,再发一次') ] ) # 获取信息 success, img_info = await get_img(url) if success: # 向用户发送结果 await session.finish("\n相似度: {info}作品链接: {url[0]}\n画师主页: {url[1]}\n其他相关链接{url[2]}\n预览图: {thumbnail}".format(**img_info), at_sender=True) else: #info = await ascii2d_api(url) info = False img_info += """,转用ascii2d引擎搜索 ascii2d引擎搜索结果: 色彩搜索: 最相似来源结果:{0[0]} 作品名:{0[1]} 该作品链接:{0[2]} 作者名:{0[3]} 该作者链接:{0[4]} 预览图:{0[5]} \n######\n 特征搜索: 最相似来源结果:{1[0]} 作品名:{1[1]} 该作品链接:{1[2]} 作者名:{1[3]} 该作者链接:{1[4]} 预览图:{1[5]}""".format(*info) if info else "\n所有引擎均未成功匹配" await session.finish(img_info, at_sender=True)