feat✨: 添加hook,更新其他

This commit is contained in:
HibiKier
2024-02-26 03:04:32 +08:00
parent eb0572ea77
commit 7b3793728a
22 changed files with 1064 additions and 117 deletions
+12 -2
View File
@@ -453,14 +453,24 @@ class BuildImage:
return self
def pic2bs4(self) -> str:
"""
BuildImage 转 base64
"""BuildImage 转 base64
返回:
str: base64
"""
buf = BytesIO()
self.markImg.save(buf, format="PNG")
base64_str = base64.b64encode(buf.getvalue()).decode()
return "base64://" + base64_str
def pic2io(self) -> BytesIO:
"""图片转 BytesIO
返回:
BytesIO: BytesIO
"""
return BytesIO(self.tobytes())
def convert(self, type_: ModeType) -> Self:
"""
修改图片类型
+4 -1
View File
@@ -10,6 +10,8 @@ class GoldHandle(StrEnum):
"""购买"""
GET = "GET"
"""获取"""
PLUGIN = "PLUGIN"
"""插件花费"""
class PropHandle(StrEnum):
@@ -40,7 +42,7 @@ class BlockType(StrEnum):
禁用状态
"""
FRIEND = "PRIVATE"
PRIVATE = "PRIVATE"
GROUP = "GROUP"
ALL = "ALL"
@@ -72,6 +74,7 @@ class LimitWatchType(StrEnum):
USER = "USER"
GROUP = "GROUP"
ALL = "ALL"
class RequestType(StrEnum):
+24
View File
@@ -1,14 +1,38 @@
class NotFoundError(Exception):
"""
未发现
"""
pass
class GroupInfoNotFound(Exception):
"""
群组未找到
"""
pass
class EmptyError(Exception):
"""
空错误
"""
pass
class UserAndGroupIsNone(Exception):
"""
用户和群组为空
"""
pass
class InsufficientGold(Exception):
"""
金币不足
"""
pass
+3 -1
View File
@@ -27,7 +27,9 @@ def admin_check(a: int | str, key: str | None = None) -> Rule:
if type(a) == str and key:
level = Config.get_config(a, key)
if level is not None:
return bool(LevelUser.check_level(session.id1, session.id2, int(level)))
return bool(
await LevelUser.check_level(session.id1, session.id2, int(level))
)
return False
return Rule(_rule)
+22 -10
View File
@@ -1,10 +1,12 @@
import os
import time
from collections import defaultdict
from datetime import datetime
from pathlib import Path
from typing import Any
import httpx
import pytz
from zhenxun.services.log import logger
@@ -78,21 +80,31 @@ class ResourceDirManager:
class CountLimiter:
"""
次数检测工具,检测调用次数是否超过设定值
每日调用命令次数限制
"""
def __init__(self, max_count: int):
tz = pytz.timezone("Asia/Shanghai")
def __init__(self, max_num):
self.today = -1
self.count = defaultdict(int)
self.max_count = max_count
self.max = max_num
def add(self, key: Any):
self.count[key] += 1
def check(self, key) -> bool:
day = datetime.now(self.tz).day
if day != self.today:
self.today = day
self.count.clear()
return bool(self.count[key] < self.max)
def check(self, key: Any) -> bool:
if self.count[key] >= self.max_count:
self.count[key] = 0
return True
return False
def get_num(self, key):
return self.count[key]
def increase(self, key, num=1):
self.count[key] += num
def reset(self, key):
self.count[key] = 0
class UserBlockLimiter: