summaryrefslogtreecommitdiff
path: root/ATRI/utils
diff options
context:
space:
mode:
authorKyomotoi <[email protected]>2021-08-26 01:22:34 +0800
committerKyomotoi <[email protected]>2021-08-26 01:22:34 +0800
commitc177a4d279b159a76d737e6b4ae547ccdd979a4e (patch)
treebd5001f02e92a5bff38286a4251aa2781cae4683 /ATRI/utils
parentf17b264ad6470ba1308deacb25b9ead59461c895 (diff)
downloadATRI-c177a4d279b159a76d737e6b4ae547ccdd979a4e.tar.gz
ATRI-c177a4d279b159a76d737e6b4ae547ccdd979a4e.tar.bz2
ATRI-c177a4d279b159a76d737e6b4ae547ccdd979a4e.zip
🐛🔥 更改一些内容
修复: - 好友/群邀请 写入文件失败 - 同意 好友/群邀请、查看申请列表 获取arg失败 删除: - 移除 Ubuntu paste 更改: - saucenao 最大显示数量为3 - anime search 最大显示数量为3
Diffstat (limited to 'ATRI/utils')
-rw-r--r--ATRI/utils/__init__.py55
1 files changed, 9 insertions, 46 deletions
diff --git a/ATRI/utils/__init__.py b/ATRI/utils/__init__.py
index 6cccc7f..d4298f5 100644
--- a/ATRI/utils/__init__.py
+++ b/ATRI/utils/__init__.py
@@ -37,7 +37,6 @@ class ListDealer:
"""
对列表进行处理
"""
-
def __init__(self, lst: list, aim):
self.lst = lst
self.aim = aim
@@ -59,7 +58,6 @@ class CoolqCodeChecker:
"""
检查所传回的cq码是否存在被注入可能
"""
-
tenc_gchat_url: str = "gchat.qpic.cn"
may_inject_keys: list = ["record", "video", "music", "xml", "json"]
@@ -89,14 +87,14 @@ class FileDealer:
"""
打开文件
"""
-
def __init__(self, path: Path, encoding: str = "utf-8"):
self.path = path
self.encoding = encoding
async def write(self, path: Path, content):
try:
- async with aiofiles.open(path, "w", encoding=self.encoding) as target:
+ async with aiofiles.open(path, "w",
+ encoding=self.encoding) as target:
await target.write(content)
except Exception:
raise Exception(f"Writing file({path}) failed!")
@@ -129,8 +127,11 @@ class ImageDealer:
"""
对图片进行压缩处理
"""
-
- def __init__(self, out_path, kb: int = 300, quality: int = 85, k: float = 0.9):
+ def __init__(self,
+ out_path,
+ kb: int = 300,
+ quality: int = 85,
+ k: float = 0.9):
self.out_path = out_path
self.kb = kb
self.quality = quality
@@ -145,7 +146,8 @@ class ImageDealer:
while o_size > self.kb:
img = Image.open(self.out_path)
x, y = img.size
- out = img.resize((int(x * self.k), int(y * self.k)), Image.ANTIALIAS)
+ out = img.resize((int(x * self.k), int(y * self.k)),
+ Image.ANTIALIAS)
try:
out.save(self.out_path, quality=self.quality)
except Exception:
@@ -192,42 +194,3 @@ class Translate:
output_str_list.append(self.text[i])
return "".join(output_str_list)
-
-
-class UbuntuPaste:
- """
- 将信息粘贴至 ubuntu pastebin
- """
-
- URL = "https://paste.ubuntu.com/"
-
- def __init__(
- self,
- poster: str = "ATRI running log",
- syntax: str = "text",
- expiration: str = "day",
- content: str = "0w0",
- ):
- self.poster = poster
- self.syntax = syntax
- self.expiration = expiration
- self.content = content
-
- def _gen_form_data(self) -> FormData:
- data = FormData()
- data.add_field("poster", self.poster)
- data.add_field("syntax", self.syntax)
- data.add_field("expiration", self.expiration)
- data.add_field("content", self.content)
- return data
-
- async def paste(self) -> str:
- try:
- res = await request.post(self.URL, self._gen_form_data())
- except BaseException:
- raise BaseException("Request failed!")
- result = str(res.url)
- if result == self.URL:
- result = self.content
-
- return result