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) index = session.get('index', prompt='你想取消哪一个订阅呢?(请发送序号)', arg_filters=[ extractors.extract_text, 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 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 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 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 subscribe(session: CommandSession): message = session.get('message', prompt='你想订阅什么内容呢?', arg_filters=[validators.not_empty('请输入有效内容哦~')]) hour = session.state.get('hour') minute = session.state.get('minute') if hour is None or minute is None: time = session.get('time', prompt='你希望我在每天的什么时候给你推送呢?\n' '(请使用24小时制,并使用阿拉伯数字表示小时和分钟)') m = re.match(r'(?P<hour>\d{1,2})[.::](?P<minute>\d{1,2})', time) if not m: m = re.match( r'(?P<hour>\d{1,2})\s*[点时]\s*' r'(?:(?P<minute>\d{1,2}|半|一刻)\s*[分]?)?', time) if m: hour = int(m.group('hour')) session.state['hour'] = hour try: minute = int(m.group('minute') or 0) except ValueError: if m.group('minute') == '半': minute = 30 elif m.group('minute') == '一刻': minute = 15 session.state['minute'] = minute else: del session.state['time'] session.pause('时间格式不对啦,请重新发送') repeat = session.get('repeat', prompt='是否希望我在推送消息的时候重复你上面发的消息内容呢?(请回答是或否)', arg_filters=[ extractors.extract_text, converters.simple_chinese_to_bool, validators.ensure_true(lambda x: x is not None, '我听不懂呀,请用是或否再回答一次呢') ]) escaped_message = message.replace('\\', '\\\\').replace('"', '\\"') if repeat: switch_arg = f'--repeat "{escaped_message}"' else: switch_arg = f'"{escaped_message}"' try: job = await scheduler.add_scheduled_commands( ScheduledCommand('switch', switch_arg), job_id=scheduler.make_job_id( PLUGIN_NAME, context_id(session.ctx), (random_string(1, string.ascii_lowercase) + random_string(7, string.ascii_lowercase + string.digits))), ctx=session.ctx, trigger='cron', hour=hour, minute=minute, replace_existing=False) session.finish(f'订阅成功啦,下次推送时间 ' f'{job.next_run_time.strftime("%Y-%m-%d %H:%M")}') except scheduler.JobIdConflictError: session.finish('订阅失败,有可能只是运气不好哦,请稍后重试~')