mirror of
https://github.com/ChenXu233/nonebot_plugin_dialectlist.git
synced 2024-11-27 09:35:25 +08:00
🎨 格式化代码
This commit is contained in:
parent
d42140cc95
commit
633ffbde9a
31
README.md
31
README.md
@ -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`
|
||||
|
||||
## 💪 目前支持的平台
|
||||
|
||||
@ -158,14 +166,19 @@ __!!注意!!__
|
||||
|
||||
- [x] 私聊的查询(超级用户可以任意查询群聊的信息)一半完成
|
||||
|
||||
- [ ] 特殊的储存方案优化消息统计
|
||||
- [x] 特殊的储存方案优化消息统计
|
||||
|
||||
- [ ] 查询带某关键词的消息量
|
||||
- [x] 查询带某关键词的消息量
|
||||
|
||||
- [ ] 合并转发
|
||||
|
||||
待补充。.....
|
||||
|
||||
## 📖版本
|
||||
|
||||
## 📖版本日志
|
||||
|
||||
<details>
|
||||
<summary>点我展开</summary>
|
||||
|
||||
### V1.0
|
||||
|
||||
- 看看群里群友能有多话痨
|
||||
@ -199,5 +212,11 @@ __!!注意!!__
|
||||
|
||||
- 优化代码,添加一些新的可配置项。
|
||||
|
||||
### V2.4
|
||||
|
||||
- 添加一些新的可配置项。
|
||||
|
||||
</details>
|
||||
|
||||
### 👾题外话
|
||||
~~整个项目快被我写成屎山了~~
|
||||
|
@ -88,10 +88,7 @@ async def _build_cache(bot: Bot, event: Event):
|
||||
rank_cmd = on_alconna(
|
||||
Alconna(
|
||||
"B话榜",
|
||||
Args[
|
||||
"type?",
|
||||
["今日", "昨日", "本周", "上周", "本月", "上月", "年度", "历史"]
|
||||
][
|
||||
Args["type?", ["今日", "昨日", "本周", "上周", "本月", "上月", "年度", "历史"]][
|
||||
"time?",
|
||||
str,
|
||||
],
|
||||
@ -232,7 +229,7 @@ async def handle_rank(
|
||||
|
||||
if not id:
|
||||
await saa.Text("没有指定群哦").finish()
|
||||
|
||||
|
||||
keyword = state["keyword"]
|
||||
|
||||
if plugin_config.counting_cache:
|
||||
@ -253,11 +250,13 @@ async def handle_rank(
|
||||
time_stop=stop,
|
||||
exclude_id1s=plugin_config.excluded_people,
|
||||
)
|
||||
raw_rank = msg_counter(messages,keyword)
|
||||
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])
|
||||
@ -270,12 +269,12 @@ async def handle_rank(
|
||||
logger.debug(f"获取用户信息花费时间:{t.time() - t1}")
|
||||
|
||||
string: str = ""
|
||||
|
||||
|
||||
if keyword:
|
||||
string += f"关于{keyword}的话痨榜结果:\n"
|
||||
else:
|
||||
string += "话痨榜:\n"
|
||||
|
||||
|
||||
for i in rank2:
|
||||
logger.debug(i.user_name)
|
||||
for i in range(len(rank2)):
|
||||
|
@ -2,8 +2,42 @@ from inspect import cleandoc
|
||||
|
||||
__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`
|
||||
|
||||
"""
|
||||
)
|
||||
|
@ -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],keyword:Optional[str]) -> Dict[str, int]:
|
||||
def msg_counter(
|
||||
msg_list: List[MessageRecord], keyword: Optional[str]
|
||||
) -> Dict[str, int]:
|
||||
"""### 计算每个人的消息量
|
||||
|
||||
Args:
|
||||
@ -92,6 +94,7 @@ def msg_counter(msg_list: List[MessageRecord],keyword:Optional[str]) -> Dict[str
|
||||
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
|
||||
|
112
tests/render.py
112
tests/render.py
@ -1,112 +0,0 @@
|
||||
import PIL
|
||||
import abc
|
||||
from typing import List, Tuple, Union, Iterable
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
|
||||
class BaseElement(abc.ABC):
|
||||
def __init__(self, box:Union[Iterable[int],Iterable[float]] = (0, 0, 0, 0)):
|
||||
self.box = [float(i) for i in box]
|
||||
self.ux = None
|
||||
self.ly = None
|
||||
self.dx = None
|
||||
self.ry = None
|
||||
self.hight = None
|
||||
self.width = None
|
||||
self.image = None
|
||||
self.position = (self.ux, self.ly)
|
||||
self.size = (self.width, self.hight)
|
||||
|
||||
@abc.abstractmethod
|
||||
def render(self):
|
||||
raise NotImplementedError
|
||||
|
||||
def get_box(self):
|
||||
return self.box
|
||||
|
||||
def set_box(self, box:Tuple[float, float, float, float]):
|
||||
self.box = box
|
||||
|
||||
def get_size(self):
|
||||
self.size = (self.width, self.hight)
|
||||
return self.size
|
||||
|
||||
def get_position(self):
|
||||
self.position = (self.ux, self.ly)
|
||||
return self.position
|
||||
|
||||
class Board(BaseElement):
|
||||
def __init__(self, width, hight):
|
||||
self.width = width
|
||||
self.hight = hight
|
||||
self.image = Image.new('RGBA', (self.width, self.hight), (255, 255, 255, 0))
|
||||
self.elements = []
|
||||
|
||||
def render(self):
|
||||
for i in self.elements:
|
||||
i.ux = self.width * i.box[0]
|
||||
i.ly = self.hight * i.box[1]
|
||||
i.dx = self.width * i.box[2]
|
||||
i.ry = self.hight * i.box[3]
|
||||
i.hight = i.dx - i.ux
|
||||
i.width = i.ry - i.ly
|
||||
i.position = (i.ux, i.ly)
|
||||
image = i.render()
|
||||
self.image.paste(image, i.get_position())
|
||||
|
||||
def add_element(self, element:BaseElement):
|
||||
self.elements.append(element)
|
||||
|
||||
|
||||
class Container(BaseElement):
|
||||
def __init__(self, box:Union[Iterable[int],Iterable[float]] = (0, 0, 0, 0)):
|
||||
super().__init__(box)
|
||||
self.elements:List[BaseElement] = []
|
||||
|
||||
def render(self,size:Tuple[int, int] = (100, 100)):
|
||||
if not self.width and self.hight:
|
||||
self.width = size[0]
|
||||
self.hight = size[1]
|
||||
if not self.image:
|
||||
self.image = Image.new('RGBA', (self.width, self.hight), (255, 255, 255, 0))
|
||||
for i in self.elements:
|
||||
image = i.render()
|
||||
self.image.paste(image, i.get_position())
|
||||
|
||||
class Element(BaseElement):
|
||||
|
||||
|
||||
|
||||
|
||||
# class BaseContainer(abc.ABC):
|
||||
# def __init__(self, width:int, height:int):
|
||||
# self.width = width
|
||||
# self.height = height
|
||||
# self.image = Image.new('RGBA', (self.width, self.height), (255, 255, 255, 0))
|
||||
|
||||
# @abc.abstractmethod
|
||||
# def render(self):
|
||||
# raise NotImplementedError
|
||||
|
||||
# def set_image(self,image):
|
||||
# self.image = image
|
||||
|
||||
# class Elements():
|
||||
# def __init__(self, width:int, height:int):
|
||||
# self.width = width
|
||||
# self.height = height
|
||||
# self.image = Image.new('RGBA', (self.width, self.height), (255, 255, 255, 0))
|
||||
|
||||
# def render(self):
|
||||
# return self.image
|
||||
|
||||
# class Container(BaseContainer):
|
||||
# def __init__(self, width:int, height:int,elements:List[Union['Container',Elements]] = []):
|
||||
# super().__init__(width, height)
|
||||
# self.elements = elements
|
||||
|
||||
# def render(self):
|
||||
# for i in self.elements:
|
||||
# image = i.render()
|
||||
# self.image.paste(image, i.position)
|
||||
# return self.image
|
||||
|
Loading…
Reference in New Issue
Block a user