This commit is contained in:
HibiKier
2022-05-21 13:15:53 +08:00
parent 86a8fe7096
commit 188ae38525
25 changed files with 153 additions and 124 deletions
-2
View File
@@ -15,8 +15,6 @@ _browser: Optional[Browser] = None
async def init(**kwargs) -> Optional[Browser]:
global _browser
if platform.system() == "Windows":
return None
try:
browser = await async_playwright().start()
_browser = await browser.chromium.launch(**kwargs)
+6
View File
@@ -0,0 +1,6 @@
+22 -6
View File
@@ -17,13 +17,15 @@ class ShopRegister(dict):
name: Tuple[str, ...],
price: Tuple[float, ...],
des: Tuple[str, ...],
discount: Tuple[float, ...],
limit_time: Tuple[int, ...],
load_status: Tuple[bool, ...],
**kwargs,
):
def add_register_item(func: Callable):
if name in self._data.keys():
raise ValueError("该商品已注册,请替换其他名称!")
for n, p, d, s in zip(name, price, des, load_status):
for n, p, d, dd, l, s in zip(name, price, des, discount, limit_time, load_status):
if s:
_temp_kwargs = {}
for key, value in kwargs.items():
@@ -32,6 +34,8 @@ class ShopRegister(dict):
self._data[n] = {
"price": p,
"des": d,
"discount": dd,
"limit_time": l,
"func": func,
"kwargs": _temp_kwargs,
}
@@ -46,7 +50,7 @@ class ShopRegister(dict):
self._flag = False
for name in self._data.keys():
await shop.register_goods(
name, self._data[name]["price"], self._data[name]["des"]
name, self._data[name]["price"], self._data[name]["des"], self._data[name]["discount"], self._data[name]["limit_time"]
)
use.register_use(
name, self._data[name]["func"], **self._data[name]["kwargs"]
@@ -57,24 +61,36 @@ class ShopRegister(dict):
name: Union[str, Tuple[str, ...]],
price: Union[float, Tuple[float, ...]],
des: Union[str, Tuple[str, ...]],
discount: Union[float, Tuple[float, ...]] = 1,
limit_time: Union[int, Tuple[int, ...]] = 0,
load_status: Union[bool, Tuple[bool, ...]] = True,
**kwargs,
):
_tuple_list = []
_current_len = -1
for x in [name, price, des, load_status]:
for x in [name, price, des, discount, limit_time, load_status]:
if isinstance(x, tuple):
if _current_len == -1:
_current_len = len(x)
if _current_len != len(x):
raise ValueError(f"注册商品 {name} 中 name,price,des,load_status 数量不符!")
raise ValueError(f"注册商品 {name} 中 name,price,des,discount,limit_time,load_status 数量不符!")
_current_len = _current_len if _current_len > -1 else 1
_name = name if isinstance(name, tuple) else tuple(name)
_name = name if isinstance(name, tuple) else (name,)
_price = (
price
if isinstance(price, tuple)
else tuple([price for _ in range(_current_len)])
)
_discount = (
discount
if isinstance(discount, tuple)
else tuple([discount for _ in range(_current_len)])
)
_limit_time = (
limit_time
if isinstance(limit_time, tuple)
else tuple([limit_time for _ in range(_current_len)])
)
_des = (
des if isinstance(des, tuple) else tuple([des for _ in range(_current_len)])
)
@@ -83,7 +99,7 @@ class ShopRegister(dict):
if isinstance(load_status, tuple)
else tuple([load_status for _ in range(_current_len)])
)
return self.register(_name, _price, _des, _load_status, **kwargs)
return self.register(_name, _price, _des, _discount, _limit_time, _load_status, **kwargs)
def __setitem__(self, key, value):
self._data[key] = value
+5 -4
View File
@@ -1493,10 +1493,11 @@ async def text2image(
height = 0
_tmp = BuildImage(0, 0, font=font, font_size=font_size)
for x in text.split("\n"):
x = x if x.strip() else "正"
w, h = _tmp.getsize(x)
height += h + _add_height
width = width if width > w else w
if x:
w, _ = _tmp.getsize(x)
_, h = _tmp.getsize("正")
height += h + _add_height
width = width if width > w else w
width += pw
height += ph
A = BuildImage(
+10 -25
View File
@@ -16,6 +16,7 @@ try:
except ModuleNotFoundError:
import json
scheduler = require("nonebot_plugin_apscheduler").scheduler
@@ -107,8 +108,8 @@ class BanCheckLimiter:
self.mint[key] = 0
return False
if (
self.mint[key] >= self.default_count
and time.time() - self.mtime[key] < self.default_check_time
self.mint[key] >= self.default_count
and time.time() - self.mtime[key] < self.default_check_time
):
self.mtime[key] = time.time()
self.mint[key] = 0
@@ -202,7 +203,10 @@ def get_message_at(data: Union[str, Message]) -> List[int]:
for msg in data["message"]:
if msg["type"] == "at":
qq_list.append(int(msg["data"]["qq"]))
else:
for seg in data:
if seg.type == "at":
qq_list.append(seg.data["qq"])
return qq_list
@@ -225,25 +229,6 @@ def get_message_img(data: Union[str, Message]) -> List[str]:
return img_list
def get_message_img_file(data: Union[str, Message]) -> List[str]:
"""
说明:
获取消息中所有的 图片file
参数:
:param data: event.json()
"""
file_list = []
if isinstance(data, str):
data = json.loads(data)
for msg in data["message"]:
if msg["type"] == "image":
file_list.append(msg["data"]["file"])
else:
for seg in data["image"]:
file_list.append(seg.data["file"])
return file_list
def get_message_text(data: Union[str, Message]) -> str:
"""
说明:
@@ -370,7 +355,7 @@ def cn2py(word: str) -> str:
def change_pixiv_image_links(
url: str, size: Optional[str] = None, nginx_url: Optional[str] = None
url: str, size: Optional[str] = None, nginx_url: Optional[str] = None
):
"""
说明:
@@ -388,7 +373,7 @@ def change_pixiv_image_links(
if nginx_url:
url = (
url.replace("i.pximg.net", nginx_url)
.replace("i.pixiv.cat", nginx_url)
.replace("_webp", "")
.replace("i.pixiv.cat", nginx_url)
.replace("_webp", "")
)
return url