mirror of
https://github.com/LiteyukiStudio/LiteyukiBot.git
synced 2024-11-11 04:07:23 +08:00
feat: 重启时间显示
This commit is contained in:
parent
db0542279b
commit
38f658edf9
@ -15,7 +15,7 @@ weather-key # 和风天气的天气key
|
||||
```
|
||||
命令
|
||||
```shell
|
||||
weather <keywords...> # 查询目标地天气,例如:"天气 北京 海淀", "weather Tokyo Shinjuku"
|
||||
weather <keywords...> # 查询目标地实时天气,例如:"天气 北京 海淀", "weather Tokyo Shinjuku"
|
||||
bind-city <keywords...> # 绑定查询城市,个人全局生效
|
||||
别名:weather 天气
|
||||
```
|
@ -1,21 +1,22 @@
|
||||
import asyncio
|
||||
import base64
|
||||
import time
|
||||
from typing import Any
|
||||
|
||||
import nonebot
|
||||
import pip
|
||||
from git import Repo
|
||||
from nonebot import Bot, require, get_driver
|
||||
from nonebot import Bot, get_driver, require
|
||||
from nonebot.exception import MockApiException
|
||||
from nonebot.internal.matcher import Matcher
|
||||
from nonebot.permission import SUPERUSER
|
||||
|
||||
from liteyuki.utils.config import config, load_from_yaml
|
||||
from liteyuki.utils.data_manager import StoredConfig, common_db
|
||||
from liteyuki.utils.config import load_from_yaml
|
||||
from liteyuki.utils.data_manager import StoredConfig, TempConfig, common_db
|
||||
from liteyuki.utils.language import get_user_lang
|
||||
from liteyuki.utils.ly_typing import T_Bot, T_MessageEvent
|
||||
from liteyuki.utils.message import Markdown as md
|
||||
from liteyuki.utils.reloader import Reloader
|
||||
from liteyuki.utils.resource import get_loaded_resource_packs, load_resources
|
||||
|
||||
require("nonebot_plugin_alconna"), require("nonebot_plugin_htmlrender")
|
||||
from nonebot_plugin_alconna import on_alconna, Alconna, Args, Subcommand, Arparma
|
||||
@ -84,9 +85,17 @@ async def _(bot: T_Bot, event: T_MessageEvent):
|
||||
),
|
||||
permission=SUPERUSER
|
||||
).handle()
|
||||
async def _(matcher: Matcher):
|
||||
async def _(matcher: Matcher, bot: T_Bot, event: T_MessageEvent):
|
||||
await matcher.send("Liteyuki reloading")
|
||||
Reloader.reload(3)
|
||||
temp_data = common_db.first(TempConfig(), default=TempConfig())
|
||||
temp_data.data["reload"] = True
|
||||
temp_data.data["reload_time"] = time.time()
|
||||
temp_data.data["reload_bot_id"] = bot.self_id
|
||||
temp_data.data["reload_session_type"] = event.message_type
|
||||
temp_data.data["reload_session_id"] = event.group_id if event.message_type == "group" else event.user_id
|
||||
temp_data.data["delta_time"] = 0
|
||||
common_db.upsert(temp_data)
|
||||
Reloader.reload(0)
|
||||
|
||||
|
||||
@on_alconna(
|
||||
@ -197,9 +206,34 @@ async def test_for_md_image(bot: T_Bot, api: str, data: dict):
|
||||
|
||||
@driver.on_startup
|
||||
async def on_startup():
|
||||
pass
|
||||
temp_data = common_db.first(TempConfig(), default=TempConfig())
|
||||
if temp_data.data.get("reload", False):
|
||||
delta_time = time.time() - temp_data.data.get("reload_time", 0)
|
||||
temp_data.data["delta_time"] = delta_time
|
||||
common_db.upsert(temp_data) # 更新数据
|
||||
|
||||
|
||||
@driver.on_shutdown
|
||||
async def on_shutdown():
|
||||
pass
|
||||
|
||||
|
||||
@driver.on_bot_connect
|
||||
async def _(bot: T_Bot):
|
||||
temp_data = common_db.first(TempConfig(), default=TempConfig())
|
||||
if temp_data.data.get("reload", False):
|
||||
temp_data.data["reload"] = False
|
||||
reload_bot_id = temp_data.data.get("reload_bot_id", 0)
|
||||
if reload_bot_id != bot.self_id:
|
||||
return
|
||||
reload_session_type = temp_data.data.get("reload_session_type", "private")
|
||||
reload_session_id = temp_data.data.get("reload_session_id", 0)
|
||||
delta_time = temp_data.data.get("delta_time", 0)
|
||||
common_db.upsert(temp_data) # 更新数据
|
||||
await bot.call_api(
|
||||
"send_msg",
|
||||
message_type=reload_session_type,
|
||||
user_id=reload_session_id,
|
||||
group_id=reload_session_id,
|
||||
message="Liteyuki reloaded in %.2f s" % delta_time
|
||||
)
|
||||
|
@ -5,36 +5,48 @@ from liteyuki.utils.data import LiteModel
|
||||
class Location(LiteModel):
|
||||
name: str = ""
|
||||
id: str = ""
|
||||
lat: str = ""
|
||||
lon: str = ""
|
||||
adm2: str = ""
|
||||
adm1: str = ""
|
||||
country: str = ""
|
||||
tz: str = ""
|
||||
utcOffset: str = ""
|
||||
isDst: str = ""
|
||||
type: str = ""
|
||||
rank: str = ""
|
||||
fxLink: str = ""
|
||||
sources: str = ""
|
||||
license: str = ""
|
||||
|
||||
|
||||
class CityLookupResponse(LiteModel):
|
||||
code: str = ""
|
||||
location: Location = Location()
|
||||
|
||||
|
||||
class WeatherNow(LiteModel):
|
||||
time: str = ""
|
||||
city: str = ""
|
||||
obsTime: str = ""
|
||||
temp: str = ""
|
||||
feelsLike: str = ""
|
||||
icon: str = ""
|
||||
text: str = ""
|
||||
wind360: str = ""
|
||||
windDir: str = ""
|
||||
windScale: str = ""
|
||||
windSpeed: str = ""
|
||||
humidity: str = ""
|
||||
precip: str = ""
|
||||
pressure: str = ""
|
||||
vis: str = ""
|
||||
cloud: str = ""
|
||||
dew: str = ""
|
||||
sources: str = ""
|
||||
license: str = ""
|
||||
|
||||
|
||||
weather = on_command("weather", aliases={"天气", "查天气", "天气预报", "查天气预报"})
|
||||
weather_now = on_command("weather_now", aliases={"实时天气", "查实时天气", "实时天气预报", "查实时天气预报"})
|
||||
weather_forecast = on_command("weather_forecast", aliases={"天气预报", "查天气预报", "未来天气", "查未来天气"})
|
||||
weather_warning = on_command("weather_warning", aliases={"天气预警", "查天气预警", "天气警告", "查天气警告"})
|
||||
weather_life = on_command("weather_life", aliases={"生活指数", "查生活指数", "生活指数预报", "查生活指数预报"})
|
||||
weather_air = on_command("weather_air", aliases={"空气质量", "查空气质量", "空气质量预报", "查空气质量预报"})
|
||||
weather_rain = on_command("weather_rain", aliases={"降雨预报", "查降雨预报", "降雨量", "查降雨量"})
|
||||
weather_snow = on_command("weather_snow", aliases={"降雪预报", "查降雪预报", "降雪量", "查降雪量"})
|
||||
|
||||
|
||||
@weather.handle()
|
||||
async def handle_weather(bot, event):
|
||||
args = str(event.get_message()).strip()
|
||||
if not args:
|
||||
await weather.finish("请输入要查询的城市")
|
||||
else:
|
||||
pass
|
||||
|
||||
|
||||
@weather_now.handle()
|
||||
async def handle_weather_now(bot, event):
|
||||
pass
|
||||
|
||||
@weather_forecast.handle()
|
||||
async def handle_weather_forecast(bot, event):
|
||||
pass
|
||||
class WeatherNowResponse(LiteModel):
|
||||
code: str = ""
|
||||
updateTime: str = ""
|
||||
fxLink: str = ""
|
||||
now: WeatherNow = WeatherNow()
|
||||
|
15
liteyuki/plugins/liteyuki_weather/qweather.py
Normal file
15
liteyuki/plugins/liteyuki_weather/qweather.py
Normal file
@ -0,0 +1,15 @@
|
||||
from nonebot import require
|
||||
|
||||
require("nonebot_plugin_alconna")
|
||||
from nonebot_plugin_alconna import on_alconna, Alconna, Subcommand, Args, MultiVar, Arparma
|
||||
|
||||
|
||||
@on_alconna(
|
||||
aliases={"天气"},
|
||||
command=Alconna(
|
||||
"weather",
|
||||
Args["keywords", MultiVar(str)],
|
||||
),
|
||||
).handle()
|
||||
async def _(result: Arparma):
|
||||
"""await alconna.send("weather", city)"""
|
@ -1,10 +1,5 @@
|
||||
// 存放格言
|
||||
const mottos = [
|
||||
{
|
||||
"text": "人生自古谁无死,留取丹心照汗青。",
|
||||
"author": "文天祥",
|
||||
"source": "《正气歌》"
|
||||
},
|
||||
{
|
||||
"text": "同是天涯沦落人,相逢何必曾相识。",
|
||||
"author": "白居易",
|
||||
@ -15,16 +10,6 @@ const mottos = [
|
||||
"author": "王勃",
|
||||
"source": "《送杜少府之任蜀州》"
|
||||
},
|
||||
{
|
||||
"text": "人生到处知何似,应似飞鸿踏雪泥。",
|
||||
"author": "苏轼",
|
||||
"source": "《水调歌头》"
|
||||
},
|
||||
{
|
||||
"text": "大鹏一日同风起,扶摇直上九万里。",
|
||||
"author": "李白",
|
||||
"source": "《将进酒》"
|
||||
},
|
||||
{
|
||||
"text": "银烛秋光冷画屏,轻罗小扇扑流萤。",
|
||||
"author": "陆游",
|
||||
@ -32,8 +17,8 @@ const mottos = [
|
||||
},
|
||||
{
|
||||
"text": "明月几时有,把酒问青天。",
|
||||
"author": "辛弃疾",
|
||||
"source": "《水龙吟》"
|
||||
"author": "苏轼",
|
||||
"source": "《水调歌头》"
|
||||
},
|
||||
{
|
||||
"text": "逸一时,误一世,逸久逸久罢已龄",
|
||||
@ -60,4 +45,9 @@ const mottos = [
|
||||
"author": "SnowyKami",
|
||||
"source": "轻雪文档"
|
||||
},
|
||||
{
|
||||
"text": "你知道吗,轻雪的主题是基于Vue.js开发的",
|
||||
"author": "SnowyKami",
|
||||
"source": "轻雪文档"
|
||||
}
|
||||
]
|
@ -48,9 +48,14 @@ class StoredConfig(LiteModel):
|
||||
config: dict = {}
|
||||
|
||||
|
||||
class TempConfig(LiteModel):
|
||||
"""储存临时键值对的表"""
|
||||
TABLE_NAME = "temp_data"
|
||||
data: dict = {}
|
||||
|
||||
|
||||
def auto_migrate():
|
||||
user_db.auto_migrate(User())
|
||||
group_db.auto_migrate(Group())
|
||||
plugin_db.auto_migrate(InstalledPlugin(), GlobalPlugin())
|
||||
common_db.auto_migrate(GlobalPlugin(), StoredConfig())
|
||||
|
||||
common_db.auto_migrate(GlobalPlugin(), StoredConfig(), TempConfig())
|
||||
|
Loading…
Reference in New Issue
Block a user