那我问你
在前面的插件中,我们要想查看涩图,只需发送指令,但 Bot 并不能根据参数进行筛选。 如果我们想要实现此类对话模式,就需要使用会话控制
询问并获取用户输入
py
from nonebot.params import CommandArg, ArgPlainText
matcher = on_command("来张涩图")
@matcher.handle()
async def _(args: Message = CommandArg()):
if type := args.extract_plain_text():
await matcher.finish(f"正在寻找「{type}」涩图...")
@matcher.got("type", prompt="请输入你喜欢的类型")
async def got_type(type: str = ArgPlainText()):
await matcher.finish(f"正在寻找「{type}」涩图...")
py
# plugin_waiter 为 alconna 依赖,无需再次安装
from nonebot import require
from nonebot.adapters import Event
require("nonebot_plugin_waiter")
require("nonebot_plugin_alconna")
from nonebot_plugin_waiter import waiter
from nonebot_plugin_alconna import Command, Match
matcher = Command("来张涩图 [type:str]").build(use_cmd_start=True)
@matcher.handle()
async def _(type: Match[str]):
if type.available:
await matcher.finish(f"正在寻找「{type.result}」涩图...")
await matcher.send("请输入你喜欢的类型")
@waiter(waits=["message"], keep_session=True)
async def check(event: Event):
return event.get_plaintext()
resp = await check.wait(timeout=60)
if resp == "猎奇":
await matcher.finish("暂不支持此类型的涩图")
await matcher.finish(f"正在寻找「{type.result}」涩图...")