summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
Diffstat (limited to 'utils')
-rw-r--r--utils/utils_banList/__init__.py45
-rw-r--r--utils/utils_error/__init__.py15
-rw-r--r--utils/utils_history/__init__.py11
-rw-r--r--utils/utils_img/__init__.py93
-rw-r--r--utils/utils_request/__init__.py11
-rw-r--r--utils/utils_switch/__init__.py17
-rw-r--r--utils/utils_switch/switch.json2
7 files changed, 176 insertions, 18 deletions
diff --git a/utils/utils_banList/__init__.py b/utils/utils_banList/__init__.py
index 66142cc..e7ccbec 100644
--- a/utils/utils_banList/__init__.py
+++ b/utils/utils_banList/__init__.py
@@ -1,11 +1,20 @@
#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
+# -*- encoding: utf-8 -*-
+'''
+@File : __init__.py
+@Time : 2020/10/11 14:42:59
+@Author : Kyomotoi
+@Contact : [email protected]
+@Github : https://github.com/Kyomotoi
+@License : Copyright © 2018-2020 Kyomotoi, All Rights Reserved.
+'''
+__author__ = 'kyomotoi'
import json
from pathlib import Path
from typing import Optional
-def banList(user: str, group: Optional[str] = None) -> bool:
+def banList(user: Optional[str] = None, group: Optional[str] = None) -> bool:
"""
:说明:
@@ -13,8 +22,9 @@ def banList(user: str, group: Optional[str] = None) -> bool:
:参数:
- * ``user: str``: 用户QQ号
- * ``group: Optional[str] = None``: 用户所在群号,若不传入则只检测用户
+ * ``user: Optional[str] = None``: 用户QQ号
+ * ``group: Optional[str] = None``: 用户所在群号
+ * !!!二者必须传入一个,否则一律返回 False !!!
:返回:
@@ -42,14 +52,29 @@ def banList(user: str, group: Optional[str] = None) -> bool:
except:
data_group = {}
- if user not in data_user:
- if group:
- if group not in data_group:
+ if user:
+ if user not in data_user:
+ if group:
+ if group not in data_group:
+ return True
+ else:
+ return False
+ else:
return True
+ else:
+ return False
+
+ elif group:
+ if group not in data_group:
+ if user:
+ if user not in data_user:
+ return True
+ else:
+ return False
else:
- return False
+ return True
else:
- return True
+ return False
+
else:
- print(3)
return False \ No newline at end of file
diff --git a/utils/utils_error/__init__.py b/utils/utils_error/__init__.py
index e037b30..2674018 100644
--- a/utils/utils_error/__init__.py
+++ b/utils/utils_error/__init__.py
@@ -1,5 +1,14 @@
#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
+# -*- encoding: utf-8 -*-
+'''
+@File : __init__.py
+@Time : 2020/10/11 14:43:10
+@Author : Kyomotoi
+@Contact : [email protected]
+@Github : https://github.com/Kyomotoi
+@License : Copyright © 2018-2020 Kyomotoi, All Rights Reserved.
+'''
+__author__ = 'kyomotoi'
import json
import string
@@ -9,8 +18,6 @@ from typing import Optional
from datetime import datetime
from traceback import format_exc
-from nonebot.rule import keyword
-
def errorRepo(repo_msg: Optional[str] = None) -> str:
"""
:说明:
@@ -23,7 +30,7 @@ def errorRepo(repo_msg: Optional[str] = None) -> str:
:返回:
- 错误信息
+ 错误堆栈
:用法:
diff --git a/utils/utils_history/__init__.py b/utils/utils_history/__init__.py
index d6a6d33..74834d8 100644
--- a/utils/utils_history/__init__.py
+++ b/utils/utils_history/__init__.py
@@ -1,5 +1,14 @@
#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
+# -*- encoding: utf-8 -*-
+'''
+@File : __init__.py
+@Time : 2020/10/11 14:43:20
+@Author : Kyomotoi
+@Contact : [email protected]
+@Github : https://github.com/Kyomotoi
+@License : Copyright © 2018-2020 Kyomotoi, All Rights Reserved.
+'''
+__author__ = 'kyomotoi'
import os
import json
diff --git a/utils/utils_img/__init__.py b/utils/utils_img/__init__.py
new file mode 100644
index 0000000..1b8c767
--- /dev/null
+++ b/utils/utils_img/__init__.py
@@ -0,0 +1,93 @@
+#!/usr/bin/env python3
+# -*- encoding: utf-8 -*-
+'''
+@File : __init__.py
+@Time : 2020/10/11 14:40:17
+@Author : Kyomotoi
+@Contact : [email protected]
+@Github : https://github.com/Kyomotoi
+@License : Copyright © 2018-2020 Kyomotoi, All Rights Reserved.
+'''
+__author__ = 'kyomotoi'
+
+import os
+import string
+import aiohttp
+import PIL.Image as Image
+from pathlib import Path
+from random import sample
+
+from PIL import Image
+from PIL import ImageFile
+
+async def aio_download_pics(url):
+ """
+ :说明:
+
+ 下载图片并重名文件
+
+ :参数:
+
+ * ``URL: str``: 目标网址
+
+ :返回:
+
+ 文件根目录
+
+ :用法:
+
+ .. code-block:: python
+
+ aio_download_pics(URL="https://www.demo.com/demo.jpg")
+
+ """
+ path = Path('.') / 'ATRI' / 'data' / 'data_Temp' / 'img'
+ path = os.path.abspath(path)
+ img_key = ''.join(sample(string.ascii_letters + string.digits, 16))
+ img = path + f'\\{img_key}.png'
+ async with aiohttp.ClientSession() as session:
+ async with session.get(url) as response:
+ pic = await response.read() #以Bytes方式读入非文字
+ with open(img, mode='wb') as f:# 写入文件
+ f.write(pic)
+ f.close()
+ return img
+
+def compress_image(outfile: str, kb=400, quality=85, k=0.9) -> str:
+ """
+ :说明:
+
+ 不改变图片尺寸压缩到指定大小,输出 base64 ,完成后自动删除文件
+
+ :参数:
+
+ * ``outfile: str``: 文件目录
+ * ``kb=150``: 目标文件大小,单位:KB
+
+ :返回:
+
+ base64
+
+ :用法:
+
+ .. code-block:: python
+
+ compress_image(outfile=C:/xxx)
+
+ """
+ o_size = os.path.getsize(outfile) // 1024
+ if o_size <= kb:
+ return outfile
+
+ ImageFile.LOAD_TRUNCATED_IMAGES = True # type: ignore
+ while o_size > kb:
+ im = Image.open(outfile)
+ x, y = im.size
+ out = im.resize((int(x*k), int(y*k)), Image.ANTIALIAS)
+ try:
+ out.save(outfile, quality=quality)
+ except Exception as e:
+ print(e)
+ break
+ o_size = os.path.getsize(outfile) // 1024
+ return outfile
diff --git a/utils/utils_request/__init__.py b/utils/utils_request/__init__.py
index cc0992a..b32f372 100644
--- a/utils/utils_request/__init__.py
+++ b/utils/utils_request/__init__.py
@@ -1,5 +1,14 @@
#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
+# -*- encoding: utf-8 -*-
+'''
+@File : __init__.py
+@Time : 2020/10/11 14:43:55
+@Author : Kyomotoi
+@Contact : [email protected]
+@Github : https://github.com/Kyomotoi
+@License : Copyright © 2018-2020 Kyomotoi, All Rights Reserved.
+'''
+__author__ = 'kyomotoi'
import requests
from typing import Optional
diff --git a/utils/utils_switch/__init__.py b/utils/utils_switch/__init__.py
index 5c10a85..df7b877 100644
--- a/utils/utils_switch/__init__.py
+++ b/utils/utils_switch/__init__.py
@@ -1,5 +1,14 @@
#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
+# -*- encoding: utf-8 -*-
+'''
+@File : __init__.py
+@Time : 2020/10/11 14:44:06
+@Author : Kyomotoi
+@Contact : [email protected]
+@Github : https://github.com/Kyomotoi
+@License : Copyright © 2018-2020 Kyomotoi, All Rights Reserved.
+'''
+__author__ = 'kyomotoi'
import os
import json
@@ -40,6 +49,9 @@ def checkSwitch(func_name: str, group: str) -> bool:
data_switch_all["anime-pic-search"] = "True"
data_switch_all["anime-vid-search"] = "True"
data_switch_all["ai-face"] = "True"
+ data_switch_all["pixiv-pic-search"] = "True"
+ data_switch_all["pixiv-author-search"] = "True"
+ data_switch_all["pixiv-rank"] = "True"
with open(file_switch_all, 'w') as f:
f.write(json.dumps(data_switch_all))
@@ -59,6 +71,9 @@ def checkSwitch(func_name: str, group: str) -> bool:
data_switch_alone["anime-pic-search"] = "True"
data_switch_alone["anime-vid-search"] = "True"
data_switch_alone["ai-face"] = "True"
+ data_switch_alone["pixiv-pic-search"] = "True"
+ data_switch_alone["pixiv-author-search"] = "True"
+ data_switch_alone["pixiv-rank"] = "True"
with open(file_switch_alone, 'w') as f:
f.write(json.dumps(data_switch_alone))
diff --git a/utils/utils_switch/switch.json b/utils/utils_switch/switch.json
index 9b6bb22..9fb8cfa 100644
--- a/utils/utils_switch/switch.json
+++ b/utils/utils_switch/switch.json
@@ -1 +1 @@
-{"anime-setu": "True", "anime-pic-search": "True", "anime-vid-search": "True", "all-off-anime-setu": "True"} \ No newline at end of file
+{"anime-setu": "True", "anime-pic-search": "True", "anime-vid-search": "True", "all-off-anime-setu": "True", "ai-face": "True", "pixiv-pic-search": "True", "pixiv-author-search": "True", "pixiv-rank": "True"} \ No newline at end of file