async def task(session: CommandSession): arg = session.get('arg') userid = session.event.user_id # QQ号 nickname = session.event.sender['nickname'] # 昵称,注意转义 tasknumber = await record(arg, userid, session) if tasknumber == '-1': await arg_err(session) elif tasknumber == "-2": session.finish() else: await session.send(str(userid)+' 任务 '+tasknumber+' 记录成功') session.finish()
async def swcmd(session: CommandSession, on: bool): if session.event.detail_type == "private": session.finish("目前仅支持针对群聊的操控哦!") ccmd = session.current_arg_text.strip().split(" ") ans = [] async with db.pool.acquire() as conn: values = await conn.fetch("""select * from mg where gid={}""".format( session.event.group_id)) if len(values) == 0: await conn.execute( "insert into mg (gid,white) values ({},{})".format( session.event.group_id, on)) for i in ccmd: if i in cmd: await conn.execute( """update mg set {} = {} where gid = {}""".format( i, on, session.event.group_id)) ans.append(cmd[i]) if len(ans) > 0: session.finish("{} 功能已{}".format("、".join(ans), "开启" if on else "关闭"))
async def arg_err(session): """input wrong arg""" await session.send(ERR_STR) session.finish()
async def check(session: CommandSession): arg = session.get('arg') userid = session.event.user_id # QQ号 nickname = session.event.sender['nickname'] # 昵称,注意转义 tasknumber = await checkrecord(arg, userid, session) session.finish()
async def _(session: CommandSession): 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) i_tpye = msg[1] pid = msg[2] URL = url + pid dc = json.loads(response.request_api(URL)) if not dc: session.finish('ATRI在尝试解析数据时出问题...等会再试试吧...') title = dc["response"][0]["title"] tags = dc["response"][0]["tags"] account = dc["response"][0]["user"]["account"] name = dc["response"][0]["user"]["name"] u_id = dc["response"][0]["user"]["id"] 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秒后开始构建...') await asyncio.sleep(3) await session.send('开始构建数据库!') con = sqlite3.connect( Path('.') / 'ATRI' / '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() con.close() await session.send('完成') con = sqlite3.connect( Path('.') / 'ATRI' / 'data' / 'sqlite' / 'setu' / 'normal.db') cur = con.cursor() cur.execute( 'INSERT INTO normal(pid, title, tags, account, name, u_id, user_link, img) VALUES(?, ?, ?, ?, ?, ?, ?, ?)', dataSETU) con.commit() con.close() elif i_tpye == '擦边球': if os.path.exists('ATRI/data/sqlite/setu/nearR18.db'): print('数据文件存在!') else: await session.send('数据库不存在,将在3秒后开始构建...') await asyncio.sleep(3) await session.send('开始构建数据库!') con = sqlite3.connect( Path('.') / 'ATRI' / '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() con.close() await session.send('完成') con = sqlite3.connect( Path('.') / 'ATRI' / 'data' / 'sqlite' / 'setu' / 'nearR18.db') cur = con.cursor() cur.execute( 'INSERT INTO nearR18(pid, title, tags, account, name, u_id, user_link, img) VALUES(?, ?, ?, ?, ?, ?, ?, ?)', dataSETU) con.commit() con.close() elif i_tpye == 'r18': if os.path.exists('ATRI/data/sqlite/cloudmusic/cloudmusic.db'): print('数据文件存在!') else: await session.send('数据库不存在,将在3秒后开始构建...') await asyncio.sleep(3) await session.send('开始构建数据库!') con = sqlite3.connect( Path('.') / 'ATRI' / '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() con.close() await session.send('完成') con = sqlite3.connect( Path('.') / 'ATRI' / 'data' / 'sqlite' / 'setu' / 'r18.db') cur = con.cursor() cur.execute( 'INSERT INTO r18(pid, title, tags, account, name, u_id, user_link, img) VALUES(?, ?, ?, ?, ?, ?, ?, ?)', dataSETU) con.commit() con.close() end = time.perf_counter() await session.send(f'数据上传完成!\n耗时: {round(end - start, 3)}s')
async def mg(session: CommandSession): session.finish("{}")