diff options
Diffstat (limited to 'ATRI/plugins/plugin_sqlite/__init__.py')
-rw-r--r-- | ATRI/plugins/plugin_sqlite/__init__.py | 146 |
1 files changed, 91 insertions, 55 deletions
diff --git a/ATRI/plugins/plugin_sqlite/__init__.py b/ATRI/plugins/plugin_sqlite/__init__.py index 42ea60c..1663026 100644 --- a/ATRI/plugins/plugin_sqlite/__init__.py +++ b/ATRI/plugins/plugin_sqlite/__init__.py @@ -22,12 +22,38 @@ from utils.utils_error import errorRepo from utils.utils_request import aio_get_bytes -UploadSetu = on_command('setu', permission=SUPERUSER) +SetuData = on_command('setu', permission=SUPERUSER) + [email protected]() # type: ignore +async def _(bot: Bot, event: Event, state: dict) -> None: + msg0 = "-==ATRI Setu Data System==-\n" + msg0 += "Upload:\n" + msg0 += " - setu [type] [pid]\n" + msg0 += " * type: normal, nearR18 r18\n" + msg0 += "Delete:\n" + msg0 += " - setu-delete [pid]" + await SetuData.finish(msg0) + + +UploadSetu = on_command('setu-upload', permission=SUPERUSER) @UploadSetu.handle() # type: ignore async def _(bot: Bot, event: Event, state: dict) -> None: msg = str(event.message).strip().split(' ') + if msg[0] and msg[1]: + pass + else: + msg0 = "请检查格式奥~!\n" + msg0 += "setu-upload [type] [pid]\n" + msg0 += "type: normal, nearR18, r18" + await UploadSetu.finish(msg0) + + if msg[0] not in ["noraml", "nearR18", "nearr18", "r18", "R18"]: + msg0 = "请检查类型~!\n" + msg0 += "type: normal, nearR18, r18" + await UploadSetu.finish(msg0) + s_type = msg[0] pid = msg[1] @@ -42,7 +68,7 @@ async def _(bot: Bot, event: Event, state: dict) -> None: info = info["response"][0] title = info["title"] tags = info["tags"] - account = info["account"] + account = info["user"]["account"] name = info["user"]["name"] u_id = info["user"]["id"] user_link = f'https://www.pixiv.net/users/' + f'{u_id}' @@ -50,61 +76,71 @@ async def _(bot: Bot, event: Event, state: dict) -> None: data_setu = (f'{pid}', f'{title}', f'{tags}', f'{account}', f'{name}', f'{u_id}', f'{user_link}', f'{img}') - if s_type == "normal": - if os.path.exists('ATRI/data/data_Sqlite/setu/normal.db'): - print('数据文件存在!') - else: - await bot.send(event, '数据库不存在,将开始构建...') - await bot.send(event, '开始构建数据库!') - con = sqlite3.connect(Path('.') / 'ATRI' / 'data' / 'data_Sqlite' / 'setu' / 'normal.db') - cur = con.cursor() - cur.execute('CREATE TABLE normal(pid PID, title TITLE, tags TAGS, account ACCOUNT, name NAME, u_id UID, user_link USERLINK, img IMG, UNIQUE(pid, title, tags, account, name, u_id, user_link, img))') - con.commit() - cur.close() - await bot.send(event, '完成') - - con = sqlite3.connect(Path('.') / 'ATRI' / 'data' / 'data_Sqlite' / 'setu' / 'normal.db') - cur = con.cursor() - cur.execute('INSERT INTO normal(pid, title, tags, account, name, u_id, user_link, img) VALUES(?, ?, ?, ?, ?, ?, ?, ?)', data_setu) - con.commit() - con.close() - - elif s_type == "nearr18": - if os.path.exists('ATRI/data/data_Sqlite/setu/nearR18.db'): - print('数据文件存在!') - else: - await bot.send(event, '数据库不存在,将开始构建...') - await bot.send(event, '开始构建数据库!') - con = sqlite3.connect(Path('.') / 'ATRI' / 'data' / 'data_Sqlite' / 'setu' / 'nearR18.db') - cur = con.cursor() - cur.execute('CREATE TABLE nearR18(pid PID, title TITLE, tags TAGS, account ACCOUNT, name NAME, u_id UID, user_link USERLINK, img IMG, UNIQUE(pid, title, tags, account, name, u_id, user_link, img))') - con.commit() - cur.close() - await bot.send(event, '完成') - - con = sqlite3.connect(Path('.') / 'ATRI' / 'data' / 'data_Sqlite' / 'setu' / 'nearR18.db') + if s_type == "nearr18": + s_type = "nearR18" + elif s_type == "R18": + s_type = "r18" + else: + pass + + if os.path.exists(f'ATRI/data/data_Sqlite/setu/{s_type}.db'): + print('数据文件存在!') + else: + await DeleteSetu.finish("数据库都不在添加🔨!?罢了我现创一个") + con = sqlite3.connect(Path('.') / 'ATRI' / 'data' / 'data_Sqlite' / 'setu' / f'{s_type}.db') cur = con.cursor() - cur.execute('INSERT INTO nearR18(pid, title, tags, account, name, u_id, user_link, img) VALUES(?, ?, ?, ?, ?, ?, ?, ?)', data_setu) + cur.execute(f'CREATE TABLE {s_type}(pid PID, title TITLE, tags TAGS, account ACCOUNT, name NAME, u_id UID, user_link USERLINK, img IMG, UNIQUE(pid, title, tags, account, name, u_id, user_link, img))') con.commit() - con.close() + cur.close() + await bot.send(event, '完成') + + con = sqlite3.connect(Path('.') / 'ATRI' / 'data' / 'data_Sqlite' / 'setu' / f'{s_type}.db') + cur = con.cursor() + cur.execute(f'INSERT INTO {s_type}(pid, title, tags, account, name, u_id, user_link, img) VALUES(?, ?, ?, ?, ?, ?, ?, ?)', data_setu) + con.commit() + cur.close() + + await UploadSetu.finish(f"数据上传完成~!\n涩图库[{s_type}]涩图 +1") + + +DeleteSetu = on_command('setu-delete', permission=SUPERUSER) + [email protected]() # type: ignore +async def _(bot: Bot, event: Event, state: dict) -> None: + msg = str(event.message).strip().split(' ') - elif s_type == "r18": - if os.path.exists('ATRI/data/data_Sqlite/setu/r18.db'): - print('数据文件存在!') - else: - await bot.send(event, '数据库不存在,将开始构建...') - await bot.send(event, '开始构建数据库!') - con = sqlite3.connect(Path('.') / 'ATRI' / 'data' / 'data_Sqlite' / 'setu' / 'r18.db') - cur = con.cursor() - cur.execute('CREATE TABLE r18(pid PID, title TITLE, tags TAGS, account ACCOUNT, name NAME, u_id UID, user_link USERLINK, img IMG, UNIQUE(pid, title, tags, account, name, u_id, user_link, img))') - con.commit() - cur.close() - await bot.send(event, '完成') + if msg[0] and msg[1]: + pass + else: + msg0 = "请检查格式奥~!\n" + msg0 += "setu-delete [type] [pid]\n" + msg0 += "type: normal, nearR18, r18" + await DeleteSetu.finish(msg0) + + if msg[0] not in ["noraml", "nearR18", "nearr18", "r18", "R18"]: + msg0 = "请检查类型~!\n" + msg0 += "type: normal, nearR18, r18" + await UploadSetu.finish(msg0) + + s_type = msg[0] + pid = msg[1] + + if s_type == "nearr18": + s_type = "nearR18" + elif s_type == "R18": + s_type = "r18" + else: + pass + + if os.path.exists(f'ATRI/data/data_Sqlite/setu/{s_type}.db'): + print('数据文件存在!') + else: + await DeleteSetu.finish("数据库都不在删🔨!?") - con = sqlite3.connect(Path('.') / 'ATRI' / 'data' / 'data_Sqlite' / 'setu' / 'r18.db') - cur = con.cursor() - cur.execute('INSERT INTO r18(pid, title, tags, account, name, u_id, user_link, img) VALUES(?, ?, ?, ?, ?, ?, ?, ?)', data_setu) - con.commit() - con.close() + con = sqlite3.connect(Path('.') / 'ATRI' / 'data' / 'data_Sqlite' / 'setu' / f'{s_type}.db') + cur = con.cursor() + cur.execute(f'DELETE FROM {s_type} WHERE pid = {pid}') + con.commit() + con.close() - await UploadSetu.finish(f"数据上传完成~!\n涩图库[{s_type}]涩图 +1") + await UploadSetu.finish(f"数据删除完成~!\n涩图库[{s_type}]涩图 -1") |