2020-09-23 23:01:06 +08:00
|
|
|
|
from nonebot import on_command
|
|
|
|
|
from nonebot.rule import to_me
|
2020-12-17 21:09:30 +08:00
|
|
|
|
from nonebot.typing import T_State
|
2020-12-07 00:06:09 +08:00
|
|
|
|
from nonebot.adapters import Bot, Event
|
2020-09-23 23:01:06 +08:00
|
|
|
|
|
|
|
|
|
weather = on_command("天气", rule=to_me(), priority=1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@weather.handle()
|
2020-12-17 21:09:30 +08:00
|
|
|
|
async def handle_first_receive(bot: Bot, event: Event, state: T_State):
|
2020-12-16 23:13:00 +08:00
|
|
|
|
args = str(event.get_message()).strip() # 首次发送命令时跟随的参数,例:/天气 上海,则args为上海
|
2020-09-23 23:01:06 +08:00
|
|
|
|
print(f"==={args}===")
|
|
|
|
|
if args:
|
|
|
|
|
state["city"] = args # 如果用户发送了参数则直接赋值
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@weather.got("city", prompt="你想查询哪个城市的天气呢?")
|
2020-12-17 21:09:30 +08:00
|
|
|
|
async def handle_city(bot: Bot, state: T_State):
|
2020-09-23 23:01:06 +08:00
|
|
|
|
city = state["city"]
|
|
|
|
|
if city not in ["上海", "北京"]:
|
|
|
|
|
await weather.reject("你想查询的城市暂不支持,请重新输入!")
|
|
|
|
|
# weather = await get_weather_from_xxx(city)
|
|
|
|
|
city_weather = "晴天"
|
|
|
|
|
# await bot.send(city_weather)
|
|
|
|
|
await weather.finish(city_weather)
|