diff options
Diffstat (limited to 'ATRI/plugins/UploadSqlite.py')
-rw-r--r-- | ATRI/plugins/UploadSqlite.py | 111 |
1 files changed, 100 insertions, 11 deletions
diff --git a/ATRI/plugins/UploadSqlite.py b/ATRI/plugins/UploadSqlite.py index f1dc602..6488ed4 100644 --- a/ATRI/plugins/UploadSqlite.py +++ b/ATRI/plugins/UploadSqlite.py @@ -1,11 +1,13 @@ import os import time import json +import asyncio import sqlite3 import nonebot from pathlib import Path from nonebot import on_command, CommandSession +from nonebot import session from ATRI.modules import response # type: ignore @@ -15,9 +17,26 @@ master = bot.config.SUPERUSERS # type: ignore url = f'https://api.imjad.cn/pixiv/v1/?type=illust&id=' +try: + with open(Path('.') / 'ATRI' / 'plugins' / 'UploadSqlite' / 'sepi.json', 'r') as f: + sP = json.load(f) +except: + sP = {} +sepi = list(sP.keys()) + +try: + with open(Path('.') / 'ATRI' / 'plugins' / 'UploadSqlite' / 'cloudmusic.json', 'r') as f: + cD = json.load(f) +except: + cD = {} +cloudmusic = list(cD.keys()) + + + @on_command('upload_setu', aliases = ['上传涩图'], only_to_me = False) async def _(session: CommandSession): - if session.event.user_id in master: + user = session.event.user_id + if user in master or user in sepi: start = time.perf_counter() msg = session.event.raw_message.split(' ', 2) print(msg) @@ -37,12 +56,14 @@ async def _(session: CommandSession): user_link = f'https://www.pixiv.net/users/' + f'{u_id}' img = f'https://pixiv.cat/{pid}.jpg' + dataSETU = (f'{pid}', f'{title}', f'{tags}', f'{account}', f'{name}', f'{u_id}', f'{user_link}', f'{img}') + if i_tpye == '正常': if os.path.exists('ATRI/data/sqlite/setu/normal.db'): print('数据文件存在!') else: await session.send('数据库不存在,将在3秒后开始构建...') - time.sleep(3) + await asyncio.sleep(3) await session.send('开始构建数据库!') con = sqlite3.connect(Path('.') / 'ATRI' / 'data' / 'sqlite' / 'setu' / 'normal.db') cur = con.cursor() @@ -54,7 +75,7 @@ async def _(session: CommandSession): con = sqlite3.connect(Path('.') / 'ATRI' / 'data' / 'sqlite' / 'setu' / 'normal.db') cur = con.cursor() - cur.execute('INSERT INTO normal VALUES ("%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s")'%(pid, title, tags, account, name, u_id, user_link, img)) + cur.execute('INSERT INTO normal(pid, title, tags, account, name, u_id, user_link, img) VALUES(?, ?, ?, ?, ?, ?, ?, ?)', dataSETU) con.commit() con.close() @@ -63,7 +84,7 @@ async def _(session: CommandSession): print('数据文件存在!') else: await session.send('数据库不存在,将在3秒后开始构建...') - time.sleep(3) + await asyncio.sleep(3) await session.send('开始构建数据库!') con = sqlite3.connect(Path('.') / 'ATRI' / 'data' / 'sqlite' / 'setu' / 'nearR18.db') cur = con.cursor() @@ -75,7 +96,7 @@ async def _(session: CommandSession): con = sqlite3.connect(Path('.') / 'ATRI' / 'data' / 'sqlite' / 'setu' / 'nearR18.db') cur = con.cursor() - cur.execute('INSERT INTO nearR18 VALUES ("%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s")'%(pid, title, tags, account, name, u_id, user_link, img)) + cur.execute('INSERT INTO nearR18(pid, title, tags, account, name, u_id, user_link, img) VALUES(?, ?, ?, ?, ?, ?, ?, ?)', dataSETU) con.commit() con.close() @@ -84,7 +105,7 @@ async def _(session: CommandSession): print('数据文件存在!') else: await session.send('数据库不存在,将在3秒后开始构建...') - time.sleep(3) + await asyncio.sleep(3) await session.send('开始构建数据库!') con = sqlite3.connect(Path('.') / 'ATRI' / 'data' / 'sqlite' / 'setu' / 'r18.db') cur = con.cursor() @@ -96,7 +117,7 @@ async def _(session: CommandSession): con = sqlite3.connect(Path('.') / 'ATRI' / 'data' / 'sqlite' / 'setu' / 'r18.db') cur = con.cursor() - cur.execute('INSERT INTO r18 VALUES ("%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s")'%(pid, title, tags, account, name, u_id, user_link, img)) + cur.execute('INSERT INTO r18(pid, title, tags, account, name, u_id, user_link, img) VALUES(?, ?, ?, ?, ?, ?, ?, ?)', dataSETU) con.commit() con.close() @@ -106,7 +127,8 @@ async def _(session: CommandSession): @on_command('upload_cloudmusic', aliases = ['上传网抑语', '网抑云', '网易云'], only_to_me = False) async def _(session: CommandSession): - if session.event.user_id in master: + user = session.event.user_id + if user in master or user in cloudmusic: start = time.perf_counter() msg = session.event.raw_message.split(' ', 1) msg = msg[1] @@ -115,7 +137,7 @@ async def _(session: CommandSession): print('数据文件存在!') else: await session.send('数据库不存在,将在3秒后开始构建...') - time.sleep(3) + await asyncio.sleep(3) await session.send('开始构建数据库!') con = sqlite3.connect(Path('.') / 'ATRI' / 'data' / 'sqlite' / 'cloudmusic' / 'cloudmusic.db') cur = con.cursor() @@ -127,10 +149,77 @@ async def _(session: CommandSession): con = sqlite3.connect(Path('.') / 'ATRI' / 'data' / 'sqlite' / 'cloudmusic' / 'cloudmusic.db') cur = con.cursor() - cur.execute('INSERT INTO cloudmusic VALUES ("%s")'%(msg)) + cur.execute('INSERT INTO cloudmusic(msg) VALUES (?)', msg) con.commit() con.close() end = time.perf_counter() - await session.send(f'数据上传完成!\n耗时: {round(end - start, 3)}s')
\ No newline at end of file + await session.send(f'数据上传完成!\n耗时: {round(end - start, 3)}s') + + +@on_command('add_check_sepi', aliases=['添加涩批', '移除涩批'], only_to_me = False) +async def _(session: CommandSession): + if session.event.user_id in master: + msg = session.event.raw_message.split(' ', 1) + m_type = msg[0] + u = msg[1] + + if m_type == '添加涩批': + try: + with open(Path('.') / 'ATRI' / 'plugins' / 'UploadSqlite' / 'sepi.json', 'r') as f: + data = json.load(f) + except: + data = {} + + data[f"{u}"] = f"{u}" + f = open(Path('.') / 'ATRI' / 'plugins' / 'UploadSqlite' / 'sepi.json', 'w') + f.write(json.dumps(data)) + f.close() + await session.send(f'成功添加涩批[{u}]!') + + elif m_type == '移除涩批': + try: + with open(Path('.') / 'ATRI' / 'plugins' / 'UploadSqlite' / 'sepi.json', 'r') as f: + data = json.load(f) + except: + data = {} + + data.pop(f"{u}") + f = open(Path('.') / 'ATRI' / 'plugins' / 'UploadSqlite' / 'sepi.json', 'w') + f.write(json.dumps(data)) + f.close() + await session.send(f'成功移除涩批[{u}]!') + +@on_command('add_check_cd', aliases = ['添加抑郁', '移除抑郁'], only_to_me = False) +async def _(session: CommandSession): + if session.event.user_id in master: + msg = session.event.raw_message.split(' ', 1) + m_type = msg[0] + u = msg[1] + + if m_type == '添加抑郁': + try: + with open(Path('.') / 'ATRI' / 'plugins' / 'UploadSqlite' / 'cloudmusic.json', 'r') as f: + data = json.load(f) + except: + data = {} + + data[f"{u}"] = f"{u}" + f = open(Path('.') / 'ATRI' / 'plugins' / 'UploadSqlite' / 'cloudmusic.json', 'w') + f.write(json.dumps(data)) + f.close() + await session.send(f'成功添加抑郁[{u}]!') + + elif m_type == '移除抑郁': + try: + with open(Path('.') / 'ATRI' / 'plugins' / 'UploadSqlite' / 'cloudmusic.json', 'r') as f: + data = json.load(f) + except: + data = {} + + data.pop(f"{u}") + f = open(Path('.') / 'ATRI' / 'plugins' / 'UploadSqlite' / 'cloudmusic.json', 'w') + f.write(json.dumps(data)) + f.close() + await session.send(f'成功移除抑郁[{u}]!')
\ No newline at end of file |