diff options
Diffstat (limited to 'ATRI/plugins')
| -rw-r--r-- | ATRI/plugins/hbook.py | 8 | ||||
| -rw-r--r-- | ATRI/plugins/hitokoto.py | 4 | ||||
| -rw-r--r-- | ATRI/plugins/other.py | 26 | ||||
| -rw-r--r-- | ATRI/plugins/pixiv.py | 15 | ||||
| -rw-r--r-- | ATRI/plugins/send.py | 8 | ||||
| -rw-r--r-- | ATRI/plugins/setu.py | 18 | ||||
| -rw-r--r-- | ATRI/plugins/switch.py | 4 | ||||
| -rw-r--r-- | ATRI/plugins/upload_setu.py | 105 | ||||
| -rw-r--r-- | ATRI/plugins/welcome.py | 5 | 
9 files changed, 136 insertions, 57 deletions
| diff --git a/ATRI/plugins/hbook.py b/ATRI/plugins/hbook.py index b0733f8..d1a79bc 100644 --- a/ATRI/plugins/hbook.py +++ b/ATRI/plugins/hbook.py @@ -1,5 +1,6 @@  # -*- coding:utf-8 -*-  import re +import time  import json  from nonebot import on_command, CommandSession @@ -8,10 +9,11 @@ from ATRI.modules import response # type: ignore  @on_command('hbook', aliases = ['本子', '本子搜索', '本子查询'], only_to_me = False)  async def _(session: CommandSession): -    with open(f'ATRI\\plugins\\switch\\switch.json', 'r') as f: +    with open('ATRI/plugins/switch/switch.json', 'r') as f:          data = json.load(f)      if data["hbook"] == 0: +        start = time.perf_counter()          h_msg = session.current_arg.strip()          if not h_msg: @@ -50,6 +52,10 @@ async def _(session: CommandSession):              for i in range(n):                  msg0 = ('\n——————————\n本子链接:https://b-upp.com%s \n本子标题:%s '%(data[i]))                  msg += msg0 +            end = time.perf_counter() +            msg0 = f'\n——————————\n耗时: {round(end - start, 3)}s' +            msg += msg0 +              await session.send(message=msg)      else: diff --git a/ATRI/plugins/hitokoto.py b/ATRI/plugins/hitokoto.py index 2f542c3..36a5f33 100644 --- a/ATRI/plugins/hitokoto.py +++ b/ATRI/plugins/hitokoto.py @@ -2,7 +2,7 @@  import json  from nonebot import on_command, on_natural_language, CommandSession  from nonebot import NLPSession, NLPResult -from ATRI.modules import response +from ATRI.modules import response # type: ignore  url = f'https://api.imjad.cn/hitokoto/?cat=a&charset=utf-8&length=50&encode=json&fun=sync&source=' @@ -30,4 +30,4 @@ async def hitokoto(session: CommandSession):  @on_natural_language('一言', only_to_me = False)  async def _(session: NLPSession): -    return NLPResult(60.0, ('hitokoto',), None)
\ No newline at end of file +    return NLPResult(60.0, ('hitokoto'), None)
\ No newline at end of file diff --git a/ATRI/plugins/other.py b/ATRI/plugins/other.py index abecb18..088d793 100644 --- a/ATRI/plugins/other.py +++ b/ATRI/plugins/other.py @@ -72,10 +72,10 @@ async def _(session: CommandSession):  async def _(session: CommandSession):      await session.send(          f"""想了解ATRI嘛 -        写出咱的是Kyomotoi -        他的主页:https://lolihub.icu -        项目地址:https://github.com/Kyomotoi/ATRI -        欢迎star~w!""" +写出咱的是Kyomotoi +他的主页:https://blog.lolihub.icu +项目地址:https://github.com/Kyomotoi/ATRI +欢迎star~w!"""      )  @on_command( @@ -90,6 +90,20 @@ async def _(session: CommandSession):  async def _(session: CommandSession):      await session.send(          f"""{render_expression(HELP_REPLY)} -        看这吧! -        https://lolihub.icu/#/robot/user""" +发送:菜单 +或看这吧! +https://lolihub.icu/#/robot/user""" +        ) + +@on_command( +    'menu', +    aliases = [ +        '菜单' +    ], +    only_to_me = False +) +async def _(session: CommandSession): +    await session.send( +        f""" +        """      )
\ No newline at end of file diff --git a/ATRI/plugins/pixiv.py b/ATRI/plugins/pixiv.py index d5b5b62..aeadc67 100644 --- a/ATRI/plugins/pixiv.py +++ b/ATRI/plugins/pixiv.py @@ -31,7 +31,7 @@ Link: {user_link}  @on_command('pixiv_seach_img', aliases = ['p站搜图', 'P站搜图', '批站搜图'], only_to_me = False)  async def _(session: CommandSession): -    with open(f'ATRI\\plugins\\switch\\switch.json', 'r') as f: +    with open('ATRI/plugins/switch/switch.json', 'r') as f:          data = json.load(f)      if data["pixiv_seach_img"] == 0: @@ -52,6 +52,7 @@ async def _(session: CommandSession):              session.finish('ATRI在网络上走散了...请重试...')          img = f'https://pixiv.cat/{pid}.jpg' +                  end = time.perf_counter() @@ -66,7 +67,7 @@ async def _(session: CommandSession):                  account = dc["response"][0]["user"]["account"],                  name = dc["response"][0]["user"]["name"],                  user_link = f'https://www.pixiv.net/users/' + f'{dc["response"][0]["user"]["id"]}', -                img = f'[CQ:image, file={img}]', +                img = img,                  time = round(end - start, 3)              )          ) @@ -75,9 +76,9 @@ async def _(session: CommandSession):          await session.send('该功能已被禁用...') -@on_command('pixiv_seach_author', aliases = ['画师'], only_to_me = False) +@on_command('pixiv_seach_author', aliases = ['画师', '搜索画师', '画师搜索'], only_to_me = False)  async def _(session: CommandSession): -    with open(f'ATRI\\plugins\\switch\\switch.json', 'r') as f: +    with open('ATRI/plugins/switch/switch.json', 'r') as f:          data = json.load(f)      if data["pixiv_seach_author"] == 0: @@ -116,7 +117,7 @@ async def _(session: CommandSession):          for i in result:              t += 1 -            msg = (f'\n---------------\n({t})\nPid: {i[1][0]}\n[CQ:image, file={i[1][1]}]') +            msg = (f'\n---------------\n({t})\nPid: {i[1][0]}\n{i[1][1]}')              msg0 += msg          end = time.perf_counter() @@ -131,7 +132,7 @@ async def _(session: CommandSession):  @on_command('pixiv_daily_rank', aliases = ['P站排行榜', '批站排行榜', 'p站排行榜'], only_to_me = False)  async def _(session: CommandSession): -    with open(f'ATRI\\plugins\\switch\\switch.json', 'r') as f: +    with open('ATRI/plugins/switch/switch.json', 'r') as f:          data = json.load(f)      if data["pixiv_daily_rank"] == 0: @@ -161,7 +162,7 @@ async def _(session: CommandSession):          for i in result:              t += 1 -            msg = (f'\n---------------\n({t})\nPid: {i[1][0]}\n[CQ:image, file={i[1][1]}]') +            msg = (f'\n---------------\n({t})\nPid: {i[1][0]}\n{i[1][1]}')              msg0 += msg          end = time.perf_counter() diff --git a/ATRI/plugins/send.py b/ATRI/plugins/send.py index 6cc57e1..6cb1905 100644 --- a/ATRI/plugins/send.py +++ b/ATRI/plugins/send.py @@ -9,11 +9,13 @@ master = bot.config.SUPERUSERS  ban_group = bot.config.BANGROUP # type: ignore -@on_command('send_all_group', aliases=['公告', '群发', '推送'], only_to_me=False) +@on_command('send_all_group', aliases = ['公告', '群发', '推送'], only_to_me=False)  async def send_all_group(session: CommandSession):      if session.event.user_id in master:          msg = session.current_arg.strip() +        start =time.perf_counter() +          if not msg:              msg = session.get('message', prompt='请告诉吾辈需要群发的内容~!') @@ -28,8 +30,10 @@ async def send_all_group(session: CommandSession):                  except:                      pass +         +        end = time.perf_counter() -        await session.send('推送完成!') +        await session.send(f'推送完成!\n耗时:{round(end - start, 3)}')  @on_command('send_to_group', aliases=['对群'], only_to_me=False) diff --git a/ATRI/plugins/setu.py b/ATRI/plugins/setu.py index 315803b..b178fef 100644 --- a/ATRI/plugins/setu.py +++ b/ATRI/plugins/setu.py @@ -3,6 +3,9 @@ import time  import json  import nonebot  from nonebot import on_command, CommandSession +from nonebot import NLPSession +from nonebot.natural_language import NLPResult +from nonebot.plugin import on_natural_language  from ATRI.modules import response # type: ignore @@ -15,17 +18,18 @@ URL = 'https://api.lolicon.app/setu/'  SETU_REPLY = """Title: {title}  Pid: {pid} -[CQ:image,file={setu}] +{setu}  ---------------  完成时间:{time}s""" -@on_command('setu', aliases = ['图来'], only_to_me = False) -async def _(session: CommandSession): -    with open(f'ATRI\\plugins\\switch\\switch.json', 'r') as f: +@on_command('setu', aliases = ['图来', '涩图', '涩图来'], only_to_me = False) +async def setu(session: CommandSession): +    with open('ATRI/plugins/switch/switch.json', 'r') as f:          data = json.load(f)      if data["setu"] == 0: +        await session.send('别急!正在找图!')          start = time.perf_counter()          values = {              "apikey": apikey, @@ -46,4 +50,8 @@ async def _(session: CommandSession):          )      else: -        await session.send('该功能已被禁用...')
\ No newline at end of file +        await session.send('该功能已被禁用...') + +@on_natural_language(['涩图', '色图'], only_to_me = False) +async def _(session: NLPSession): +    return NLPResult(60.0, ('setu'), None)
\ No newline at end of file diff --git a/ATRI/plugins/switch.py b/ATRI/plugins/switch.py index 4ba24e3..dc998a7 100644 --- a/ATRI/plugins/switch.py +++ b/ATRI/plugins/switch.py @@ -10,7 +10,7 @@ master = bot.config.SUPERUSERS  @on_command('switch', aliases = ['开启', '关闭'], only_to_me = False)  async def _(session: CommandSession): -    with open(f'ATRI\\plugins\\switch\\switch.json', 'r') as f: +    with open(f"ATRI/plugins/switch/switch.json", 'r') as f:          data = json.load(f)      if session.event.user_id in master: @@ -69,7 +69,7 @@ async def _(session: CommandSession):                  pass          a = json.dumps(data) -        f2 = open(f'ATRI\\plugins\\switch\\switch.json', 'w') +        f2 = open(f"ATRI/plugins/switch/switch.json", 'w')          f2.write(a)          f2.close diff --git a/ATRI/plugins/upload_setu.py b/ATRI/plugins/upload_setu.py index 78158c3..c9dec60 100644 --- a/ATRI/plugins/upload_setu.py +++ b/ATRI/plugins/upload_setu.py @@ -1,29 +1,29 @@  # -*- coding:utf-8 -*- +import os  import time  import json  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  bot = nonebot.get_bot()  master = bot.config.SUPERUSERS # type: ignore -path_setu = f'ATRI\\splite\\setu\\' -path_cloudmusic = f'ATRI\\splite\\cloudmusic\\'  url = f'https://api.imjad.cn/pixiv/v1/?type=illust&id='  @on_command('upload_setu', aliases = ['上传涩图'], only_to_me = False)  async def _(session: CommandSession):      if session.event.user_id in master: +        start = time.perf_counter()          msg = session.event.raw_message.split(' ', 2)          print(msg)          i_tpye = msg[1] -        pid = msg[2] +        pid = msg[2]           URL = url + pid @@ -39,80 +39,125 @@ async def _(session: CommandSession):          img = f'https://pixiv.cat/{pid}.jpg'          if i_tpye == '正常': -            con = sqlite3.connect(path_setu + 'normal.db') +            if os.path.exists('ATRI/sqlite/setu/normal.db'): +                print('数据文件存在!') +            else: +                await session.send('数据库不存在,将在3秒后开始构建...') +                time.sleep(3) +                await session.send('开始构建数据库!') +                con = sqlite3.connect(Path('.') / 'ATRI' / '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' / '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))              con.commit() - -            print('success!') -            time.sleep(0.5)              con.close()          elif i_tpye == '擦边球': -            con = sqlite3.connect(path_setu + 'nearR18.db') +            if os.path.exists('ATRI/sqlite/setu/nearR18.db'): +                print('数据文件存在!') +            else: +                await session.send('数据库不存在,将在3秒后开始构建...') +                time.sleep(3) +                await session.send('开始构建数据库!') +                con = sqlite3.connect(Path('.') / 'ATRI' / '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' / '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))              con.commit() - -            print('success!') -            time.sleep(0.5)              con.close()          elif i_tpye == 'r18': -            con = sqlite3.connect(path_setu + 'r18.db') +            if os.path.exists('ATRI/sqlite/cloudmusic/cloudmusic.db'): +                print('数据文件存在!') +            else: +                await session.send('数据库不存在,将在3秒后开始构建...') +                time.sleep(3) +                await session.send('开始构建数据库!') +                con = sqlite3.connect(Path('.') / 'ATRI' / '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' / '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))              con.commit() - -            print('success!') -            time.sleep(0.5)              con.close() -        await session.send('数据上传完成!') +        end = time.perf_counter() +         +        await session.send(f'数据上传完成!\n耗时: {round(end - start, 3)}s')  @on_command('upload_cloudmusic', aliases = ['上传网抑语', '网抑云', '网易云'], only_to_me = False)  async def _(session: CommandSession):      if session.event.user_id in master: +        start = time.perf_counter()          msg = session.event.raw_message.split(' ', 1)          msg = msg[1] -        con = sqlite3.connect(path_cloudmusic + 'cloudmusic.db') +        if os.path.exists('ATRI/sqlite/cloudmusic/cloudmusic.db'): +                print('数据文件存在!') +        else: +            await session.send('数据库不存在,将在3秒后开始构建...') +            time.sleep(3) +            await session.send('开始构建数据库!') +            con = sqlite3.connect(Path('.') / 'ATRI' / 'sqlite' / 'cloudmusic' / 'cloudmusic.db') +            cur = con.cursor() +            cur.execute('CREATE TABLE cloudmusic(msg MSG, UNIQUE(msg))') +            con.commit() +            cur.close() +            con.close() +            await session.send('完成') +  +        con = sqlite3.connect(Path('.') / 'ATRI' / 'sqlite' / 'cloudmusic' / 'cloudmusic.db')          cur = con.cursor() -          cur.execute('INSERT INTO cloudmusic VALUES ("%s")'%(msg))          con.commit() - -        print('success!') -        time.sleep(0.5)          con.close() -        await session.send('数据上传完成!') +        end = time.perf_counter() + +        await session.send(f'数据上传完成!\n耗时: {round(end - start, 3)}s')  @on_command('data_list', aliases = ['查看上传数据', '数据总量'], only_to_me = False)  async def _(session: CommandSession): -    con = sqlite3.connect(path_setu + 'normal.db') # setu-normal +    con = sqlite3.connect(Path('.') / 'ATRI' / 'sqlite' / 'setu' / 'normal.db') # setu-normal      cur = con.cursor()      cur.execute("select * from normal")      data_normal = len(cur.fetchall())      con.close() -    con = sqlite3.connect(path_setu + 'nearR18.db') # setu-nearR18 +    con = sqlite3.connect(Path('.') / 'ATRI' / 'sqlite' / 'setu' / 'nearR18.db') # setu-nearR18      cur = con.cursor()      cur.execute("select * from nearR18")      data_nearR18 = len(cur.fetchall())      con.close() -    con = sqlite3.connect(path_setu + 'r18.db') # setu-r18 +    con = sqlite3.connect(Path('.') / 'ATRI' / 'sqlite' / 'setu' / 'r18.db') # setu-r18      cur = con.cursor()      cur.execute("select * from r18")      data_r18 = len(cur.fetchall())      con.close() -    con = sqlite3.connect(path_cloudmusic + 'cloudmusic.db') # cloudmusic +    con = sqlite3.connect(Path('.') / 'ATRI' / 'sqlite' / 'cloudmusic' / 'cloudmusic.db') # cloudmusic      cur = con.cursor()      cur.execute("select * from cloudmusic")      data_cloudmusic = len(cur.fetchall()) diff --git a/ATRI/plugins/welcome.py b/ATRI/plugins/welcome.py index 16cd706..fd33370 100644 --- a/ATRI/plugins/welcome.py +++ b/ATRI/plugins/welcome.py @@ -1,6 +1,7 @@  # -*- coding:utf-8 -*-  import json  import nonebot +from pathlib import Path  from nonebot import on_notice  from nonebot.notice_request import NoticeSession, RequestSession  from nonebot.plugin import on_request @@ -28,7 +29,7 @@ async def _(session: NoticeSession, CommandSession):          message = f'{user}\n想认识ATRI欸欸欸!!'      ) -    with open(f'ATRI\\plugins\\switch\\switch.json', 'r') as f: +    with open(Path('.') / 'ATRI' / 'plugins' / 'switch' / 'switch.json', 'r') as f:          data = json.load(f)      if data["approve_friend_add"] == 0: @@ -57,7 +58,7 @@ async def _(session: RequestSession):      group = session.event.group_id      user = session.event.user_id -    with open(f'ATRI\\plugins\\switch\\switch.json', 'r') as f: +    with open(Path('.') / 'ATRI' / 'plugins' / 'switch' / 'switch.json', 'r') as f:          data = json.load(f)      if session.event.sub_type == 'invite': | 
