diff options
| author | Kyomotoi <1172294279@qq.com> | 2020-10-18 15:22:16 +0800 | 
|---|---|---|
| committer | Kyomotoi <1172294279@qq.com> | 2020-10-18 15:22:16 +0800 | 
| commit | e96c42ef2006e052dc334c1cc1771e546f357fae (patch) | |
| tree | f1f813573396f0b7ecd005bed8b8bfb54f355a72 | |
| parent | 9b1384577c16486f8ea21632a0cee50e05fd43ad (diff) | |
| download | ATRI-e96c42ef2006e052dc334c1cc1771e546f357fae.tar.gz ATRI-e96c42ef2006e052dc334c1cc1771e546f357fae.tar.bz2 ATRI-e96c42ef2006e052dc334c1cc1771e546f357fae.zip  | |
[Update]
| -rw-r--r-- | ATRI/__init__.py | 11 | ||||
| -rw-r--r-- | ATRI/data/data_IDcard/main.bin | bin | 0 -> 3992353 bytes | |||
| -rw-r--r-- | ATRI/plugins/plugin_admin/__init__.py | 20 | ||||
| -rw-r--r-- | ATRI/plugins/plugin_anime/__init__.py | 114 | ||||
| -rw-r--r-- | ATRI/plugins/plugin_anime/body.py | 11 | ||||
| -rw-r--r-- | ATRI/plugins/plugin_chat/__init__.py | 92 | ||||
| -rw-r--r-- | ATRI/plugins/plugin_pixiv/__init__.py | 203 | ||||
| -rw-r--r-- | ATRI/plugins/plugin_rich/__init__.py | 12 | ||||
| -rw-r--r-- | ATRI/plugins/plugin_rich/body.py | 11 | ||||
| -rw-r--r-- | ATRI/plugins/plugin_status/__init__.py | 11 | ||||
| -rw-r--r-- | ATRI/plugins/plugin_test/__init__.py | 47 | ||||
| -rw-r--r-- | ATRI/plugins/plugin_test/test.mp3 | bin | 0 -> 4029360 bytes | |||
| -rw-r--r-- | ATRI/plugins/plugin_utils/__init__.py | 88 | ||||
| -rw-r--r-- | BOT.py | 11 | ||||
| -rw-r--r-- | README.md | 62 | ||||
| -rw-r--r-- | utils/utils_banList/__init__.py | 45 | ||||
| -rw-r--r-- | utils/utils_error/__init__.py | 15 | ||||
| -rw-r--r-- | utils/utils_history/__init__.py | 11 | ||||
| -rw-r--r-- | utils/utils_img/__init__.py | 93 | ||||
| -rw-r--r-- | utils/utils_request/__init__.py | 11 | ||||
| -rw-r--r-- | utils/utils_switch/__init__.py | 17 | ||||
| -rw-r--r-- | utils/utils_switch/switch.json | 2 | 
22 files changed, 778 insertions, 109 deletions
diff --git a/ATRI/__init__.py b/ATRI/__init__.py index 4fe81ba..fd5b8f6 100644 --- a/ATRI/__init__.py +++ b/ATRI/__init__.py @@ -1,5 +1,14 @@  #!/usr/bin/env python3 -# -*- coding: utf-8 -*- +# -*- encoding: utf-8 -*- +''' +@File    :   __init__.py +@Time    :   2020/10/11 14:42:47 +@Author  :   Kyomotoi +@Contact :   kyomotoiowo@gmail.com +@Github  :   https://github.com/Kyomotoi +@License :   Copyright © 2018-2020 Kyomotoi, All Rights Reserved. +''' +__author__ = 'kyomotoi'  import json  from pathlib import Path diff --git a/ATRI/data/data_IDcard/main.bin b/ATRI/data/data_IDcard/main.bin Binary files differnew file mode 100644 index 0000000..6e74a60 --- /dev/null +++ b/ATRI/data/data_IDcard/main.bin diff --git a/ATRI/plugins/plugin_admin/__init__.py b/ATRI/plugins/plugin_admin/__init__.py index 3a7175c..3a3c259 100644 --- a/ATRI/plugins/plugin_admin/__init__.py +++ b/ATRI/plugins/plugin_admin/__init__.py @@ -1,5 +1,14 @@  #!/usr/bin/env python3 -# -*- coding: utf-8 -*- +# -*- encoding: utf-8 -*- +''' +@File    :   __init__.py +@Time    :   2020/10/11 14:37:53 +@Author  :   Kyomotoi +@Contact :   kyomotoiowo@gmail.com +@Github  :   https://github.com/Kyomotoi +@License :   Copyright © 2018-2020 Kyomotoi, All Rights Reserved. +''' +__author__ = 'kyomotoi'  import re @@ -36,14 +45,15 @@ async def _(bot: Bot, event: Event, state: dict) -> None:              msg0 += "└Service:\n"              msg0 += "    ├anime-setu\n"              msg0 += "    ├anime-pic-search\n" -            msg0 += "    └anime-vid-search\n" +            msg0 += "    ├anime-vid-search\n" +            msg0 += "    ├ai-face\n" +            msg0 += "    ├pixiv-pic-search\n" +            msg0 += "    ├pixiv-author-search\n" +            msg0 += "    └pixiv-rank"              await switch.finish(msg0)          funct = re.findall(r"[on|off]-(.*)", func) -        print(func, funct) - -        print(type(master[0]), type(user))          if "all-on" in func:              if int(user) in master: diff --git a/ATRI/plugins/plugin_anime/__init__.py b/ATRI/plugins/plugin_anime/__init__.py index 7abf59d..c15fc14 100644 --- a/ATRI/plugins/plugin_anime/__init__.py +++ b/ATRI/plugins/plugin_anime/__init__.py @@ -1,5 +1,14 @@  #!/usr/bin/env python3 -# -*- coding: utf-8 -*- +# -*- encoding: utf-8 -*- +''' +@File    :   __init__.py +@Time    :   2020/10/11 14:38:14 +@Author  :   Kyomotoi +@Contact :   kyomotoiowo@gmail.com +@Github  :   https://github.com/Kyomotoi +@License :   Copyright © 2018-2020 Kyomotoi, All Rights Reserved. +''' +__author__ = 'kyomotoi'  import re  import json @@ -8,8 +17,9 @@ from pathlib import Path  from random import randint  from nonebot.log import logger -from nonebot.adapters.cqhttp import Bot, Event +from nonebot import scheduler  from nonebot.permission import SUPERUSER +from nonebot.adapters.cqhttp import Bot, Event  from nonebot.plugin import on_message, on_command, on_regex  from utils.utils_banList import banList @@ -17,6 +27,7 @@ from utils.utils_error import errorRepo  from utils.utils_history import getMessage  from utils.utils_switch import checkSwitch  from utils.utils_request import aio_get_bytes, request_get +from utils.utils_img import compress_image, aio_download_pics  from .body import resultRepo  import ATRI @@ -229,19 +240,13 @@ setu_type = 1  # setu-type: 1(local), 2(url: https://api.lolicon.app/#/setu) def  setu = on_regex(r"来[点丶张份副个幅][涩色瑟][图圖]|[涩色瑟][图圖]来|[涩色瑟][图圖][gkd|GKD|搞快点]|[gkd|GKD|搞快点][涩色瑟][图圖]")  @setu.handle() # type: ignore -async def _(bot: Bot, event: Event, state: dict) -> None: +async def _setu(bot: Bot, event: Event, state: dict) -> None:      user = str(event.user_id)      group = str(event.group_id)      if banList(user, group):          if checkSwitch(plugin_name_2, group): -            await bot.send_msg( -                user_id=int(user), -                group_id=int(group), -                message="别急!正在找图!" -            ) -              res = randint(1,5)              if setu_type == 1: @@ -258,8 +263,8 @@ async def _(bot: Bot, event: Event, state: dict) -> None:                      msg0 = f"setu info:\n"                      msg0 += f"Title: {title}\n"                      msg0 += f"Pid: {pid}\n" -                    msg0 += f"{img}" - +                    msg0 += f"[CQ:image,file=file:///{compress_image(await aio_download_pics(img))}]" +                                          if 1 <= res < 5:                          await setu.finish(msg0) @@ -270,9 +275,9 @@ async def _(bot: Bot, event: Event, state: dict) -> None:                              message="我找到涩图了!但我发给主人了\nο(=•ω<=)ρ⌒☆"                          ) -                        await bot.send_msg( +                        await bot.send_private_msg(                              user_id=ATRI.config_SUPERUSERS, -                            message=f"主人,从群{group}来的涩图!热乎着!\nTitle: {title}\nPid: {pid}\n{img}" +                            message=f"主人,从群{group}来的涩图!热乎着!\nTitle: {title}\nPid: {pid}\n[CQ:image,file=file:///{compress_image(await aio_download_pics(img))}]"                          )              else: @@ -282,18 +287,33 @@ async def _(bot: Bot, event: Event, state: dict) -> None:                      "num": "1"                  } +                data = {} +                  try:                      data = json.loads(request_get('https://api.lolicon.app/setu/', params))                  except Exception:                      await setu.finish(errorRepo("请求数据失败,也可能为接口调用次数达上限")) -                msg0 = f"setu info:" -                msg0 += f'Title: {data["data"][0]["title"]}' # type: ignore -                msg0 += f'Pid: {data["data"][0]["pid"]}' # type: ignore -                msg0 += f'{data["data"][0]["url"]}' # type: ignore +                msg0 = f"setu info:\n" +                msg0 += f'Title: {data["data"][0]["title"]}\n' +                msg0 += f'Pid: {data["data"][0]["pid"]}\n' +                msg0 += f'[CQ:image,file=file:///{compress_image(await aio_download_pics(data["data"][0]["url"]))}]' -                await setu.finish(msg0) -         +                if 1 <= res < 5: +                    await setu.finish(msg0) +                 +                elif res == 5: +                    await bot.send_msg( +                        user_id=int(user), +                        group_id=int(group), +                        message="我找到涩图了!但我发给主人了\nο(=•ω<=)ρ⌒☆" +                    ) + +                    await bot.send_private_msg( +                        user_id=ATRI.config_SUPERUSERS, +                        message=f'主人,从群{group}来的涩图!热乎着!\nTitle: {data["data"][0]["title"]}\nPid: {data["data"][0]["pid"]}\n[CQ:image,file=file:///{compress_image(await aio_download_pics(data["data"][0]["url"]))}]' +                    ) +                      else:              await setu.finish(f"Service-{plugin_name_2} has been closed.") @@ -326,3 +346,59 @@ async def _(bot: Bot, event: Event, state: dict) -> None:          await setuType.finish("请检查类型是否输入正确嗷!")      await setuType.finish("Type conversion completed!") + + +# @scheduler.scheduled_job( +#     "cron", +#     minute=45, +#     bot=Bot, +#     event=Event, +#     state=dict +#     ) +# async def _(bot: Bot, event: Event, state: dict) -> None: +#     group = str(event.group_id) + +#     if banList(group=group): +#         if checkSwitch(plugin_name_2, group): +#             # group_list = await bot.get_group_list() +#             # group = sample(group_list, 1) +#             # group = group['group_id'] + +#             if setu_type == 1: + +#                 con = sqlite3.connect(Path('.') / 'ATRI' / 'data' / 'data_Sqlite' / 'setu' / 'nearR18.db') +#                 cur = con.cursor() +#                 msg = cur.execute('SELECT * FROM nearR18 ORDER BY RANDOM() limit 1;') + +#                 for i in msg: +#                     pid = i[0] +#                     title = i[1] +#                     img = i[7] +                     +#                     msg0 = f"setu info:\n" +#                     msg0 += f"Title: {title}\n" +#                     msg0 += f"Pid: {pid}\n" +#                     msg0 += f"[CQ:image,file=file:///{compress_image(await aio_download_pics(img))}]" +                     +#                     await setu.finish(msg0) +             +#             else: +#                 params = { +#                     "apikey": key_LoliconAPI, +#                     "r18": "0", +#                     "num": "1" +#                 } + +#                 data = {} + +#                 try: +#                     data = json.loads(request_get('https://api.lolicon.app/setu/', params)) +#                 except Exception: +#                     await setu.finish(errorRepo("请求数据失败,也可能为接口调用次数达上限")) +                 +#                 msg0 = f"setu info:\n" +#                 msg0 += f'Title: {data["data"][0]["title"]}\n' +#                 msg0 += f'Pid: {data["data"][0]["pid"]}\n' +#                 msg0 += f'[CQ:image,file=file:///{compress_image(await aio_download_pics(data["data"][0]["url"]))}]' + +#                 await setu.finish(msg0) diff --git a/ATRI/plugins/plugin_anime/body.py b/ATRI/plugins/plugin_anime/body.py index 02c57bb..00ee4ec 100644 --- a/ATRI/plugins/plugin_anime/body.py +++ b/ATRI/plugins/plugin_anime/body.py @@ -1,5 +1,14 @@  #!/usr/bin/env python3 -# -*- coding: utf-8 -*- +# -*- encoding: utf-8 -*- +''' +@File    :   body.py +@Time    :   2020/10/11 14:38:23 +@Author  :   Kyomotoi +@Contact :   kyomotoiowo@gmail.com +@Github  :   https://github.com/Kyomotoi +@License :   Copyright © 2018-2020 Kyomotoi, All Rights Reserved. +''' +__author__ = 'kyomotoi'  import json diff --git a/ATRI/plugins/plugin_chat/__init__.py b/ATRI/plugins/plugin_chat/__init__.py index 6fd7099..fc2a6e2 100644 --- a/ATRI/plugins/plugin_chat/__init__.py +++ b/ATRI/plugins/plugin_chat/__init__.py @@ -1,13 +1,27 @@  #!/usr/bin/env python3 -# -*- coding: utf-8 -*- +# -*- encoding: utf-8 -*- +''' +@File    :   __init__.py +@Time    :   2020/10/11 14:38:38 +@Author  :   Kyomotoi +@Contact :   kyomotoiowo@gmail.com +@Github  :   https://github.com/Kyomotoi +@License :   Copyright © 2018-2020 Kyomotoi, All Rights Reserved. +''' +__author__ = 'kyomotoi' + +from random import choice  from nonebot.log import logger -from nonebot.plugin import on_message +from nonebot.rule import to_me  from nonebot.adapters.cqhttp import Bot, Event +from nonebot.plugin import on_command, on_message, on_notice +from utils.utils_banList import banList  from utils.utils_history import saveMessage +# 收集 bot 所在群的聊天记录  MessageSave = on_message()  @MessageSave.handle() # type: ignore @@ -22,4 +36,76 @@ async def _(bot: Bot, event: Event, state: dict) -> None:      else:          saveMessage(message_id, message, user, group) -    logger.opt(colors=True).info(f"[<yellow>{group}</yellow>]-U: (<blue>{user}</blue>) | Message: (<green>{message}</green>) Saved successfully")
\ No newline at end of file +    logger.opt(colors=True).info(f"[<yellow>{group}</yellow>]-U: (<blue>{user}</blue>) | Message: (<green>{message}</green>) Saved successfully") + + +# Call bot +callMe = on_message() + +@callMe.handle() # type: ignore +async def _(bot: Bot, event: Event, state: dict) -> None: +    user = str(event.user_id) +    group = str(event.group_id) + +    if banList(user, group): +        msg = str(event.message) + +        if "ATRI" == msg or "亚托莉" == msg or "アトリ" == msg: +            await callMe.finish("叫我有啥事吗w") +         +        elif "萝卜子" in msg: +            await bot.send(event, "萝卜子是对咱的蔑称!!") +         +        else: +            pass + + + +# 戳 一 戳 +pokehah = on_command("戳一戳", rule=to_me()) + +@pokehah.handle() # type: ignore +async def _poke(bot: Bot, event: Event, state: dict) -> None: +    user = str(event.user_id) +    group = str(event.group_id) + +    if banList(user, group): +        msg = choice( +                    [ +                        "你再戳!", +                        "?再戳试试?", +                        "别戳了别戳了再戳就坏了555", +                        "我爪巴爪巴,球球别再戳了", +                        "你戳你🐎呢?!", +                        "那...那里...那里不能戳...绝对...", +                        "(。´・ω・)ん?", +                        "有事恁叫我,别天天一个劲戳戳戳!", +                        "欸很烦欸!你戳🔨呢", +                        "?" +                    ]) + +        await pokehah.finish(msg) + + +async def poke_(bot: Bot, event: Event, state: dict) -> bool: +    return (event.detail_type == "notify" and event.raw_event["sub_type"] == "poke" and +            event.sub_type == "notice" and int(event.self_id) == event.raw_event["target_id"]) + +poke = on_notice(poke_, block=True) +poke.handle()(_poke) + + +groupEvent = on_notice() + +@groupEvent.handle() # type: ignore +async def _(bot: Bot, event: Event, state: dict) -> None: +    group = str(event.group_id) +    print(event.raw_event) + +    if banList(group): +        if event.raw_event["notice_type"] == "group_increase": +            await groupEvent.finish(f'好欸!事新人[CQ:at,qq={event.raw_event["user_id"]}]') +            await groupEvent.finish(f"在下 ATRI,你可以叫我 亚托莉 或 アトリ !~w") + +        elif event.raw_event["notice_type"] == "group_decrease": +            await groupEvent.finish(f'[{event.raw_event["operator_id"]}] 离开了我们...') diff --git a/ATRI/plugins/plugin_pixiv/__init__.py b/ATRI/plugins/plugin_pixiv/__init__.py new file mode 100644 index 0000000..5826b49 --- /dev/null +++ b/ATRI/plugins/plugin_pixiv/__init__.py @@ -0,0 +1,203 @@ +#!/usr/bin/env python3 +# -*- encoding: utf-8 -*- +''' +@File    :   __init__.py +@Time    :   2020/10/11 14:38:49 +@Author  :   Kyomotoi +@Contact :   kyomotoiowo@gmail.com +@Github  :   https://github.com/Kyomotoi +@License :   Copyright © 2018-2020 Kyomotoi, All Rights Reserved. +''' +__author__ = 'kyomotoi' + +import re +import json + +from nonebot.plugin import on_command +from nonebot.adapters.cqhttp import Bot, Event + +from utils.utils_error import errorRepo +from utils.utils_banList import banList +from utils.utils_switch import checkSwitch +from utils.utils_request import request_get + + +plugin_name_0 = "pixiv-pic-search" +pixivSearchIMG = on_command('p站搜图') + +@pixivSearchIMG.handle() # type: ignore +async def _(bot: Bot, event: Event, state: dict) -> None: +    user = str(event.user_id) +    group = str(event.group_id) + +    state["user"] = user +    state["group"] = group + +    if banList(user, group): +        if checkSwitch(plugin_name_0, group): +            pid = str(event.message).strip() + +            if pid: +                state["pid"] = pid +        else: +            await pixivSearchIMG.finish(f"Service-{plugin_name_0} has been closed.") + +@pixivSearchIMG.got("pid", prompt="请发送目标PID码") # type: ignore +async def _(bot: Bot, event: Event, state: dict) -> None: +    pid = state["pid"] +    pid = re.findall(r"\d+", pid) + +    if len(pid): +        pass +    else: +        await pixivSearchIMG.reject("请发送纯阿拉伯数字的pid") + +    await bot.send_msg( +        user_id=state["user"], +        group_id=state["group"], +        message="别急!在搜索了!" +    ) + +    URL = f"https://api.imjad.cn/pixiv/v1/?type=illust&id={pid}" +    data = {} + +    try: +        data = json.loads(request_get(URL)) +    except: +        await pixivSearchIMG.finish(errorRepo("请求数据失败")) +     +    msg0 = f'[CQ:at,qq={state["user"]}]\n' +    msg0 += f"Search result:\n" +    msg0 += f"Pid: {pid}\n" +    msg0 += f'Title {data["response"][0]["title"]}\n' +    msg0 += f'W&H: {data["response"][0]["width"]}x{data["response"][0]["height"]}\n' +    msg0 += f'Tags: {data["response"][0]["tags"]}\n' +    msg0 += f'Account Name: {data["response"][0]["user"]["account"]}\n' +    msg0 += f'Author Name: {data["response"][0]["user"]["name"]}\n' +    msg0 += f'Link: https://www.pixiv.net/users/{data["response"][0]["user"]["id"]}\n' +    msg0 += f'IMG: https://pixiv.cat/{pid}.jpg' + +    await pixivSearchIMG.finish(msg0) + + +plugin_name_1 = "pixiv-author-search" +pixivSearchAuthor = on_command("p站画师") + +@pixivSearchAuthor.handle() # type: ignore +async def _(bot: Bot, event: Event, state: dict) -> None: +    user = str(event.user_id) +    group = str(event.group_id) + +    state["user"] = user +    state["group"] = group + +    if banList(user, group): +        if checkSwitch(plugin_name_1, group): +            author_id = str(event.message).strip() + +            if author_id: +                state["author_id"] = author_id +        else: +            await pixivSearchAuthor.finish(f"Service-{plugin_name_1} has been closed.") + +@pixivSearchAuthor.got("author_id", prompt="请发送目标画师id") # type: ignore +async def _(bot: Bot, event: Event, state: dict) -> None: +    author_id = state["author_id"] +    author_id = re.findall(r"\d+", author_id) + +    if len(author_id): +        pass +    else: +        await pixivSearchAuthor.reject("请发送纯阿拉伯数字的画师id") +     +    await bot.send_msg( +        user_id=state["user"], +        group_id=state["group"], +        message=f"别急!在搜索了!\n将展示画师[{author_id}]的前三项作品" +    ) + +    URL = f"https://api.imjad.cn/pixiv/v1/?type=member_illust&id={author_id}" +    data = {} + +    try: +        data = json.loads(request_get(URL)) +    except: +        await pixivSearchAuthor.finish(errorRepo("请求网络失败")) + +    for i in range(0,3): +        pid = data["response"][i]["id"] +        IMG = f"https://pixiv.cat/{author_id}.jpg" +        data[i] = [f"{pid}", f"{IMG}"] +     +    msg0 = f'[CQ:at,qq={state["user"]}]\n' +     +    result = sorted( +        data.items(), +        key=lambda x:x[1], +        reverse=True +    ) + +    t = 0 + +    for i in result: +        t += 1 +        msg = f"\n---------------\n" +        msg += f"({t})\n" +        msg += f"Pid: {i[1][0]}\n{i[1][1]}" +        msg0 += msg +     +    await pixivSearchAuthor.finish(msg0) + + +plugin_name_2 = "pixiv_rank" +pixivRank = on_command("p站排行榜") + +@pixivRank.handle() # type: ignore +async def _(bot: Bot, event: Event, state: dict) -> None: +    user = str(event.user_id) +    group = str(event.group_id) + +    if banList(user, group): +        if checkSwitch(plugin_name_2, group): + +            await bot.send_msg( +                user_id=int(user), +                group_id=int(group), +                message="正在获取P站每日排行榜前五作品" +            ) + +            URL = "https://api.imjad.cn/pixiv/v1/?type=rank" +            data = {} + +            try: +                data = json.loads(request_get(URL)) +            except: +                await pixivRank.finish(errorRepo("网络请求失败")) +             +            for i in range(0,5): +                pid = data["response"][0]["works"][i]["work"]["id"] +                IMG = f"https://pixiv.cat/{pid}.jpg" +                data[i] = [f"{pid}", f"{IMG}"] +             +            msg0 = f"[CQ:at,qq={user}]" + +            result = sorted( +                data.items(), +                key=lambda x:x[1], +                reverse=True +            ) + +            t = 0 + +            for i in result: +                t += 1 +                msg = "\n---------------\n" +                msg += f"({t})\n" +                msg += f"Pid: {i[1][0]}" +                msg += f"{i[1][1]}" +                msg0 += msg +             +            await pixivRank.finish(msg0) +         +        else: +            await pixivRank.finish(f"Service-{plugin_name_2} has been closed.")
\ No newline at end of file diff --git a/ATRI/plugins/plugin_rich/__init__.py b/ATRI/plugins/plugin_rich/__init__.py index 2639188..99026a8 100644 --- a/ATRI/plugins/plugin_rich/__init__.py +++ b/ATRI/plugins/plugin_rich/__init__.py @@ -1,10 +1,18 @@  #!/usr/bin/env python3 -# -*- coding: utf-8 -*- +# -*- encoding: utf-8 -*- +''' +@File    :   __init__.py +@Time    :   2020/10/11 14:40:34 +@Author  :   Kyomotoi +@Contact :   kyomotoiowo@gmail.com +@Github  :   https://github.com/Kyomotoi +@License :   Copyright © 2018-2020 Kyomotoi, All Rights Reserved. +''' +__author__ = 'kyomotoi'  import re  import json  import requests -from datetime import datetime  from nonebot.log import logger  from nonebot.plugin import on_message diff --git a/ATRI/plugins/plugin_rich/body.py b/ATRI/plugins/plugin_rich/body.py index 2c743c0..ae3d99b 100644 --- a/ATRI/plugins/plugin_rich/body.py +++ b/ATRI/plugins/plugin_rich/body.py @@ -1,5 +1,14 @@  #!/usr/bin/env python3 -# -*- coding: utf-8 -*- +# -*- encoding: utf-8 -*- +''' +@File    :   body.py +@Time    :   2020/10/11 14:40:43 +@Author  :   Kyomotoi +@Contact :   kyomotoiowo@gmail.com +@Github  :   https://github.com/Kyomotoi +@License :   Copyright © 2018-2020 Kyomotoi, All Rights Reserved. +''' +__author__ = 'kyomotoi'  table='fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF'  tr={} diff --git a/ATRI/plugins/plugin_status/__init__.py b/ATRI/plugins/plugin_status/__init__.py index ddd9e60..d51e2e9 100644 --- a/ATRI/plugins/plugin_status/__init__.py +++ b/ATRI/plugins/plugin_status/__init__.py @@ -1,5 +1,14 @@  #!/usr/bin/env python3 -# -*- coding: utf-8 -*- +# -*- encoding: utf-8 -*- +''' +@File    :   __init__.py +@Time    :   2020/10/11 14:40:55 +@Author  :   Kyomotoi +@Contact :   kyomotoiowo@gmail.com +@Github  :   https://github.com/Kyomotoi +@License :   Copyright © 2018-2020 Kyomotoi, All Rights Reserved. +''' +__author__ = 'kyomotoi'  import psutil  import sqlite3 diff --git a/ATRI/plugins/plugin_test/__init__.py b/ATRI/plugins/plugin_test/__init__.py new file mode 100644 index 0000000..5a6fe96 --- /dev/null +++ b/ATRI/plugins/plugin_test/__init__.py @@ -0,0 +1,47 @@ +# !/usr/bin/env python3 +# -*- encoding: utf-8 -*- +''' +@File    :   __init__.py +@Time    :   2020/10/11 14:35:26 +@Author  :   Kyomotoi +@Contact :   kyomotoiowo@gmail.com +@Github  :   https://github.com/Kyomotoi +@License :   Copyright © 2018-2020 Kyomotoi, All Rights Reserved. +@Desc    :   None +''' +__author__ = 'kyomotoi' + +import os +from pathlib import Path +from random import sample + +import nonebot +from nonebot.plugin import on_command +from nonebot.permission import SUPERUSER +from nonebot.adapters.cqhttp import Bot, Event + + +# 此目录下均为功能测试! + + +testRecord = on_command('测试语音', permission=SUPERUSER) + +@testRecord.handle() # type: ignore +async def _(bot: Bot, event: Event, state: dict) -> None: +    await testRecord.finish(f"[CQ:record,file=file:///{os.path.abspath(Path('.') / 'ATRI' / 'plugins' / 'plugin_test' / 'test.mp3')}]") + + +testGroupList = on_command('获取群列表', permission=SUPERUSER) + +@testGroupList.handle() # type: ignore +async def _(bot: Bot, event: Event, state: dict) -> None: +    group_list = await bot.get_group_list() +    group = sample(group_list, 1) +    print(group[0]['group_id'], type(group[0]['group_id'])) + +testBot = on_command('获取bot', permission=SUPERUSER) + +@testBot.handle() # type: ignore +async def _(bot: Bot, event: Event, state: dict) -> None: +    test_bot = nonebot.get_bots() +    print(test_bot, type(test_bot.keys()))
\ No newline at end of file diff --git a/ATRI/plugins/plugin_test/test.mp3 b/ATRI/plugins/plugin_test/test.mp3 Binary files differnew file mode 100644 index 0000000..774cf5d --- /dev/null +++ b/ATRI/plugins/plugin_test/test.mp3 diff --git a/ATRI/plugins/plugin_utils/__init__.py b/ATRI/plugins/plugin_utils/__init__.py new file mode 100644 index 0000000..54abdeb --- /dev/null +++ b/ATRI/plugins/plugin_utils/__init__.py @@ -0,0 +1,88 @@ +#!/usr/bin/env python3 +# -*- encoding: utf-8 -*- +''' +@File    :   __init__.py +@Time    :   2020/10/17 21:16:59 +@Author  :   Kyomotoi +@Contact :   kyomotoiowo@gmail.com +@Github  :   https://github.com/Kyomotoi +@License :   Copyright © 2018-2020 Kyomotoi, All Rights Reserved. +@Docs    :   Thanks for mnixry idea! fork from https://github.com/mnixry/coolQPythonBot +''' +__author__ = 'kyomotoi' + +import os +import json +import random +from pathlib import Path +from time import strftime +from zipfile import PyZipFile +from typing import Tuple, Dict, List +from datetime import datetime, timedelta + +from nonebot.plugin import on_command +from nonebot.adapters.cqhttp import Bot, Event + +from utils.utils_banList import banList + + +file = Path('.') / 'ATRI' / 'data' / 'data_IDcard' / 'main.bin' + +def infoID() -> Tuple[Dict[str, List[str]], Dict[str, str]]: +    with PyZipFile(os.path.abspath(file), "r") as zipFile: +        with zipFile.open("name.json", "r") as f: +            name = json.loads(f.read().decode()) +        with zipFile.open("area.json", "r") as f: +            area = json.loads(f.read().decode()) +    return name, area + +NAME, AREA = infoID() + +BIRTH_BEGIN = datetime(*[1980, 10, 10]) # type: ignore +BIRTH_END = datetime(*[2002, 10, 10]) # type: ignore + +def numberID(area: int, sex: int, birth: int) -> str: +    def checkSum(fullCode: str) -> int or str: +        assert len(fullCode) == 17 +        checkSum = sum( +            [((1 << (17 - i)) % 11) * int(fullCode[i]) for i in range(0, 17)] +        ) +        checkDigit = (12 - (checkSum % 11)) % 11 +        if checkDigit < 10: +            return checkDigit +        else: +            return "X" +     +    orderCode = str(random.randint(10, 99)) +    sexCode = str(random.randrange(sex, 10, step=2)) +    fullCode = str(area) + str(birth) + str(orderCode) + str(sexCode) +    fullCode += str(checkSum(fullCode)) +    return fullCode + + +plugin_name = "one-key-adult" +generateID = on_command("我要转大人,一天打25小时游戏") + +@generateID.handle() # type: ignore +async def _(bot: Bot, event: Event, state: dict) -> None: +    user = str(event.user_id) +    group = str(event.group_id) + +    if banList(user, group): +        id_card_area = int(random.choice(list(AREA.keys()))) +        id_card_area_name = AREA[str(id_card_area)] +        id_card_year_old = timedelta(days=random.randint(0, (BIRTH_END - BIRTH_BEGIN).days) + 1) +        id_card_birth_day = strftime("%Y%m%d", (BIRTH_BEGIN + id_card_year_old).timetuple()) +        id_card_sex = random.choice([0, 1]) +        id_card_name = random.choice(NAME[{0: "female", 1: "male"}[id_card_sex]]) +        id_card_id = numberID(id_card_area, id_card_sex, id_card_birth_day) + +        msg0 = "恭喜,你已经成大人了!\n" +        msg0 += "这是你一天25h游戏的通行证:\n" +        msg0 += f"NumberID: {id_card_id}\n" +        msg0 += f"Sex: {'男' if id_card_sex == 1 else '女'}\n" +        msg0 += f"Name: {id_card_name} || Address: {id_card_area_name}\n" +        msg0 += "注: 1、以上信息根据国家公开标准生成,非真实信息。\n" +        msg0 += "     2、不适用于网易和腾讯。" + +        await generateID.finish(msg0) @@ -1,5 +1,14 @@  #!/usr/bin/env python3 -# -*- coding: utf-8 -*- +# -*- encoding: utf-8 -*- +''' +@File    :   bot.py +@Time    :   2020/10/11 14:36:01 +@Author  :   Kyomotoi +@Contact :   kyomotoiowo@gmail.com +@Github  :   https://github.com/Kyomotoi +@License :   Copyright © 2018-2020 Kyomotoi, All Rights Reserved. +''' +__author__ = 'kyomotoi'  import time  COPYRIGHT = ( @@ -1,59 +1,7 @@ -**This project in rebuild now** +# ATRI -# ATRI————A project of pleasure -アトリは、高性能ですから! +## How to start -[CN](README_CN.md) - -[](https://wakatime.com/badge/github/Kyomotoi/ATRI) -[](https://www.codacy.com/manual/Kyomotoi/ATRI?utm_source=github.com&utm_medium=referral&utm_content=Kyomotoi/ATRI&utm_campaign=Badge_Grade) -## ABOUT -This project name and inspiration from [ATRI-My Dear Moments-](https://atri-mdm.com/) by [ANIPLEX](https://aniplex-exe.com/). - -For Tencent QQ group add a lively ATRI is the goal of this project. - -The project leader, learn Python is still less than half a year, so i think the code of this project may increase your blood pressure. But i'll do it better! - -This project also serves as a good channel for me to learn Python. Thanks [Richard Chien](https://github.com/richardchien) and the Python-SDK: [NoneBot](https://github.com/nonebot/nonebot), them provided great help to this project. - -## ACHIEVE -アトリ can run on all platforms. - -This project is completed by `go-CQHTTP + NoneBot` with `Python` as the main language. - -**The framework of the previous version is CoolQ, here to commemorate the suspension of CoolQ** - -**May we meet in a more open parallel world** - -## MORE INTRODUCTION -This project is now formal edition, but the code is a entire hunk of shit. - -If you want to experience, you can join my Tencent QQ group: 567297659 - -- Any more about functions: [THE DOOR](https://blog.lolihub.icu/#/ATRI/user) - -- Any more about install: [THE DOOR](https://blog.lolihub.icu/#/ATRI/install) - -AND - -~~If this project reach 100 stars and 30 forks, i'll put on skirt and show the photo on my blog~~ - -## THANKS -[Richard Chien](https://github.com/richardchien): [CQHTTP](https://github.com/richardchien/coolq-http-api) and [NoneBot](https://github.com/nonebot/nonebot). - -[mnixry](https://github.com/mnixry): Give advice. - -[JetBrains](https://www.jetbrains.com/) provides [PyCharm](https://www.jetbrains.com/pycharm/) authorization for this project. - -And them: - - 50861735 11CNY - - 1072324725 17CNY - - 2862890179 func - - AfdianUser_quGy 5CNY - - 1752179928 45.14CNY - -## OTHER -This project has been activated by [Afdian](https://afdian.net/@Kyomotoi), welcome to sponsor. - -## ABOUT OPEN SOURCE -[GPLv3](https://github.com/Kyomotoi/Aya/blob/master/LICENSE) +1. generate project using `nb create` . +2. writing your plugins under `atri/plugins` folder. +3. run your bot using `nb run` . diff --git a/utils/utils_banList/__init__.py b/utils/utils_banList/__init__.py index 66142cc..e7ccbec 100644 --- a/utils/utils_banList/__init__.py +++ b/utils/utils_banList/__init__.py @@ -1,11 +1,20 @@  #!/usr/bin/env python3 -# -*- coding: utf-8 -*- +# -*- encoding: utf-8 -*- +''' +@File    :   __init__.py +@Time    :   2020/10/11 14:42:59 +@Author  :   Kyomotoi +@Contact :   kyomotoiowo@gmail.com +@Github  :   https://github.com/Kyomotoi +@License :   Copyright © 2018-2020 Kyomotoi, All Rights Reserved. +''' +__author__ = 'kyomotoi'  import json  from pathlib import Path  from typing import Optional -def banList(user: str, group: Optional[str] = None) -> bool: +def banList(user: Optional[str] = None, group: Optional[str] = None) -> bool:      """      :说明: @@ -13,8 +22,9 @@ def banList(user: str, group: Optional[str] = None) -> bool:      :参数: -      * ``user: str``: 用户QQ号 -      * ``group: Optional[str] = None``: 用户所在群号,若不传入则只检测用户 +      * ``user: Optional[str] = None``: 用户QQ号 +      * ``group: Optional[str] = None``: 用户所在群号 +      * !!!二者必须传入一个,否则一律返回 False !!!      :返回: @@ -42,14 +52,29 @@ def banList(user: str, group: Optional[str] = None) -> bool:      except:          data_group = {} -    if user not in data_user: -        if group: -            if group not in data_group: +    if user: +        if user not in data_user: +            if group: +                if group not in data_group: +                    return True +                else: +                    return False +            else:                  return True +        else: +            return False + +    elif group: +        if group not in data_group: +            if user: +                if user not in data_user: +                    return True +                else: +                    return False              else: -                return False +                return True          else: -            return True +            return False +      else: -        print(3)          return False
\ No newline at end of file diff --git a/utils/utils_error/__init__.py b/utils/utils_error/__init__.py index e037b30..2674018 100644 --- a/utils/utils_error/__init__.py +++ b/utils/utils_error/__init__.py @@ -1,5 +1,14 @@  #!/usr/bin/env python3 -# -*- coding: utf-8 -*- +# -*- encoding: utf-8 -*- +''' +@File    :   __init__.py +@Time    :   2020/10/11 14:43:10 +@Author  :   Kyomotoi +@Contact :   kyomotoiowo@gmail.com +@Github  :   https://github.com/Kyomotoi +@License :   Copyright © 2018-2020 Kyomotoi, All Rights Reserved. +''' +__author__ = 'kyomotoi'  import json  import string @@ -9,8 +18,6 @@ from typing import Optional  from datetime import datetime  from traceback import format_exc -from nonebot.rule import keyword -  def errorRepo(repo_msg: Optional[str] = None) -> str:      """      :说明: @@ -23,7 +30,7 @@ def errorRepo(repo_msg: Optional[str] = None) -> str:      :返回: -      错误信息 +      错误堆栈      :用法: diff --git a/utils/utils_history/__init__.py b/utils/utils_history/__init__.py index d6a6d33..74834d8 100644 --- a/utils/utils_history/__init__.py +++ b/utils/utils_history/__init__.py @@ -1,5 +1,14 @@  #!/usr/bin/env python3 -# -*- coding: utf-8 -*- +# -*- encoding: utf-8 -*- +''' +@File    :   __init__.py +@Time    :   2020/10/11 14:43:20 +@Author  :   Kyomotoi +@Contact :   kyomotoiowo@gmail.com +@Github  :   https://github.com/Kyomotoi +@License :   Copyright © 2018-2020 Kyomotoi, All Rights Reserved. +''' +__author__ = 'kyomotoi'  import os  import json diff --git a/utils/utils_img/__init__.py b/utils/utils_img/__init__.py new file mode 100644 index 0000000..1b8c767 --- /dev/null +++ b/utils/utils_img/__init__.py @@ -0,0 +1,93 @@ +#!/usr/bin/env python3 +# -*- encoding: utf-8 -*- +''' +@File    :   __init__.py +@Time    :   2020/10/11 14:40:17 +@Author  :   Kyomotoi +@Contact :   kyomotoiowo@gmail.com +@Github  :   https://github.com/Kyomotoi +@License :   Copyright © 2018-2020 Kyomotoi, All Rights Reserved. +''' +__author__ = 'kyomotoi' + +import os +import string +import aiohttp +import PIL.Image as Image +from pathlib import Path +from random import sample + +from PIL import Image +from PIL import ImageFile + +async def aio_download_pics(url): +    """ +    :说明: +     +      下载图片并重名文件 +     +    :参数: + +      * ``URL: str``: 目标网址 +     +    :返回: + +      文件根目录 +     +    :用法: + +    .. code-block:: python + +        aio_download_pics(URL="https://www.demo.com/demo.jpg") + +    """ +    path = Path('.') / 'ATRI' / 'data' / 'data_Temp' / 'img' +    path = os.path.abspath(path) +    img_key = ''.join(sample(string.ascii_letters + string.digits, 16)) +    img = path + f'\\{img_key}.png' +    async with aiohttp.ClientSession() as session:          +        async with session.get(url) as response:                 +            pic = await response.read()    #以Bytes方式读入非文字                      +            with open(img, mode='wb') as f:# 写入文件 +                f.write(pic) +                f.close() +    return img + +def compress_image(outfile: str, kb=400, quality=85, k=0.9) -> str: +    """ +    :说明: +     +      不改变图片尺寸压缩到指定大小,输出 base64 ,完成后自动删除文件 +     +    :参数: + +      * ``outfile: str``: 文件目录 +      * ``kb=150``: 目标文件大小,单位:KB + +    :返回: + +      base64 + +    :用法: + +    .. code-block:: python + +        compress_image(outfile=C:/xxx) + +    """ +    o_size = os.path.getsize(outfile) // 1024 +    if o_size <= kb: +        return outfile +    +    ImageFile.LOAD_TRUNCATED_IMAGES = True # type: ignore +    while o_size > kb: +        im = Image.open(outfile) +        x, y = im.size +        out = im.resize((int(x*k), int(y*k)), Image.ANTIALIAS) +        try: +            out.save(outfile, quality=quality) +        except Exception as e: +            print(e) +            break +        o_size = os.path.getsize(outfile) // 1024 +    return outfile diff --git a/utils/utils_request/__init__.py b/utils/utils_request/__init__.py index cc0992a..b32f372 100644 --- a/utils/utils_request/__init__.py +++ b/utils/utils_request/__init__.py @@ -1,5 +1,14 @@  #!/usr/bin/env python3 -# -*- coding: utf-8 -*- +# -*- encoding: utf-8 -*- +''' +@File    :   __init__.py +@Time    :   2020/10/11 14:43:55 +@Author  :   Kyomotoi +@Contact :   kyomotoiowo@gmail.com +@Github  :   https://github.com/Kyomotoi +@License :   Copyright © 2018-2020 Kyomotoi, All Rights Reserved. +''' +__author__ = 'kyomotoi'  import requests  from typing import Optional diff --git a/utils/utils_switch/__init__.py b/utils/utils_switch/__init__.py index 5c10a85..df7b877 100644 --- a/utils/utils_switch/__init__.py +++ b/utils/utils_switch/__init__.py @@ -1,5 +1,14 @@  #!/usr/bin/env python3 -# -*- coding: utf-8 -*- +# -*- encoding: utf-8 -*- +''' +@File    :   __init__.py +@Time    :   2020/10/11 14:44:06 +@Author  :   Kyomotoi +@Contact :   kyomotoiowo@gmail.com +@Github  :   https://github.com/Kyomotoi +@License :   Copyright © 2018-2020 Kyomotoi, All Rights Reserved. +''' +__author__ = 'kyomotoi'  import os  import json @@ -40,6 +49,9 @@ def checkSwitch(func_name: str, group: str) -> bool:          data_switch_all["anime-pic-search"] = "True"          data_switch_all["anime-vid-search"] = "True"          data_switch_all["ai-face"] = "True" +        data_switch_all["pixiv-pic-search"] = "True" +        data_switch_all["pixiv-author-search"] = "True" +        data_switch_all["pixiv-rank"] = "True"          with open(file_switch_all, 'w') as f:              f.write(json.dumps(data_switch_all)) @@ -59,6 +71,9 @@ def checkSwitch(func_name: str, group: str) -> bool:          data_switch_alone["anime-pic-search"] = "True"          data_switch_alone["anime-vid-search"] = "True"          data_switch_alone["ai-face"] = "True" +        data_switch_alone["pixiv-pic-search"] = "True" +        data_switch_alone["pixiv-author-search"] = "True" +        data_switch_alone["pixiv-rank"] = "True"          with open(file_switch_alone, 'w') as f:              f.write(json.dumps(data_switch_alone)) diff --git a/utils/utils_switch/switch.json b/utils/utils_switch/switch.json index 9b6bb22..9fb8cfa 100644 --- a/utils/utils_switch/switch.json +++ b/utils/utils_switch/switch.json @@ -1 +1 @@ -{"anime-setu": "True", "anime-pic-search": "True", "anime-vid-search": "True", "all-off-anime-setu": "True"}
\ No newline at end of file +{"anime-setu": "True", "anime-pic-search": "True", "anime-vid-search": "True", "all-off-anime-setu": "True", "ai-face": "True", "pixiv-pic-search": "True", "pixiv-author-search": "True", "pixiv-rank": "True"}
\ No newline at end of file  | 
