mirror of
https://github.com/TriM-Organization/LiteyukiBot-TriM.git
synced 2024-11-24 16:15:03 +08:00
✨ 优化圆角样式
This commit is contained in:
parent
1ccf94883a
commit
c171873fa6
@ -1,5 +1,6 @@
|
|||||||
from nonebot.plugin import PluginMetadata
|
from nonebot.plugin import PluginMetadata
|
||||||
from .rt_guide import *
|
from .rt_guide import *
|
||||||
|
from .crt_matchers import *
|
||||||
|
|
||||||
__plugin_meta__ = PluginMetadata(
|
__plugin_meta__ = PluginMetadata(
|
||||||
name="CRT生成工具",
|
name="CRT生成工具",
|
||||||
|
71
liteyuki/plugins/liteyuki_crt_utils/crt_matchers.py
Normal file
71
liteyuki/plugins/liteyuki_crt_utils/crt_matchers.py
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
from urllib.parse import quote
|
||||||
|
|
||||||
|
import aiohttp
|
||||||
|
from nonebot import require
|
||||||
|
|
||||||
|
from liteyuki.utils.event import get_user_id
|
||||||
|
from liteyuki.utils.base.language import Language
|
||||||
|
from liteyuki.utils.base.ly_typing import T_MessageEvent
|
||||||
|
from liteyuki.utils.base.resource import get_path
|
||||||
|
from liteyuki.utils.message.html_tool import template2image
|
||||||
|
|
||||||
|
require("nonebot_plugin_alconna")
|
||||||
|
|
||||||
|
from nonebot_plugin_alconna import UniMessage, on_alconna, Alconna, Args, Subcommand, Arparma, Option
|
||||||
|
|
||||||
|
crt_cmd = on_alconna(
|
||||||
|
Alconna(
|
||||||
|
"crt",
|
||||||
|
Subcommand(
|
||||||
|
"route",
|
||||||
|
Args["start", str, "沙坪坝"]["end", str, "上新街"],
|
||||||
|
alias=("r",),
|
||||||
|
help_text="查询两地之间的地铁路线"
|
||||||
|
),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@crt_cmd.assign("route")
|
||||||
|
async def _(result: Arparma, event: T_MessageEvent):
|
||||||
|
# 获取语言
|
||||||
|
ulang = Language(get_user_id(event))
|
||||||
|
|
||||||
|
# 获取参数
|
||||||
|
start = quote(quote(result.other_args.get("start")))
|
||||||
|
end = quote(quote(result.other_args.get("end")))
|
||||||
|
|
||||||
|
# 判断参数语言
|
||||||
|
query_lang_code = "Eng" if ulang.lang_code not in ["zh-CN", "zh-HK"] else ""
|
||||||
|
if start.isalpha() and end.isalpha():
|
||||||
|
query_lang_code = "Eng"
|
||||||
|
|
||||||
|
# 构造请求 URL
|
||||||
|
url = f"https://www.cqmetro.cn/Front/html/TakeLine!queryYs{query_lang_code}TakeLine.action?entity.startStaName={start}&entity.endStaName={end}"
|
||||||
|
|
||||||
|
# 请求数据
|
||||||
|
async with aiohttp.ClientSession() as session:
|
||||||
|
async with session.get(url) as resp:
|
||||||
|
result = await resp.json()
|
||||||
|
|
||||||
|
# 检查结果/无则终止
|
||||||
|
if not result.get("result"):
|
||||||
|
await crt_cmd.send(ulang.get("crt.no_result"))
|
||||||
|
return
|
||||||
|
|
||||||
|
# 模板传参定义
|
||||||
|
templates = {
|
||||||
|
"data": {
|
||||||
|
"result": result["result"],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# 生成图片
|
||||||
|
image = await template2image(
|
||||||
|
template=get_path("templates/crt_route.html"),
|
||||||
|
templates=templates,
|
||||||
|
debug=True
|
||||||
|
)
|
||||||
|
|
||||||
|
# 发送图片
|
||||||
|
await crt_cmd.send(UniMessage.image(raw=image))
|
@ -158,7 +158,6 @@ async def generate_chart(limit):
|
|||||||
templates={
|
templates={
|
||||||
"data": data
|
"data": data
|
||||||
},
|
},
|
||||||
debug=True
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return img
|
return img
|
||||||
|
@ -87,7 +87,7 @@ async def get_stat_msg_image(duration: int, period: int, group_id: str = None, b
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
return await template2image(get_path("templates/stat_msg.html"), templates, debug=True)
|
return await template2image(get_path("templates/stat_msg.html"), templates)
|
||||||
|
|
||||||
# if not timestamps or period_start_time != timestamps[-1]:
|
# if not timestamps or period_start_time != timestamps[-1]:
|
||||||
# timestamps.append(period_start_time)
|
# timestamps.append(period_start_time)
|
||||||
|
@ -84,20 +84,19 @@ async def get_weather_now_card(matcher: Matcher, event: T_MessageEvent, keyword:
|
|||||||
image = await template2image(
|
image = await template2image(
|
||||||
template=get_path("templates/weather_now.html", abs_path=True),
|
template=get_path("templates/weather_now.html", abs_path=True),
|
||||||
templates={
|
templates={
|
||||||
"data": {
|
"data": {
|
||||||
"params": {
|
"params" : {
|
||||||
"unit": unit,
|
"unit": unit,
|
||||||
"lang": ulang.lang_code,
|
"lang": ulang.lang_code,
|
||||||
},
|
},
|
||||||
"weatherNow": weather_now,
|
"weatherNow" : weather_now,
|
||||||
"weatherDaily": weather_daily,
|
"weatherDaily" : weather_daily,
|
||||||
"weatherHourly": weather_hourly,
|
"weatherHourly": weather_hourly,
|
||||||
"aqi": aqi,
|
"aqi" : aqi,
|
||||||
"location": location_data.dump(),
|
"location" : location_data.dump(),
|
||||||
"localization": get_local_data(ulang.lang_code)
|
"localization" : get_local_data(ulang.lang_code)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
debug=True,
|
|
||||||
wait=1
|
wait=1
|
||||||
)
|
)
|
||||||
return image
|
return image
|
||||||
|
3
liteyuki/resources/liteyuki_crt/metadata.yml
Normal file
3
liteyuki/resources/liteyuki_crt/metadata.yml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
name: CRT相关资源包
|
||||||
|
description: For Liteyuki CRT utils
|
||||||
|
version: 2024.4.26
|
22
liteyuki/resources/liteyuki_crt/templates/crt_route.html
Normal file
22
liteyuki/resources/liteyuki_crt/templates/crt_route.html
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>CRT 线路图</title>
|
||||||
|
<link rel="stylesheet" href="./css/card.css">
|
||||||
|
<link rel="stylesheet" href="./css/fonts.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="data-storage" id="data">{{ data | tojson }}</div>
|
||||||
|
|
||||||
|
<!---->
|
||||||
|
<template id="route-template">
|
||||||
|
<div class="info-box" id="route-info">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script src="./js/card.js"></script>
|
||||||
|
<script src="./js/crt_route.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
31
liteyuki/resources/liteyuki_crt/templates/js/crt_route.js
Normal file
31
liteyuki/resources/liteyuki_crt/templates/js/crt_route.js
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
// Copyright (c) 2024 SnowyKami Liteyuki Studio All Rights Reserved.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {{
|
||||||
|
* results: Array<{
|
||||||
|
* abstracts: string,
|
||||||
|
* createdDt: string,
|
||||||
|
* endStaName: string,
|
||||||
|
* startStaName: string,
|
||||||
|
* isValid: boolean,
|
||||||
|
* needTimeScope: number,
|
||||||
|
* needTransferTimes: number,
|
||||||
|
* price: number,
|
||||||
|
* skipGenerateSequence: boolean,
|
||||||
|
* transferLines: string,
|
||||||
|
* transferLinesColor: string,
|
||||||
|
* transferStaDerict: string,
|
||||||
|
* transferStaNames: string,
|
||||||
|
* }>
|
||||||
|
* }}
|
||||||
|
*/
|
||||||
|
|
||||||
|
const data = JSON.parse(document.getElementById("data").innerText);
|
||||||
|
const results = data["result"];
|
||||||
|
|
||||||
|
const solution_template = document.getElementById("route-template").innerText;
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -19,8 +19,8 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.info-box {
|
.info-box {
|
||||||
border-radius: 50px;
|
border-radius: 60px;
|
||||||
padding: 30px;
|
padding: 40px;
|
||||||
backdrop-filter: blur(10px);
|
backdrop-filter: blur(10px);
|
||||||
background-color: rgba(0, 0, 0, 0.5);
|
background-color: rgba(0, 0, 0, 0.5);
|
||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
|
15
liteyuki/utils/network/__init__.py
Normal file
15
liteyuki/utils/network/__init__.py
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
from aiohttp import ClientSession
|
||||||
|
|
||||||
|
|
||||||
|
async def simple_get(url: str) -> str:
|
||||||
|
"""
|
||||||
|
简单异步get请求
|
||||||
|
Args:
|
||||||
|
url:
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
async with ClientSession() as session:
|
||||||
|
async with session.get(url) as resp:
|
||||||
|
return await resp.text()
|
Loading…
Reference in New Issue
Block a user