赞
踩
from nonebot import on_keyword,on_command from nonebot.permission import * from nonebot.rule import to_me import requests from nonebot . adapters .cqhttp import Bot,Event,Message liaotian=on_command('',rule=to_me(),priority=7) @liaotian.handle() async def handle_first_receive(bot: Bot, event: Event, state: dict): args = str(event.get_message()).strip() # 首次发送命令时跟随的参数,例:/天气 上海,则args为上海 if args: state["city"] = args # 如果用户发送了参数则直接赋值 @liaotian.got("city", prompt="你想问我什么?我是万能的哦!我会同时回答两句提供参考哟") async def handle_city(bot: Bot, event: Event, state: dict): city = state["city"] if city=='结束': await liaotian.finish('下次继续聊哦') city1=await chat(city) await liaotian.send(message=city1) await liaotian.reject() async def chat(city: str): cityname = city url_api = "http://api.qingyunke.com/api.php?key=free&appid=0&msg=" + cityname r = requests.get(url_api).json() # print(r) data = r['content'] # str=await eval(r.text)['content'] return str(data)
声明:使用本专栏源码不得对外人开放,或者表明出处
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。