mirror of
https://github.com/ChenXu233/nonebot_plugin_dialectlist.git
synced 2024-11-27 17:45:07 +08:00
💩 🍻 高考出分怒写代码
This commit is contained in:
parent
471585beb0
commit
ff49f38ae1
@ -56,7 +56,7 @@ from .utils import (
|
|||||||
got_rank,
|
got_rank,
|
||||||
msg_counter,
|
msg_counter,
|
||||||
persist_id2user_id,
|
persist_id2user_id,
|
||||||
parse_datetime
|
parse_datetime,
|
||||||
)
|
)
|
||||||
|
|
||||||
__plugin_meta__ = PluginMetadata(
|
__plugin_meta__ = PluginMetadata(
|
||||||
@ -81,18 +81,20 @@ class SameTime(ArparmaBehavior):
|
|||||||
if type is None and time:
|
if type is None and time:
|
||||||
interface.behave_fail()
|
interface.behave_fail()
|
||||||
|
|
||||||
|
|
||||||
def wrapper(slot: Union[int, str], content: Optional[str]) -> str:
|
def wrapper(slot: Union[int, str], content: Optional[str]) -> str:
|
||||||
if slot == "type" and content:
|
if slot == "type" and content:
|
||||||
return content
|
return content
|
||||||
return "" # pragma: no cover
|
return "" # pragma: no cover
|
||||||
|
|
||||||
|
|
||||||
rank_cmd = on_alconna(
|
rank_cmd = on_alconna(
|
||||||
Alconna(
|
Alconna(
|
||||||
"B话榜",
|
"B话榜",
|
||||||
Args["type?", ["今日", "昨日", "本周", "上周", "本月", "上月", "年度", "历史"]][
|
Args["type?", ["今日", "昨日", "本周", "上周", "本月", "上月", "年度", "历史"]][
|
||||||
"time?", str,
|
"time?",
|
||||||
"group_id?", int
|
str,
|
||||||
],
|
]["group_id?", str],
|
||||||
behaviors=[SameTime()],
|
behaviors=[SameTime()],
|
||||||
),
|
),
|
||||||
aliases={"废话榜"},
|
aliases={"废话榜"},
|
||||||
@ -110,6 +112,7 @@ rank_cmd.shortcut(
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# 这段函数完全抄的词云
|
# 这段函数完全抄的词云
|
||||||
@rank_cmd.handle()
|
@rank_cmd.handle()
|
||||||
async def _group_message(
|
async def _group_message(
|
||||||
@ -117,13 +120,15 @@ async def _group_message(
|
|||||||
session: Session = Depends(extract_session),
|
session: Session = Depends(extract_session),
|
||||||
type: Optional[str] = None,
|
type: Optional[str] = None,
|
||||||
time: Optional[str] = None,
|
time: Optional[str] = None,
|
||||||
group_id: Optional[int] = None,
|
group_id: Optional[str] = None,
|
||||||
):
|
):
|
||||||
|
|
||||||
dt = get_datetime_now_with_timezone()
|
dt = get_datetime_now_with_timezone()
|
||||||
|
|
||||||
if not group_id:
|
if group_id is None:
|
||||||
state["group_id"] = session.id2
|
group_id = session.id2
|
||||||
|
|
||||||
|
state["group_id"] = group_id
|
||||||
|
|
||||||
if not type:
|
if not type:
|
||||||
await rank_cmd.finish(__plugin_meta__.usage)
|
await rank_cmd.finish(__plugin_meta__.usage)
|
||||||
@ -191,15 +196,25 @@ async def _group_message(
|
|||||||
prompt="请输入你要查询的结束日期(如 2022-02-22)",
|
prompt="请输入你要查询的结束日期(如 2022-02-22)",
|
||||||
parameterless=[Depends(parse_datetime("stop"))],
|
parameterless=[Depends(parse_datetime("stop"))],
|
||||||
)
|
)
|
||||||
|
@rank_cmd.got("group_id", prompt="请输入你要查询的群号。")
|
||||||
async def handle_rank(
|
async def handle_rank(
|
||||||
bot: Bot,
|
bot: Bot,
|
||||||
event: Event,
|
event: Event,
|
||||||
session: Session = Depends(extract_session),
|
session: Session = Depends(extract_session),
|
||||||
start: datetime = Arg(),
|
start: datetime = Arg(),
|
||||||
stop: datetime = Arg(),
|
stop: datetime = Arg(),
|
||||||
|
group_id: str = Arg(),
|
||||||
):
|
):
|
||||||
|
if group_id:
|
||||||
|
id = group_id
|
||||||
|
else:
|
||||||
|
id = session.id2
|
||||||
|
|
||||||
|
if not id:
|
||||||
|
await saa.Text("没有指定群哦").finish()
|
||||||
|
|
||||||
messages = await get_message_records(
|
messages = await get_message_records(
|
||||||
session=session,
|
id2s=[id],
|
||||||
id_type=SessionIdType.GROUP,
|
id_type=SessionIdType.GROUP,
|
||||||
include_bot_id=False,
|
include_bot_id=False,
|
||||||
include_bot_type=False,
|
include_bot_type=False,
|
||||||
@ -240,10 +255,10 @@ async def handle_rank(
|
|||||||
|
|
||||||
bar = Bar(init_opts=opts.InitOpts(theme=ThemeType.LIGHT))
|
bar = Bar(init_opts=opts.InitOpts(theme=ThemeType.LIGHT))
|
||||||
bar.add_xaxis(nicknames)
|
bar.add_xaxis(nicknames)
|
||||||
bar.add_yaxis("B话数量", [i[1] for i in rank]) # type: ignore
|
bar.add_yaxis("B话数量", [i[1] for i in rank]) # type: ignore
|
||||||
bar.render(str(get_cache_file("nonebot_plugin_dialectlist","cache.html")))
|
bar.render(str(get_cache_file("nonebot_plugin_dialectlist", "cache.html")))
|
||||||
with open(get_cache_file("nonebot_plugin_dialectlist","cache.html")) as f:
|
with open(get_cache_file("nonebot_plugin_dialectlist", "cache.html")) as f:
|
||||||
a = f.read()
|
a = f.read()
|
||||||
image = await html_to_pic(a,device_scale_factor=3.2)
|
image = await html_to_pic(a, device_scale_factor=3.2)
|
||||||
|
|
||||||
await (saa.Text(string)+saa.Image(image)).finish(reply=True)
|
await (saa.Text(string) + saa.Image(image)).finish(reply=True)
|
||||||
|
@ -1 +1 @@
|
|||||||
# TODO 更好的图片渲染,支持自定义模板渲染。
|
# TODO 更好的图片渲染,支持自定义模板渲染。
|
||||||
|
BIN
nonebot_plugin_dialectlist/source/img/background.jpg
Normal file
BIN
nonebot_plugin_dialectlist/source/img/background.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.3 MiB |
61
nonebot_plugin_dialectlist/source/rank.html
Normal file
61
nonebot_plugin_dialectlist/source/rank.html
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>
|
||||||
|
在 title 里夹一点私货应该不会被发现吧?——ddl 真是太厉害啦!
|
||||||
|
</title>
|
||||||
|
<style>
|
||||||
|
.container {
|
||||||
|
position: relative;
|
||||||
|
width: "auto";
|
||||||
|
height: "auto";
|
||||||
|
}
|
||||||
|
|
||||||
|
.blur-image {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
/*filter: blur(0.6px); /* 模糊程度可以根据需要进行调整 */
|
||||||
|
}
|
||||||
|
.container1 {
|
||||||
|
position: absolute;
|
||||||
|
|
||||||
|
}
|
||||||
|
.card {
|
||||||
|
position: absolute;
|
||||||
|
top: 1%;
|
||||||
|
left: 5%;
|
||||||
|
width: 20%;
|
||||||
|
height: auto;
|
||||||
|
padding: 2rem;
|
||||||
|
border-radius: 2rem;
|
||||||
|
background: rgba(255, 255, 255, .2);
|
||||||
|
-webkit-backdrop-filter: blur(10px);
|
||||||
|
backdrop-filter: blur(10px);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div
|
||||||
|
class="container"
|
||||||
|
backdrop-filter: blur(50px);
|
||||||
|
>
|
||||||
|
<img src="./img/background.jpg" class="blur-image">
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
class="container1"
|
||||||
|
backdrop-filter: blur(50px);
|
||||||
|
>
|
||||||
|
<p>
|
||||||
|
hhhhhhh
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
class="card"
|
||||||
|
top: .5rem;
|
||||||
|
left: .5rem;
|
||||||
|
>
|
||||||
|
<p>nicknames:你好</p>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -1 +1 @@
|
|||||||
# TODO 使用计数缓存进行数据库查询优化,避免一次性查询过多消息导致内存爆炸。
|
# TODO 使用计数缓存进行数据库查询优化,避免一次性查询过多消息导致内存爆炸。
|
||||||
|
@ -1 +1 @@
|
|||||||
# TODO 时间处理模块,用于处理时间相关操作。
|
# TODO 时间处理模块,用于处理时间相关操作。
|
||||||
|
@ -19,9 +19,9 @@ from nonebot_plugin_chatrecorder import MessageRecord
|
|||||||
from nonebot_plugin_alconna import AlconnaMatcher
|
from nonebot_plugin_alconna import AlconnaMatcher
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
from .config import plugin_config
|
from .config import plugin_config
|
||||||
|
|
||||||
|
|
||||||
def parse_datetime(key: str):
|
def parse_datetime(key: str):
|
||||||
"""解析数字,并将结果存入 state 中"""
|
"""解析数字,并将结果存入 state 中"""
|
||||||
|
|
||||||
@ -117,6 +117,18 @@ async def persist_id2user_id(ids: List) -> List[str]:
|
|||||||
return [i.id1 for i in records]
|
return [i.id1 for i in records]
|
||||||
|
|
||||||
|
|
||||||
|
async def user_id2persist_id(id: str) -> int:
|
||||||
|
whereclause: List[ColumnElement[bool]] = []
|
||||||
|
whereclause.append(or_(*[SessionModel.id2 == id]))
|
||||||
|
statement = (
|
||||||
|
select(SessionModel).where(*whereclause)
|
||||||
|
# .join(SessionModel, SessionModel.id == MessageRecord.session_persist_id)
|
||||||
|
)
|
||||||
|
async with get_session() as db_session:
|
||||||
|
records = (await db_session.scalars(statement)).all()
|
||||||
|
return records[0].id
|
||||||
|
|
||||||
|
|
||||||
def msg_counter(msg_list: List[MessageRecord]) -> Dict[str, int]:
|
def msg_counter(msg_list: List[MessageRecord]) -> Dict[str, int]:
|
||||||
"""### 计算每个人的消息量
|
"""### 计算每个人的消息量
|
||||||
|
|
||||||
@ -132,13 +144,12 @@ def msg_counter(msg_list: List[MessageRecord]) -> Dict[str, int]:
|
|||||||
logger.info("wow , there are {} msgs to count !!!".format(msg_len))
|
logger.info("wow , there are {} msgs to count !!!".format(msg_len))
|
||||||
|
|
||||||
for i in msg_list:
|
for i in msg_list:
|
||||||
logger.debug(i.session_persist_id)
|
|
||||||
try:
|
try:
|
||||||
lst[str(i.session_persist_id)] += 1
|
lst[str(i.session_persist_id)] += 1
|
||||||
except KeyError:
|
except KeyError:
|
||||||
lst[str(i.session_persist_id)] = 1
|
lst[str(i.session_persist_id)] = 1
|
||||||
|
|
||||||
logger.debug(lst)
|
logger.debug(f"finish counting, result is {lst}")
|
||||||
|
|
||||||
return lst
|
return lst
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user