初始化

This commit is contained in:
ClovertaTheTrilobita 2025-01-04 22:38:51 +08:00
commit 938d5e714a
11 changed files with 181 additions and 0 deletions

3
.idea/.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
# 默认忽略的文件
/shelf/
/workspace.xml

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.venv" />
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="jdk" jdkName="Python 3.13 virtualenv at D:\projects\python\QQ-chatbot\SanYeCao-Nonebot\.venv" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View file

@ -0,0 +1,39 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredPackages">
<value>
<list size="19">
<item index="0" class="java.lang.String" itemvalue="httpx" />
<item index="1" class="java.lang.String" itemvalue="annotated-types" />
<item index="2" class="java.lang.String" itemvalue="bs4" />
<item index="3" class="java.lang.String" itemvalue="jiter" />
<item index="4" class="java.lang.String" itemvalue="trio-websocket" />
<item index="5" class="java.lang.String" itemvalue="aiohappyeyeballs" />
<item index="6" class="java.lang.String" itemvalue="h11" />
<item index="7" class="java.lang.String" itemvalue="xlwt" />
<item index="8" class="java.lang.String" itemvalue="qq-botpy" />
<item index="9" class="java.lang.String" itemvalue="chromedriver" />
<item index="10" class="java.lang.String" itemvalue="pydantic-core" />
<item index="11" class="java.lang.String" itemvalue="wsproto" />
<item index="12" class="java.lang.String" itemvalue="openai" />
<item index="13" class="java.lang.String" itemvalue="trio" />
<item index="14" class="java.lang.String" itemvalue="selenium" />
<item index="15" class="java.lang.String" itemvalue="propcache" />
<item index="16" class="java.lang.String" itemvalue="apscheduler" />
<item index="17" class="java.lang.String" itemvalue="outcome" />
<item index="18" class="java.lang.String" itemvalue="httpcore" />
</list>
</value>
</option>
</inspection_tool>
<inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<option name="ignoredErrors">
<list>
<option value="N806" />
</list>
</option>
</inspection_tool>
</profile>
</component>

View file

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

7
.idea/misc.xml Normal file
View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Black">
<option name="sdkName" value="Python 3.13 (2)" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.13 virtualenv at D:\projects\python\QQ-chatbot\SanYeCao-Nonebot\.venv" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml Normal file
View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/SanYeCao-Nonebot.iml" filepath="$PROJECT_DIR$/.idea/SanYeCao-Nonebot.iml" />
</modules>
</component>
</project>

11
README.md Normal file
View file

@ -0,0 +1,11 @@
# SanYeCao-Nonebot
## How to start
1. generate project using `nb create` .
2. install plugins using `nb plugin install` .
3. run your bot using `nb run` .
## Documentation
See [Docs](https://nonebot.dev/)

14
bot.py Normal file
View file

@ -0,0 +1,14 @@
import nonebot
from nonebot.adapters.qq import Adapter as QQAdapter
nonebot.init()
driver = nonebot.get_driver()
driver.register_adapter(QQAdapter)
nonebot.load_builtin_plugins('echo', 'single_session')
nonebot.load_from_toml("pyproject.toml")
if __name__ == "__main__":
nonebot.run()

15
example.env.prod Normal file
View file

@ -0,0 +1,15 @@
DRIVER=~fastapi+~httpx+~websockets
QQ_BOTS='
[
{
"id": "xxx",
"token": "xxx",
"secret": "xxx",
"intent": {
"c2c_group_at_messages": true
},
"use_websocket": false
}
]
'

14
pyproject.toml Normal file
View file

@ -0,0 +1,14 @@
[project]
name = "SanYeCao-Nonebot"
version = "0.1.0"
description = "SanYeCao-Nonebot"
readme = "README.md"
requires-python = ">=3.9, <4.0"
[tool.nonebot]
adapters = [
{ name = "QQ", module_name = "nonebot.adapters.qq" }
]
plugins = []
plugin_dirs = ["src/plugins"]
builtin_plugins = ["echo"]

53
src/plugins/weather.py Normal file
View file

@ -0,0 +1,53 @@
from nonebot.rule import to_me
from nonebot.plugin import on_command
import requests
weather = on_command("天气", rule=to_me(), aliases={"weather", "查天气"}, priority=10, block=True)
@weather.handle()
async def handle_function():
# await weather.send("天气是...")
city_name = "海口"
result = format_weather(city_name)
await weather.finish("天气是...\n" + result)
def get_weather(city_name):
# 设置请求的URL和参数
url = f'https://apis.juhe.cn/simpleWeather/query?key=50a3bd415158e186903d6e6994157589&city={city_name}'
# 发送GET请求
response = requests.get(url)
# 检查请求是否成功
if response.status_code == 200:
# 解析返回的JSON数据
data = response.json()
# 检查是否查询成功
if data['reason'] == '查询成功!':
# 返回天气数据
return data['result']
else:
return {"error": "查询失败: " + data['reason']}
else:
return {"error": "请求失败,状态码: " + str(response.status_code)}
def format_weather(city_name):
# 假设这里你已经有了城市的URL编码这里用'%E9%87%8D%E5%BA%86'作为示例
city_encoded = city_name # 重庆的URL编码
weather_data = get_weather(city_encoded)
# 检查是否返回了错误
if 'error' in weather_data:
return weather_data['error']
else:
# 实时天气
realtime_weather = weather_data['realtime']
result = f"实时天气:" + "\n" + f"{realtime_weather['info']}, 温度: {realtime_weather['temperature']}℃, 湿度: {realtime_weather['humidity']}%, 风向: {realtime_weather['direct']}, 风力: {realtime_weather['power']}级, AQI: {realtime_weather['aqi']}"
# 未来几天的天气
result = result + "\n" + "未来几天的天气:"
for day in weather_data['future']:
result = result + "\n" + f"日期: {day['date']}, 天气: {day['weather']}, 温度: {day['temperature']}, 风向: {day['direct']}"
return result