Skip to content

Commit

Permalink
🔀 Merge pull request #43 from ChenXu233/feat#20#39
Browse files Browse the repository at this point in the history
Feat#20#39
  • Loading branch information
ChenXu233 authored Nov 9, 2024
2 parents d7baa9b + 53e52ea commit fcce942
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 126 deletions.
31 changes: 25 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,17 @@ __!!注意!!__

### 🚀进阶用法

`/{时间类型(今日|年度)?}{B话榜|废话榜} {时间类型?} {ISO8601 格式时间} {群号}`
`/{时间类型(今日|年度)?}{B话榜|废话榜} {时间类型?} {ISO8601 格式时间 ?} {群号} {关键词}`

如:`/B话榜 历史 2024-01-01~2024-01-02 12345678`
如:`/B话榜 历史 2024-01-01~2024-01-02 12345678 女装`

也可以 `/{时间类型(今日|年度)?}{B话榜|废话榜} {时间类型?} {ISO8601 格式时间 ?} -g {群号} -k {关键词}`

以下调用方法均合法:

`/今日B话榜 -g 12345678 -k 女装`
`/昨日B话榜 -k 女装`
`/本周B话榜 -g 12345678`

## 💪 目前支持的平台

Expand Down Expand Up @@ -158,14 +166,19 @@ __!!注意!!__

- [x] 私聊的查询(超级用户可以任意查询群聊的信息)一半完成

- [ ] 特殊的储存方案优化消息统计
- [x] 特殊的储存方案优化消息统计

- [ ] 查询带某关键词的消息量
- [x] 查询带某关键词的消息量

- [ ] 合并转发

待补充。.....

## 📖版本

## 📖版本日志

<details>
<summary>点我展开</summary>

### V1.0

- 看看群里群友能有多话痨
Expand Down Expand Up @@ -199,5 +212,11 @@ __!!注意!!__

- 优化代码,添加一些新的可配置项。

### V2.4

- 添加一些新的可配置项。

</details>

### 👾题外话
~~整个项目快被我写成屎山了~~
21 changes: 18 additions & 3 deletions nonebot_plugin_dialectlist/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ async def _build_cache(bot: Bot, event: Event):
str,
],
Option("-g|--group_id", Args["group_id?", str]),
Option("-k|--keyword", Args["keyword?", str]),
behaviors=[SameTime()],
),
aliases={"废话榜"},
Expand Down Expand Up @@ -129,6 +130,7 @@ async def _group_message(
type: Optional[str] = None,
time: Optional[str] = None,
group_id: Optional[str] = None,
keyword: Optional[str] = None,
):
t1 = t.time()
state["t1"] = t1
Expand All @@ -140,6 +142,8 @@ async def _group_message(
if group_id:
state["group_id"] = group_id

state["keyword"] = keyword

if not type:
await rank_cmd.finish(__plugin_meta__.usage)

Expand Down Expand Up @@ -226,7 +230,11 @@ async def handle_rank(
if not id:
await saa.Text("没有指定群哦").finish()

keyword = state["keyword"]

if plugin_config.counting_cache:
if keyword:
await saa.Text("已开启缓存~缓存不支持关键词查询哦").finish()
t1 = t.time()
raw_rank = await get_cache(start, stop, id)
logger.debug(f"获取计数消息花费时间:{t.time() - t1}")
Expand All @@ -242,11 +250,13 @@ async def handle_rank(
time_stop=stop,
exclude_id1s=plugin_config.excluded_people,
)
raw_rank = msg_counter(messages)
raw_rank = msg_counter(messages, keyword)
logger.debug(f"获取计数消息花费时间:{t.time() - t1}")

if not raw_rank:
await saa.Text("明明这个时间段都没有人说话怎么会有话痨榜呢?").finish()
await saa.Text(
"没有获取到排行榜数据哦,请确认时间范围和群号是否正确或者关键词是否存在~"
).finish()

rank = got_rank(raw_rank)
ids = await persist_id2user_id([int(i[0]) for i in rank])
Expand All @@ -259,8 +269,13 @@ async def handle_rank(
logger.debug(f"获取用户信息花费时间:{t.time() - t1}")

string: str = ""

if plugin_config.show_text_rank:

if keyword:
string += f"关于{keyword}的话痨榜结果:\n"
else:
string += "话痨榜:\n"

for i in rank2:
logger.debug(i.user_name)
for i in range(len(rank2)):
Expand Down
40 changes: 37 additions & 3 deletions nonebot_plugin_dialectlist/usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,42 @@

__usage__ = cleandoc(
"""
/今日B话榜 查看今天群里谁B话最多。
/昨日B话榜 顾名思义。
以此类推,有本周,本月,上周,上月,年度排行榜。
快速调用:
/今日B话榜 ————看看今天群友发了多少消息。
### 🎨一般用法
-`/B话榜` ————看看有史以来(机器人存在以来)群友们发了多少消息! (好像没写)
-`/今日B话榜` ————看看今天的群友发了多少消息!
-`/昨日B话榜` ————看看昨天的群友发了多少消息!
-`/前日B话榜` ————看看前天的群友发了多少消息!
-`/本周B话榜` ————看看本周的群友发了多少消息!
-`/上周B话榜` ————看看上周的群友发了多少消息!
-`/本月B话榜` ————看看这个月的群友发了多少消息!
-`/年度B话榜` ————看看今年的群友发了多少消息!
-`/历史B话榜` ————看看历史上(机器人存在以来)的群友发了多少消息!
### 🚀进阶用法
`/{时间类型(今日|年度)?}{B话榜|废话榜} {时间类型?} {ISO8601 格式时间 ?} {群号} {关键词}`
如:`/B话榜 历史 2024-01-01~2024-01-02 12345678 女装`
也可以 `/{时间类型(今日|年度)?}{B话榜|废话榜} {时间类型?} {ISO8601 格式时间 ?} -g {群号} -k {关键词}`
以下调用方法均合法:
`/今日B话榜 -g 12345678 -k 女装`
`/昨日B话榜 -k 女装`
`/本周B话榜 -g 12345678`
"""
)
10 changes: 8 additions & 2 deletions nonebot_plugin_dialectlist/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import asyncio
import unicodedata

from typing import Dict, List
from typing import Dict, List, Optional
from sqlalchemy import or_, select
from sqlalchemy.sql import ColumnElement

Expand Down Expand Up @@ -77,7 +77,9 @@ async def persist_id2group_id(ids: List[str]) -> List[str]:
return [i.id2 for i in records]


def msg_counter(msg_list: List[MessageRecord]) -> Dict[str, int]:
def msg_counter(
msg_list: List[MessageRecord], keyword: Optional[str]
) -> Dict[str, int]:
"""### 计算每个人的消息量
Args:
Expand All @@ -92,6 +94,10 @@ def msg_counter(msg_list: List[MessageRecord]) -> Dict[str, int]:
logger.info("wow , there are {} msgs to count !!!".format(msg_len))

for i in msg_list:
logger.debug(f"processing msg {i.plain_text}")
if keyword:
if keyword not in i.plain_text:
continue
try:
lst[str(i.session_persist_id)] += 1
except KeyError:
Expand Down
112 changes: 0 additions & 112 deletions tests/render.py

This file was deleted.

0 comments on commit fcce942

Please sign in to comment.