Ⓜ️手动从旧梦 81a191f merge

This commit is contained in:
2024-08-12 11:44:30 +08:00
parent 068feaa591
commit 2d67a703bd
214 changed files with 6457 additions and 10418 deletions

View File

@ -169,3 +169,20 @@ async def get_airquality(
async with httpx.AsyncClient() as client:
resp = await client.get(url, params=params)
return resp.json()
async def get_astronomy(
key: str,
location: str,
date: str,
dev: bool = get_memory_data("is_dev", True),
) -> dict:
url_path = f"v7/astronomy/sun?"
url = dev_url + url_path if dev else com_url + url_path
params = {
"key" : key,
"location" : location,
"date" : date,
}
async with httpx.AsyncClient() as client:
resp = await client.get(url, params=params)
return resp.json()

View File

@ -1,3 +1,5 @@
import datetime
from nonebot import require, on_endswith
from nonebot.adapters import satori
from nonebot.adapters.onebot.v11 import MessageSegment
@ -50,6 +52,9 @@ async def get_weather_now_card(matcher: Matcher, event: T_MessageEvent, keyword:
qw_lang = get_qw_lang(ulang.lang_code)
key = get_config("weather_key")
is_dev = get_memory_data("weather.is_dev", True)
extra_info = get_config("weather_extra_info")
attr = get_config("weather_attr")
user: User = user_db.where_one(User(), "user_id = ?", event_utils.get_user_id(event), default=User())
# params
unit = user.profile.get("unit", "m")
@ -80,6 +85,7 @@ async def get_weather_now_card(matcher: Matcher, event: T_MessageEvent, keyword:
weather_daily = await get_weather_daily(key, location_data.id, lang=qw_lang, unit=unit, dev=is_dev)
weather_hourly = await get_weather_hourly(key, location_data.id, lang=qw_lang, unit=unit, dev=is_dev)
aqi = await get_airquality(key, location_data.id, lang=qw_lang, dev=is_dev)
weather_astronomy = await get_astronomy(key, location_data.id, date=datetime.datetime.now().strftime('%Y%m%d'), dev=is_dev)
image = await template2image(
template=get_path("templates/weather_now.html", abs_path=True),
@ -89,12 +95,17 @@ async def get_weather_now_card(matcher: Matcher, event: T_MessageEvent, keyword:
"unit": unit,
"lang": ulang.lang_code,
},
"weatherNow" : weather_now,
"weatherDaily" : weather_daily,
"weatherHourly": weather_hourly,
"aqi" : aqi,
"location" : location_data.dump(),
"localization" : get_local_data(ulang.lang_code)
"weatherNow" : weather_now,
"weatherDaily" : weather_daily,
"weatherHourly" : weather_hourly,
"aqi" : aqi,
"location" : location_data.dump(),
"localization" : get_local_data(ulang.lang_code),
"weatherAstronomy" : weather_astronomy,
"is_dev" : 1 if is_dev else 0,
"extra_info" : extra_info,
"attr" : attr
}
},
)

View File

@ -1,9 +1,11 @@
from nonebot.plugin import PluginMetadata
from .npm import *
from .rpm import *
__author__ = "snowykami"
__plugin_meta__ = PluginMetadata(
name="轻雪包管理器v2",
description="详细看文档",
description="npm & rpm",
usage=(
"npm list\n"
"npm enable/disable <plugin_name>\n"
@ -13,8 +15,9 @@ __plugin_meta__ = PluginMetadata(
type="application",
homepage="https://github.com/snowykami/LiteyukiBot",
extra={
"liteyuki": True,
"toggleable" : False,
"default_enable" : False,
"liteyuki" : True,
"toggleable" : False,
"always_on" : True,
"default_enable": False,
}
)

View File

View File

@ -0,0 +1,69 @@
# npm update/upgrade
# npm search
# npm install/uninstall
# npm list
from nonebot import require
require("nonebot_plugin_alconna")
from nonebot_plugin_alconna import (
on_alconna,
Alconna,
Args,
MultiVar,
Subcommand,
Option
)
"""包管理器alc"""
npm_alc = on_alconna(
aliases={"插件", "nonebot-plugin-manager"},
command=Alconna(
"npm",
Subcommand(
"list",
Args["page", int, 1]["num", int, 10],
alias={"ls", "列表", "列出"},
dest="list installed plugins",
help_text="列出已安装插件",
),
Subcommand(
"search",
Args["keywords", MultiVar(str)],
alias=["s", "搜索"],
dest="search plugins",
help_text="搜索本地商店插件,需自行更新",
),
Subcommand(
"install",
Args["package_name", str],
alias=["i", "安装"],
dest="install plugin",
help_text="安装插件",
),
Subcommand(
"uninstall",
Args["package_name", str],
alias=["u", "卸载"],
dest="uninstall plugin",
help_text="卸载插件",
),
Subcommand(
"update",
alias={"更新"},
dest="update local store index",
help_text="更新本地索引库",
),
Subcommand(
"upgrade",
Args["package_name", str],
Option(
"package_name",
Args["package_name", str, None], # Optional
),
alias={"升级"},
dest="upgrade all plugins without package name",
help_text="升级插件",
),
),
)

View File

@ -0,0 +1,31 @@
import json
from pathlib import Path
import aiofiles
from pydantic import BaseModel
from src.utils.base.config import get_config
from src.utils.io import fetch
NONEBOT_PLUGIN_STORE_URL: str = "https://registry.nonebot.dev/plugins.json" # NoneBot商店地址
LITEYUKI_PLUGIN_STORE_URL: str = "https://bot.liteyuki.icu/assets/plugins.json" # 轻雪商店地址
class Session:
def __init__(self, session_type: str, session_id: int | str):
self.session_type = session_type
self.session_id = session_id
async def update_local_store_index() -> list[str]:
"""
更新本地插件索引库
Returns:
新增插件包名列表list[str]
"""
url = "https://registry.nonebot.dev/plugins.json"
save_file = Path(get_config("data_path"), "data/liteyuki") / "pacman/plugins.json"
raw_text = await fetch(url)
data = json.loads(raw_text)
with aiofiles.open(save_file, "w") as f:
await f.write(raw_text)

View File