diff options
Diffstat (limited to 'ATRI/modules')
-rw-r--r-- | ATRI/modules/b64/__init__.py | 26 | ||||
-rw-r--r-- | ATRI/modules/error/__init__.py | 36 | ||||
-rw-r--r-- | ATRI/modules/favoIMP/__init__.py | 58 | ||||
-rw-r--r-- | ATRI/modules/favoIMP/user.json | 1 | ||||
-rw-r--r-- | ATRI/modules/funcControl/ALLswitch.json | 1 | ||||
-rw-r--r-- | ATRI/modules/funcControl/__init__.py | 62 | ||||
-rw-r--r-- | ATRI/modules/google_translate/__init__.py | 142 | ||||
-rw-r--r-- | ATRI/modules/response/__init__.py | 19 | ||||
-rw-r--r-- | ATRI/modules/time/__init__.py | 24 |
9 files changed, 0 insertions, 369 deletions
diff --git a/ATRI/modules/b64/__init__.py b/ATRI/modules/b64/__init__.py deleted file mode 100644 index 8cce6e0..0000000 --- a/ATRI/modules/b64/__init__.py +++ /dev/null @@ -1,26 +0,0 @@ -import os -import time -import base64 -import requests -from pathlib import Path - - -path_temp_img = Path('.') / 'ATRI' / 'data' / 'temp' / 'img' - - -def b64_str_img_url(url: str): - img_d = requests.get(url) - name = 'temp.jpg' - find_img = Path('.') / 'ATRI' / 'data' / 'temp' / 'img' / f'{name}' - with open(find_img, 'wb') as f: - f.write(img_d.content) - if find_img.stat().st_size >= 1000000: - print('超过1MB,跳过!') - return - else: - with open(find_img, 'rb') as f: - content = f.read() - b64_str = base64.b64encode(content).decode() - time.sleep(1) - os.remove(str(path_temp_img) + '/' + name) - return b64_str
\ No newline at end of file diff --git a/ATRI/modules/error/__init__.py b/ATRI/modules/error/__init__.py deleted file mode 100644 index 0f69608..0000000 --- a/ATRI/modules/error/__init__.py +++ /dev/null @@ -1,36 +0,0 @@ -import json -import string -from pathlib import Path -from random import sample -from traceback import format_exc -from datetime import datetime -from typing import Optional - - -def errorBack(Lmsg: Optional[str] = None): - try: - with open(Path('.') / 'ATRI' / 'data' / 'errorData' / 'errorData.json', 'r') as f: - data = json.load(f) - except: - data = {} - - ran_str = ''.join(sample(string.ascii_letters + string.digits, 8)) - msg0 = f"{datetime.now()}\n" - msg0 += f"{format_exc()}" - data[f"{ran_str}"] = f"{msg0}" - - with open(Path('.') / 'ATRI' / 'data' / 'errorData' / 'errorData.json', 'w') as f: - f.write(json.dumps(data)) - f.close() - - if Lmsg: - pass - else: - Lmsg = 'unknown' - - msg0 = f'ERROR! Reason: [{Lmsg}]\n' - msg0 += f'trackID: {ran_str}\n' - msg0 += "请使用[来杯红茶]功能以联系维护者\n" - msg0 += "并附上 trackID" - - return msg0
\ No newline at end of file diff --git a/ATRI/modules/favoIMP/__init__.py b/ATRI/modules/favoIMP/__init__.py deleted file mode 100644 index 3dabdae..0000000 --- a/ATRI/modules/favoIMP/__init__.py +++ /dev/null @@ -1,58 +0,0 @@ -import json -from random import randint -from pathlib import Path - -def GetFavoIMP(u): - try: - with open(Path('.') / 'ATRI' / 'modules' / 'favoIMP' / 'user.json', 'r') as f: - data = json.load(f) - except: - return 0 - - try: - if data[f"{u}"][0]: - pass - else: - return 0 - except: - return 0 - - return [data[f"{u}"][0], data[f"{u}"][1]] - -def AddFavoIMP(u, f:int, s:bool): - if s: - favoIMP = randint(1,f) - else: - favoIMP = f - try: - with open(Path('.') / 'ATRI' / 'modules' / 'favoIMP' / 'user.json', 'r') as a: - data = json.load(a) - data[f"{u}"][0] = int(data[f"{u}"][0]) + favoIMP - with open(Path('.') / 'ATRI' / 'modules' / 'favoIMP' / 'user.json', 'w') as a: - a.write(json.dumps(data)) - a.close() - except: - data = {} - data[f"{u}"] = [f"{favoIMP}"] - with open(Path('.') / 'ATRI' / 'modules' / 'favoIMP' / 'user.json', 'w') as a: - a.write(json.dumps(data)) - a.close() - -def DelFavoIMP(u, f:int, s:bool): - if s: - favoIMP = randint(1,f) - else: - favoIMP = f - try: - with open(Path('.') / 'ATRI' / 'modules' / 'favoIMP' / 'user.json', 'r') as a: - data = json.load(a) - data[f"{u}"][0] = int(data[f"{u}"][0]) - favoIMP - with open(Path('.') / 'ATRI' / 'modules' / 'favoIMP' / 'user.json', 'w') as a: - a.write(json.dumps(data)) - a.close() - except: - data = {} - data[f"{u}"] = [f"{0 - favoIMP}"] - with open(Path('.') / 'ATRI' / 'modules' / 'favoIMP' / 'user.json', 'w') as a: - a.write(json.dumps(data)) - a.close()
\ No newline at end of file diff --git a/ATRI/modules/favoIMP/user.json b/ATRI/modules/favoIMP/user.json deleted file mode 100644 index 9e26dfe..0000000 --- a/ATRI/modules/favoIMP/user.json +++ /dev/null @@ -1 +0,0 @@ -{}
\ No newline at end of file diff --git a/ATRI/modules/funcControl/ALLswitch.json b/ATRI/modules/funcControl/ALLswitch.json deleted file mode 100644 index 1b87087..0000000 --- a/ATRI/modules/funcControl/ALLswitch.json +++ /dev/null @@ -1 +0,0 @@ -{"pixiv_seach_img": "on", "pixiv_seach_author": "on", "pixiv_daily_rank": "on", "setu": "on", "setu_img": "off", "anime_search": "on", "change_face": "on", "chouYou": "on", "saucenao_search": "on"}
\ No newline at end of file diff --git a/ATRI/modules/funcControl/__init__.py b/ATRI/modules/funcControl/__init__.py deleted file mode 100644 index f4dac26..0000000 --- a/ATRI/modules/funcControl/__init__.py +++ /dev/null @@ -1,62 +0,0 @@ -import os -import json -from pathlib import Path -from typing import Optional - - -def checkSwitch(funcName: str, g: int): - file = Path('.') / 'ATRI' / 'modules' / 'funcControl' / 'ALLswitch.json' - with open(file, 'r') as f: - data = json.load(f) - if data[funcName] == "off": - return False - else: - try: - file = Path('.') / 'ATRI' / 'data' / 'groupData' / f'{g}' / 'switch.json' - with open(file, 'r') as f: - data = json.load(f) - except: - try: - os.mkdir(Path('.') / 'ATRI' / 'data' / 'groupData' / f'{g}') - except: - pass - data = {} - data["pixiv_seach_img"] = "on" - data["pixiv_seach_author"] = "on" - data["pixiv_daily_rank"] = "on" - data["setu"] = "on" - data["setu_img"] = "on" - data["anime_search"] = "on" - data["change_face"] = "on" - data["chouYou"] = "on" - data["saucenao_search"] = "on" - with open(Path('.') / 'ATRI' / 'data' / 'groupData' / f'{g}' / 'switch.json', 'w') as f: - f.write(json.dumps(data)) - f.close() - - if data[funcName] == "on": - return True - -def checkNoob(u: int, g: Optional[int] = None): - fileU = Path('.') / 'ATRI' / 'plugins' / 'noobList' / 'noobList.json' - fileG = Path('.') / 'ATRI' / 'plugins' / 'noobList' / 'noobGroup.json' - try: - with open(fileU, 'r') as f: - dataU = json.load(f) - except: - dataU = {} - - try: - with open(fileG, 'r') as f: - dataG = json.load(f) - except: - dataG = {} - - if str(u) not in dataU.keys(): - if g: - if str(g) not in dataG.keys(): - return True - else: - return True - else: - pass
\ No newline at end of file diff --git a/ATRI/modules/google_translate/__init__.py b/ATRI/modules/google_translate/__init__.py deleted file mode 100644 index c42b774..0000000 --- a/ATRI/modules/google_translate/__init__.py +++ /dev/null @@ -1,142 +0,0 @@ -import re -import requests -import demjson - - -def int_overflow(val): - maxint = 2147483647 - if not -maxint - 1 <= val <= maxint: - val = (val + (maxint + 1)) % (2 * (maxint + 1)) - maxint - 1 - return val - - -def ansii(a): - return a.encode('gbk') - - -def kr(a: int, b): - c = 0 - b = ansii(b) - while c < len(b) - 2: - d = b[c + 2] - d = d - 87 if ansii("a")[0] <= d else int(chr(d)) - d = a >> d if ansii("+")[0] == b[c + 1] else a << d - d = int_overflow(d) - a = a + d & 4294967295 if ansii("+")[0] == b[c] else a ^ d - c += 3 - return int_overflow(a) - - -def mr(q, TKK): - e = q.encode() - d = str(TKK).split('.') - a = int(d[0]) - b = int(d[0]) - - for f in e: - a += f - a = kr(a, "+-a^+6") - a = kr(a, "+-3^+b+-f") - a &= 0xffffffff # 出错了,转回无符号 - a ^= (int(d[1]) or 0) - if 0 > a: - a = (a & 2147483647) + 2147483648 - a %= 1E6 - a = int(a) - - # c = '&tk=' - # return c + (str(a) + "." + str(a ^ b)) - return (str(a) + "." + str(a ^ b)) - - -""" -def Sr(a, TKK): - a = ''.join(a['a']['b']['q']) - return mr(a, TKK) -d = { - 'a':{ - 'a': ['q'], - 'b': { - 'q': ['me'] - }, - 'c': 1, - 'g': 1 - }, - 'b': 1, - 'c': None, - 'j': False, -} -TKK = '426151.3141811846' -tk = Sr(d, TKK) -print(tk) -""" - -session = requests.session() - - -def translate(q='hello', source='en', to='zh-CN', tkk=None): - """ - 限制最大5000,按utf-8算,一个汉字算1个,1个英文算一个,超过会失败 - """ - if not tkk: - tkk = '426151.3141811846' - tk = mr(q, tkk) - params = { - 'client': 't', - 'sl': source, - 'tl': to, - 'hl': source, - 'dt': [ - 'at', 'qca', 'rw', 'rm', 'ss', 't' - ], - 'tk': tk, - 'ie': 'UTF-8', - 'oe': 'UTF-8', - 'pc': 1, - 'kc': 1, - 'ssel': 0, - 'otf': 1 - } - data = { - 'q': q - } - headers = { - 'Referer': 'https://translate.google.cn/', - 'Host': 'translate.google.cn', - } - resp = requests.post('https://translate.google.cn/translate_a/single', params=params, data=data, headers=headers) - if resp.status_code == 200: - resp.encoding = 'utf-8' - data = resp.json() - - result = [] - result.append(''.join(map(lambda x: x[0], data[0][:-1]))) - result.append(data[0][-1][-1]) - return result - else: - return None - - -def ref_words(q='hello', source='en', to='zh-CN'): - params = { - 'q': q, - 'client': 'translate-web', - 'ds': 'translate', - 'hl': source, - 'requiredfields': f'tl:{to}', - 'callback': 'window.google.ref_words' - } - url = 'https://clients1.google.com/complete/search?' - headers = { - 'Referer': 'https://translate.google.cn/', - 'Host': 'clients1.google.cn', - } - resp = session.get(url, params=params, headers=headers) - if resp.status_code == 200: - resp.encoding = 'utf-8' - result = re.search(r'window.google.ref_words\((.*)\)', resp.text).group(1) - json_data = demjson.decode(result) - data_list = list(map(lambda x: x[0], json_data[1])) - return data_list - else: - return None
\ No newline at end of file diff --git a/ATRI/modules/response/__init__.py b/ATRI/modules/response/__init__.py deleted file mode 100644 index 4a47140..0000000 --- a/ATRI/modules/response/__init__.py +++ /dev/null @@ -1,19 +0,0 @@ -# -*- coding:utf-8 -*- -import requests -from aiohttp import ClientSession - -def request_api(url): - response = requests.request("GET", url) - html = response.text - return html - -def request_api_params(url, params): - response = requests.get(url, params = params) - html = response.text - return html - -async def post_bytes(url, headers=None,data=None): - async with ClientSession() as asyncsession: - async with asyncsession.post(url,headers=headers,data=data) as response: - b = await response.read() - return b
\ No newline at end of file diff --git a/ATRI/modules/time/__init__.py b/ATRI/modules/time/__init__.py deleted file mode 100644 index 6e7806d..0000000 --- a/ATRI/modules/time/__init__.py +++ /dev/null @@ -1,24 +0,0 @@ -from random import choice -from datetime import datetime - -def now_time(): - now_ = datetime.now() - hour = now_.hour - minute = now_.minute - now = hour + minute / 60 - return now - -def sleepTime(): - if 0 <= now_time() < 5.5: - msg = choice( - [ - 'zzzz......', - 'zzzzzzzz......', - 'zzz...好涩哦..zzz....', - '别...不要..zzz..那..zzz..', - '嘻嘻..zzz..呐~..zzzz..' - ] - ) - return msg - else: - return False
\ No newline at end of file |