diff options
| author | Kyomotoi <1172294279@qq.com> | 2021-03-14 16:22:34 +0800 | 
|---|---|---|
| committer | Kyomotoi <1172294279@qq.com> | 2021-03-14 16:22:34 +0800 | 
| commit | 64a991e035e52e0a17e73d4e671a22ea9a7489da (patch) | |
| tree | 8952d23a3d0f165d363e134ff7c64dbf05a670d3 /ATRI/plugins | |
| parent | da888ff020805a38a17e5f83705aeb42ffa992ba (diff) | |
| download | ATRI-64a991e035e52e0a17e73d4e671a22ea9a7489da.tar.gz ATRI-64a991e035e52e0a17e73d4e671a22ea9a7489da.tar.bz2 ATRI-64a991e035e52e0a17e73d4e671a22ea9a7489da.zip | |
✨🐛 更新插件,修复一些bug
Diffstat (limited to 'ATRI/plugins')
| -rw-r--r-- | ATRI/plugins/admin.py | 59 | ||||
| -rw-r--r-- | ATRI/plugins/anime-search/__init__.py | 27 | ||||
| -rw-r--r-- | ATRI/plugins/anti-rubbish.py | 20 | ||||
| -rw-r--r-- | ATRI/plugins/call-owner.py | 32 | ||||
| -rw-r--r-- | ATRI/plugins/code-runner.py | 26 | ||||
| -rw-r--r-- | ATRI/plugins/curse/__init__.py | 27 | ||||
| -rw-r--r-- | ATRI/plugins/drifting-bottle/__init__.py | 18 | ||||
| -rw-r--r-- | ATRI/plugins/essential.py | 48 | ||||
| -rw-r--r-- | ATRI/plugins/funny.py | 32 | ||||
| -rw-r--r-- | ATRI/plugins/github.py | 24 | ||||
| -rw-r--r-- | ATRI/plugins/hitokoto.py | 28 | ||||
| -rw-r--r-- | ATRI/plugins/key-repo/__init__.py | 171 | ||||
| -rw-r--r-- | ATRI/plugins/rich/__init__.py | 26 | ||||
| -rw-r--r-- | ATRI/plugins/rich/data_source.py | 16 | ||||
| -rw-r--r-- | ATRI/plugins/status.py | 81 | ||||
| -rw-r--r-- | ATRI/plugins/utils/__init__.py | 43 | ||||
| -rw-r--r-- | ATRI/plugins/utils/data_source.py | 16 | 
17 files changed, 340 insertions, 354 deletions
| diff --git a/ATRI/plugins/admin.py b/ATRI/plugins/admin.py index 45acf4b..9465130 100644 --- a/ATRI/plugins/admin.py +++ b/ATRI/plugins/admin.py @@ -1,26 +1,10 @@ -#!/usr/bin/env python3 -# -*- coding:utf-8 -*- -''' -File: admin.py -Created Date: 2021-02-04 21:17:12 -Author: Kyomotoi -Email: Kyomotoiowo@gmail.com -License: GPLv3 -Project: https://github.com/Kyomotoi/ATRI --------- -Last Modified: Sunday, 7th March 2021 3:14:01 pm -Modified By: Kyomotoi (kyomotoiowo@gmail.com) --------- -Copyright (c) 2021 Kyomotoi -''' - +import os  import json  import time  from pathlib import Path  from datetime import datetime  from nonebot.permission import SUPERUSER -from nonebot.plugin import on_command, on_message, CommandGroup  from nonebot.adapters.cqhttp import (      Bot,      MessageEvent, @@ -28,7 +12,8 @@ from nonebot.adapters.cqhttp import (  )  from nonebot.typing import T_State -from ATRI.exceptions import WriteError, read_error +from ATRI.service import Service as sv +from ATRI.exceptions import WriteError, load_error  from ATRI.utils.file import open_file  from ATRI.log import (      logger, @@ -38,10 +23,11 @@ from ATRI.log import (  ADMIN_DIR = Path('.') / 'ATRI' / 'data' / 'database' / 'admin' +os.makedirs(ADMIN_DIR, exist_ok=True)  # 收集bot所在的群聊聊天记录 -chat_monitor = on_message() +chat_monitor = sv.on_message()  @chat_monitor.handle()  async def _chat_monitor(bot: Bot, event: GroupMessageEvent) -> None: @@ -96,8 +82,9 @@ async def _chat_monitor(bot: Bot, event: GroupMessageEvent) -> None:  ESSENTIAL_DIR = Path('.') / 'ATRI' / 'data' / 'database' / 'essential' -request_friend = on_command( -    "好友申请", +request_friend = sv.on_command( +    name="好友申请处理", +    cmd="好友申请",      permission=SUPERUSER  ) @@ -135,8 +122,9 @@ async def _request_friend(bot: Bot, event: MessageEvent) -> None:          await request_friend.finish("阿...请检查输入——!") -request_group = on_command( -    "群聊申请", +request_group = sv.on_command( +    name="群聊申请处理", +    cmd="群聊申请",      permission=SUPERUSER  ) @@ -184,8 +172,9 @@ async def _request_group(bot: Bot, event: MessageEvent) -> None:          await request_friend.finish("阿...请检查输入——!") -broadcast = on_command( -    "/broadcast", +broadcast = sv.on_command( +    name="广播", +    cmd="/broadcast",      permission=SUPERUSER  ) @@ -224,8 +213,9 @@ async def _bd(bot: Bot, event: MessageEvent, state: T_State) -> None:      await broadcast.finish(repo_msg) -track_error = on_command( -    "/track", +track_error = sv.on_command( +    name="错误堆栈查看", +    cmd="/track",      permission=SUPERUSER  ) @@ -241,7 +231,7 @@ async def _(bot: Bot, event: MessageEvent, state: T_State) -> None:      data = {}      try: -        data = read_error(track_id) +        data = load_error(track_id)      except:          await track_error.finish("Ignore track ID!") @@ -249,14 +239,15 @@ async def _(bot: Bot, event: MessageEvent, state: T_State) -> None:          f"ID: {track_id}\n"          f"Time: {data['time']}\n"          f"Prompt: {data['prompt']}\n" -        f"{data['error_content']}" +        f"{data['content']}"      )      await track_error.finish(msg0) -get_log = on_command( -    "/getlog", +get_log = sv.on_command( +    name="获取控制台信息", +    cmd="/getlog",      permission=SUPERUSER  ) @@ -290,7 +281,11 @@ async def _get_log(bot: Bot, event: MessageEvent) -> None:      await get_log.finish("\n".join(content).replace("[36mATRI[0m", "ATRI"))  # type: ignore -shutdown = on_command("/shutdown", permission=SUPERUSER) +shutdown = sv.on_command( +    name="紧急停机", +    cmd="/shutdown", +    permission=SUPERUSER +)  @shutdown.handle()  async def _shutdown(bot: Bot, event: MessageEvent, state: T_State) -> None: diff --git a/ATRI/plugins/anime-search/__init__.py b/ATRI/plugins/anime-search/__init__.py index 3ff8964..07cc8dc 100644 --- a/ATRI/plugins/anime-search/__init__.py +++ b/ATRI/plugins/anime-search/__init__.py @@ -1,29 +1,13 @@ -#!/usr/bin/env python3 -# -*- coding:utf-8 -*- -''' -File: __init__.py -Created Date: 2021-02-19 22:16:34 -Author: Kyomotoi -Email: Kyomotoiowo@gmail.com -License: GPLv3 -Project: https://github.com/Kyomotoi/ATRI --------- -Last Modified: Sunday, 7th March 2021 3:18:10 pm -Modified By: Kyomotoi (kyomotoiowo@gmail.com) --------- -Copyright (c) 2021 Kyomotoi -''' -  import re  import json  from nonebot.adapters.cqhttp.message import MessageSegment -from nonebot.plugin import on_command  from nonebot.adapters.cqhttp import Bot, MessageEvent  from nonebot.adapters.cqhttp.message import Message  from nonebot.typing import T_State -from ATRI.rule import is_in_banlist, is_in_dormant +from ATRI.service import Service as sv +from ATRI.rule import is_block, is_in_dormant  from ATRI.exceptions import RequestTimeOut  from ATRI.utils.request import get_bytes @@ -33,9 +17,10 @@ from .data_source import to_simple_string  URL = "https://trace.moe/api/search?url=" -anime_search = on_command( -    "/anime", -    rule=is_in_banlist() & is_in_dormant() +anime_search = sv.on_command( +    name="以图搜番", +    cmd="/anime", +    rule=is_block() & is_in_dormant()  )  @anime_search.handle() diff --git a/ATRI/plugins/anti-rubbish.py b/ATRI/plugins/anti-rubbish.py index 7350789..de8e1e1 100644 --- a/ATRI/plugins/anti-rubbish.py +++ b/ATRI/plugins/anti-rubbish.py @@ -1,19 +1,3 @@ -#!/usr/bin/env python3 -# -*- coding:utf-8 -*- -''' -File: anti-rubbish.py -Created Date: 2021-02-15 12:39:24 -Author: Kyomotoi -Email: Kyomotoiowo@gmail.com -License: GPLv3 -Project: https://github.com/Kyomotoi/ATRI --------- -Last Modified: Sunday, 7th March 2021 3:13:51 pm -Modified By: Kyomotoi (kyomotoiowo@gmail.com) --------- -Copyright (c) 2021 Kyomotoi -''' -  import json  from pathlib import Path  from datetime import datetime @@ -23,7 +7,7 @@ from nonebot.plugin import on_command, on_message  from nonebot.adapters.cqhttp import Bot, GroupMessageEvent  from ATRI.log import logger -from ATRI.rule import is_in_banlist +from ATRI.rule import is_block  from ATRI.config import nonebot_config  from ATRI.utils.file import write_file  from ATRI.utils.apscheduler import scheduler @@ -58,7 +42,7 @@ async def _anti_rubbish(bot: Bot, event: GroupMessageEvent) -> None:                  f"GET 吃屎人 {user}[@群{group}] 第{noob_data[user][key]}次: {msg}") -rubbish = on_command("/rubbish", rule=is_in_banlist()) +rubbish = on_command("/rubbish", rule=is_block())  @rubbish.handle()  async def _rubbish(bot: Bot, event: GroupMessageEvent) -> None: diff --git a/ATRI/plugins/call-owner.py b/ATRI/plugins/call-owner.py index c09276f..af8e83d 100644 --- a/ATRI/plugins/call-owner.py +++ b/ATRI/plugins/call-owner.py @@ -1,28 +1,12 @@ -#!/usr/bin/env python3 -# -*- coding:utf-8 -*- -''' -File: call-owner.py -Created Date: 2021-02-19 23:02:45 -Author: Kyomotoi -Email: Kyomotoiowo@gmail.com -License: GPLv3 -Project: https://github.com/Kyomotoi/ATRI --------- -Last Modified: Sunday, 7th March 2021 3:13:40 pm -Modified By: Kyomotoi (kyomotoiowo@gmail.com) --------- -Copyright (c) 2021 Kyomotoi -''' -  from nonebot.permission import SUPERUSER -from nonebot.plugin import on_command  from nonebot.typing import T_State  from nonebot.adapters.cqhttp import (      Bot,      MessageEvent  ) -from ATRI.rule import is_in_banlist +from ATRI.service import Service as sv +from ATRI.rule import is_block  from ATRI.config import nonebot_config  from ATRI.utils.apscheduler import scheduler  from ATRI.utils.list import count_list @@ -31,7 +15,11 @@ from ATRI.utils.list import count_list  repo_list = [] -repo = on_command("来杯红茶", rule=is_in_banlist()) +repo = sv.on_command( +    name="给维护者留言", +    cmd="来杯红茶", +    rule=is_block() +)  @repo.handle()  async def _repo(bot: Bot, event: MessageEvent, state: T_State) -> None: @@ -69,7 +57,11 @@ async def _() -> None:      repo_list = [] -reset_repo = on_command("重置红茶", permission=SUPERUSER) +reset_repo = sv.on_command( +    name="重置给维护者留言次数", +    cmd="重置红茶", +    permission=SUPERUSER +)  @reset_repo.handle()  async def _reset_repo(bot: Bot, event: MessageEvent) -> None: diff --git a/ATRI/plugins/code-runner.py b/ATRI/plugins/code-runner.py index 0761384..731abfc 100644 --- a/ATRI/plugins/code-runner.py +++ b/ATRI/plugins/code-runner.py @@ -1,27 +1,11 @@ -#!/usr/bin/env python3 -# -*- coding:utf-8 -*- -''' -File: code-runner.py -Created Date: 2021-02-20 07:43:44 -Author: Kyomotoi -Email: Kyomotoiowo@gmail.com -License: GPLv3 -Project: https://github.com/Kyomotoi/ATRI --------- -Last Modified: Sunday, 7th March 2021 3:13:28 pm -Modified By: Kyomotoi (kyomotoiowo@gmail.com) --------- -Copyright (c) 2021 Kyomotoi -''' -  """  Idea from: https://github.com/cczu-osa/aki  """  import json -from nonebot.plugin import on_command  from nonebot.adapters.cqhttp import Bot, MessageEvent -from ATRI.rule import is_in_banlist, is_in_dormant +from ATRI.service import Service as sv +from ATRI.rule import is_block, is_in_dormant  from ATRI.utils.request import post_bytes  from ATRI.exceptions import RequestTimeOut @@ -56,7 +40,11 @@ SUPPORTED_LANGUAGES = {  } -code_runner = on_command("/code", rule=is_in_banlist() & is_in_dormant()) +code_runner = sv.on_command( +    name="运行代码", +    cmd="/code", +    rule=is_block() & is_in_dormant() +)  @code_runner.handle()  async def _code_runner(bot: Bot, event: MessageEvent) -> None: diff --git a/ATRI/plugins/curse/__init__.py b/ATRI/plugins/curse/__init__.py index f78e022..03da205 100644 --- a/ATRI/plugins/curse/__init__.py +++ b/ATRI/plugins/curse/__init__.py @@ -1,24 +1,8 @@ -#!/usr/bin/env python3 -# -*- coding:utf-8 -*- -''' -File: __init__.py -Created Date: 2021-02-04 17:58:27 -Author: Kyomotoi -Email: Kyomotoiowo@gmail.com -License: GPLv3 -Project: https://github.com/Kyomotoi/ATRI --------- -Last Modified: Sunday, 7th March 2021 3:14:41 pm -Modified By: Kyomotoi (kyomotoiowo@gmail.com) --------- -Copyright (c) 2021 Kyomotoi -''' - -from nonebot.plugin import on_command  from nonebot.adapters.cqhttp import Bot, MessageEvent +from ATRI.service import Service as sv  from ATRI.rule import ( -    is_in_banlist, +    is_block,      is_in_dormant,      is_in_service  ) @@ -33,10 +17,11 @@ sick_list = []  __plugin_name__ = 'curse' -curse = on_command( -    "口臭一下", +curse = sv.on_command( +    name="口臭", +    cmd="口臭一下",      aliases={"口臭", "骂我"}, -    rule=is_in_banlist() & is_in_dormant() +    rule=is_block() & is_in_dormant()      & is_in_service(__plugin_name__)  ) diff --git a/ATRI/plugins/drifting-bottle/__init__.py b/ATRI/plugins/drifting-bottle/__init__.py index c9bd0a7..5bd514c 100644 --- a/ATRI/plugins/drifting-bottle/__init__.py +++ b/ATRI/plugins/drifting-bottle/__init__.py @@ -1,16 +1,2 @@ -#!/usr/bin/env python3 -# -*- coding:utf-8 -*- -''' -File: __init__.py -Created Date: 2021-02-15 11:45:36 -Author: Kyomotoi -Email: Kyomotoiowo@gmail.com -License: GPLv3 -Project: https://github.com/Kyomotoi/ATRI --------- -Last Modified: Sunday, 7th March 2021 3:14:36 pm -Modified By: Kyomotoi (kyomotoiowo@gmail.com) --------- -Copyright (c) 2021 Kyomotoi -''' - +from ATRI.service import Service as sv +from ATRI.rule import is_block, is_in_service
\ No newline at end of file diff --git a/ATRI/plugins/essential.py b/ATRI/plugins/essential.py index f7d9840..020a413 100644 --- a/ATRI/plugins/essential.py +++ b/ATRI/plugins/essential.py @@ -1,28 +1,11 @@ -#!/usr/bin/env python3 -# -*- coding:utf-8 -*- -''' -File: essential.py -Created Date: 2021-02-04 12:53:00 -Author: Kyomotoi -Email: Kyomotoiowo@gmail.com -License: GPLv3 -Project: https://github.com/Kyomotoi/ATRI --------- -Last Modified: Sunday, 7th March 2021 3:13:09 pm -Modified By: Kyomotoi (kyomotoiowo@gmail.com) --------- -Copyright (c) 2021 Kyomotoi -''' - +import os  import time  import json  import shutil  from pathlib import Path  from random import choice -import nonebot  from nonebot.adapters import Bot -from nonebot.plugin import on_notice, on_request  from nonebot.adapters.cqhttp.message import Message  from nonebot.adapters.cqhttp import (      FriendRequestEvent, @@ -37,17 +20,19 @@ from nonebot.adapters.cqhttp import (      FriendRecallNoticeEvent  ) +import ATRI  from ATRI.log import logger  from ATRI.exceptions import WriteError  from ATRI.config import nonebot_config -from ATRI.rule import is_in_banlist +from ATRI.rule import is_block  from ATRI.service import Service as sv -PLUGIN_INFO_DIR = Path('.') / 'ATRI' / 'data' / 'service' / 'plugins' +PLUGIN_INFO_DIR = Path('.') / 'ATRI' / 'data' / 'service' / 'services' + +driver = ATRI.driver() -driver = nonebot.get_driver()  @driver.on_startup  async def startup() -> None: @@ -64,8 +49,8 @@ async def shutdown() -> None:      except:          repo = (              '清理插件信息失败', -            '请前往 ATRI/data/service 下', -            '将 plugins 整个文件夹删除' +            '请前往 ATRI/data/service/services 下', +            '将 services 整个文件夹删除'          )          logger.error(repo)          time.sleep(10) @@ -94,9 +79,10 @@ async def disconnect(bot) -> None:  ESSENTIAL_DIR = Path('.') / 'ATRI' / 'data' / 'database' / 'essential' +os.makedirs(ESSENTIAL_DIR, exist_ok=True)  # 处理:好友请求 -request_friend_event = on_request(rule=is_in_banlist()) +request_friend_event = sv.on_request("Friends request", rule=is_block())  @request_friend_event.handle()  async def _request_friend_event(bot, event: FriendRequestEvent) -> None: @@ -136,7 +122,7 @@ async def _request_friend_event(bot, event: FriendRequestEvent) -> None:  # 处理:邀请入群,如身为管理,还附有入群请求 -request_group_event = on_request(rule=is_in_banlist()) +request_group_event = sv.on_request("Group request",rule=is_block())  @request_group_event.handle()  async def _request_group_event(bot, event: GroupRequestEvent) -> None: @@ -178,7 +164,7 @@ async def _request_group_event(bot, event: GroupRequestEvent) -> None:  # 处理群成员变动 -group_member_event = on_notice() +group_member_event = sv.on_notice("Group member change")  @group_member_event.handle()  async def _group_member_event(bot: Bot, event) -> None: @@ -205,7 +191,7 @@ async def _group_member_event(bot: Bot, event) -> None:  # 处理群管理事件 -group_admin_event = on_notice() +group_admin_event = sv.on_notice("Group admin change")  @group_admin_event.handle()  async def _group_admin_event(bot: Bot, event: GroupAdminNoticeEvent) -> None: @@ -218,7 +204,7 @@ async def _group_admin_event(bot: Bot, event: GroupAdminNoticeEvent) -> None:  # 处理群禁言事件 -group_ban_event = on_notice() +group_ban_event = sv.on_notice("Group ban change")  @group_ban_event.handle()  async def _group_ban_event(bot: Bot, event: GroupBanNoticeEvent) -> None: @@ -247,7 +233,7 @@ async def _group_ban_event(bot: Bot, event: GroupBanNoticeEvent) -> None:  # 处理群红包运气王事件 -lucky_read_bag_event = on_notice() +lucky_read_bag_event = sv.on_notice("Group read bag winner")  @lucky_read_bag_event.handle()  async def _lucky_read_bag_event(bot, event: LuckyKingNotifyEvent) -> None: @@ -259,7 +245,7 @@ async def _lucky_read_bag_event(bot, event: LuckyKingNotifyEvent) -> None:  # 处理群文件上传事件 -group_file_upload_event = on_notice() +group_file_upload_event = sv.on_notice("Group file change")  @group_file_upload_event.handle()  async def _group_file_upload_event(bot, @@ -268,7 +254,7 @@ async def _group_file_upload_event(bot,  # 处理撤回事件 -recall_event = on_notice() +recall_event = sv.on_notice("Group member recall")  @recall_event.handle()  async def _recall_event(bot: Bot, event) -> None: diff --git a/ATRI/plugins/funny.py b/ATRI/plugins/funny.py index 39a691d..472c77c 100644 --- a/ATRI/plugins/funny.py +++ b/ATRI/plugins/funny.py @@ -1,27 +1,11 @@ -#!/usr/bin/env python3 -# -*- coding:utf-8 -*- -''' -File: funny.py -Created Date: 2021-02-04 21:17:21 -Author: Kyomotoi -Email: Kyomotoiowo@gmail.com -License: GPLv3 -Project: https://github.com/Kyomotoi/ATRI --------- -Last Modified: Sunday, 7th March 2021 3:13:19 pm -Modified By: Kyomotoi (kyomotoiowo@gmail.com) --------- -Copyright (c) 2021 Kyomotoi -''' -  from pathlib import Path  from random import choice, randint  from nonebot.adapters.cqhttp import Bot, MessageEvent -from nonebot.plugin import on_command, on_message +from ATRI.service import Service as sv  from ATRI.rule import ( -    is_in_banlist, +    is_block,      is_in_dormant,      is_in_service  ) @@ -29,9 +13,10 @@ from ATRI.rule import (  __plugin_name__ = "laugh" -get_laugh = on_command( -    "来句笑话", -    rule=is_in_banlist() & is_in_dormant() +get_laugh = sv.on_command( +    name="看不懂的笑话", +    cmd="来句笑话", +    rule=is_block() & is_in_dormant()      & is_in_service(__plugin_name__)  ) @@ -51,9 +36,10 @@ async def _get_laugh(bot: Bot, event: MessageEvent) -> None:  __plugin_name__ = "wty" -me_to_you = on_message( -    rule=is_in_banlist() & is_in_dormant() & is_in_service(__plugin_name__) +me_to_you = sv.on_message( +    rule=is_block() & is_in_dormant() & is_in_service(__plugin_name__)  ) +sv.manual_reg_service("你又彳亍了")  @me_to_you.handle()  async def _me_to_you(bot: Bot, event: MessageEvent) -> None: diff --git a/ATRI/plugins/github.py b/ATRI/plugins/github.py index 118d6f5..167ca2f 100644 --- a/ATRI/plugins/github.py +++ b/ATRI/plugins/github.py @@ -1,26 +1,9 @@ -#!/usr/bin/env python3 -# -*- coding:utf-8 -*- -''' -File: github.py -Created Date: 2021-02-26 23:22:34 -Author: Kyomotoi -Email: Kyomotoiowo@gmail.com -License: GPLv3 -Project: https://github.com/Kyomotoi/ATRI --------- -Last Modified: Sunday, 7th March 2021 3:11:56 pm -Modified By: Kyomotoi (kyomotoiowo@gmail.com) --------- -Copyright (c) 2021 Kyomotoi -''' -  import re  import json - -from nonebot.plugin import on_message  from nonebot.adapters.cqhttp import Bot, MessageEvent -from ATRI.rule import is_in_banlist, is_in_dormant +from ATRI.service import Service as sv +from ATRI.rule import is_block, is_in_dormant  from ATRI.utils.request import get_bytes  from ATRI.exceptions import RequestTimeOut @@ -28,7 +11,8 @@ from ATRI.exceptions import RequestTimeOut  URL = "https://api.github.com/repos/{owner}/{repo}/issues/{issue_number}" -github_issues = on_message(rule=is_in_banlist() & is_in_dormant()) +github_issues = sv.on_message(rule=is_block() & is_in_dormant()) +sv.manual_reg_service("GitHubIssue速览")  @github_issues.handle()  async def _github_issues(bot: Bot, event: MessageEvent) -> None: diff --git a/ATRI/plugins/hitokoto.py b/ATRI/plugins/hitokoto.py index ff686fc..3754125 100644 --- a/ATRI/plugins/hitokoto.py +++ b/ATRI/plugins/hitokoto.py @@ -1,33 +1,16 @@ -#!/usr/bin/env python3 -# -*- coding:utf-8 -*- -''' -File: hitokoto.py -Created Date: 2021-02-04 17:40:21 -Author: Kyomotoi -Email: Kyomotoiowo@gmail.com -License: GPLv3 -Project: https://github.com/Kyomotoi/ATRI --------- -Last Modified: Sunday, 7th March 2021 3:11:44 pm -Modified By: Kyomotoi (kyomotoiowo@gmail.com) --------- -Copyright (c) 2021 Kyomotoi -''' -  import os  import json  from pathlib import Path  from random import choice, randint - -from nonebot.plugin import on_command  from nonebot.adapters.cqhttp import Bot, MessageEvent  from ATRI.rule import ( -    is_in_banlist, +    is_block,      is_in_dormant,      is_in_service,      to_bot  ) +from ATRI.service import Service as sv  from ATRI.exceptions import LoadingError  from ATRI.utils.list import count_list, del_list_aim @@ -38,10 +21,11 @@ sick_list = []  __plugin_name__ = 'hitokoto' -hitokoto = on_command( -    "一言", +hitokoto = sv.on_command( +    name="Hitokoto", +    cmd="一言",      aliases={"抑郁一下", "网抑云"}, -    rule=is_in_banlist() & is_in_dormant() +    rule=is_block() & is_in_dormant()      & is_in_service(__plugin_name__) & to_bot()  ) diff --git a/ATRI/plugins/key-repo/__init__.py b/ATRI/plugins/key-repo/__init__.py new file mode 100644 index 0000000..4b2241c --- /dev/null +++ b/ATRI/plugins/key-repo/__init__.py @@ -0,0 +1,171 @@ +import os +import json +import time +from random import choice +from pathlib import Path + +from nonebot.typing import T_State +from nonebot.adapters.cqhttp import Bot, MessageEvent + +from ATRI.config import nonebot_config +from ATRI.service import Service as sv +from ATRI.rule import is_block, is_in_dormant, is_in_service, to_bot + + +# 此功能未完善 + + +KEYREPO_DIV = Path('.') / 'ATRI' / 'data' / 'database' / 'KeyRepo' +os.makedirs(KEYREPO_DIV, exist_ok=True) + + +__plugin_name__ = "KeyRepo" + +keyrepo = sv.on_message(rule=is_block() +                        & is_in_dormant() +                        & is_in_service(__plugin_name__) +                        & to_bot()) + +@keyrepo.handle() +async def _keyrepo(bot: Bot, event: MessageEvent) -> None: +    msg = str(event.get_message()) + +    file_name = "data.json" +    path = KEYREPO_DIV / file_name +    try: +        data = json.loads(path.read_bytes()) +    except: +        with open(path, 'w') as r: +            r.write(json.dumps({})) +        data = {} + +    for key in data.keys(): +        if key in msg: +            await keyrepo.finish(choice(data[key])) + + +train = sv.on_command( +    name="调教", +    cmd="/train", +    rule=is_block() +) + +@train.got("key", prompt="哦哦哦要开始学习了!请告诉咱知识点") +async def _train(bot: Bot, event: MessageEvent, state: T_State) -> None: +    if "[CQ" in state["key"]: +        await train.reject("仅支持纯文本呢...") + +@train.got("repo", prompt="咱该如何回答呢?") +async def _trainR(bot: Bot, event: MessageEvent, state: T_State) -> None: +    if "[CQ" in state["repo"]: +        await train.reject("仅支持纯文本呢...") +         +    if state["key"] == "-d": +        file_name = "review.json" +        path = KEYREPO_DIV / file_name +        try: +            data = json.loads(path.read_bytes()) +        except: +            data = {} + +        key = state["repo"] +        if key not in data: +            await train.finish("未发现该待审核的知识点呢...") +        else: +            msg = ( +                f"Key: {key}\n" +                f"Repo: {data[key]['repo']}\n" +                "已经从咱的审核列表移除!" +            ) +            del data[key] +            with open(path, 'w') as r: +                r.write(json.dumps(data)) +            await train.finish(msg) +    elif state["key"] == "-i": +        file_name = "review.json" +        path = KEYREPO_DIV / file_name +        try: +            data = json.loads(path.read_bytes()) +        except: +            data = {} +        if state["repo"] not in data: +            await train.finish("未发现该知识点呢") +        key = data[state["repo"]] +         +        msg = ( +            f"用户: {key['user']}\n" +            f"知识点: {state['repo']}" +            f"回复: {key['repo']}" +            f"时间: {key['time']}" +            "/train -r 知识点 y/n" +        ) +        await train.finish(msg) +    elif state["key"] == "-ls": +        file_name = "review.json" +        path = KEYREPO_DIV / file_name +        try: +            data = json.loads(path.read_bytes()) +        except: +            data = {} +        keys = ",".join(data.keys()) +        msg = f"目前等待审核的有如下:\n{keys}" +        await train.finish(msg) +    elif state["key"] == "-r": +        file_name = "review.json" +        path = KEYREPO_DIV / file_name +        try: +            data = json.loads(path.read_bytes()) +        except: +            data = {} +         +     +    key = state["key"] +    repo = state["repo"] +    user = event.get_user_id() +    if user not in nonebot_config["superusers"]: +        file_name = "review.json" +        path = KEYREPO_DIV / file_name +        try: +            data = json.loads(path.read_bytes()) +        except: +            data = {} +         +        if key in data: +            msg = "欸欸欸,该词还在等待咱的审核,请先等先来的审核完再提交吧..." +            await train.finish(msg) +        else: +            data[key] = { +                "user": user, +                "repo": repo, +                "time": time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()) +            } +            with open(path, 'r') as r: +                r.write(json.dumps(data, indent=4)) + +            msg = ( +            "欸欸欸这不错欸!不过,还是先等待咱审核审核," +            "如想撤销本次学习,请发送 /train -d 知识点" +            ) +            await train.finish(msg) +         +    else: +        file_name = "data.json" +        path = KEYREPO_DIV / file_name +        try: +            data = json.loads(path.read_bytes()) +        except: +            data = {} +         +        if key in data: +            repo_list: list = data[key] +            repo_list.append(repo) +            data[key] = repo_list +            msg = f"哦哦哦,{key}原来还有这样的回复,学到了~!" +            await bot.send(event, msg) +        else: +            data[key] = [repo] +            msg = "好欸,咱学到了新的知识点!" +            await bot.send(event, msg) +         +        with open(path, 'w') as r: +            r.write(json.dumps(data)) diff --git a/ATRI/plugins/rich/__init__.py b/ATRI/plugins/rich/__init__.py index 7f9369e..7c8179d 100644 --- a/ATRI/plugins/rich/__init__.py +++ b/ATRI/plugins/rich/__init__.py @@ -1,30 +1,13 @@ -#!/usr/bin/env python3 -# -*- coding:utf-8 -*- -''' -File: __init__.py -Created Date: 2021-02-07 09:34:23 -Author: Kyomotoi -Email: Kyomotoiowo@gmail.com -License: GPLv3 -Project: https://github.com/Kyomotoi/ATRI --------- -Last Modified: Sunday, 7th March 2021 3:14:28 pm -Modified By: Kyomotoi (kyomotoiowo@gmail.com) --------- -Copyright (c) 2021 Kyomotoi -''' -  import re  import json  from aiohttp.client import ClientSession -  from nonebot.adapters.cqhttp import Bot, MessageEvent -from nonebot.plugin import on_message +from ATRI.service import Service as sv  from ATRI.utils.request import get_bytes  from ATRI.utils.list import count_list, del_list_aim  from ATRI.rule import ( -    is_in_banlist, +    is_block,      is_in_dormant,  ) @@ -34,9 +17,10 @@ from .data_source import dec  waiting_list = [] -bilibili_rich = on_message( -    rule=is_in_banlist() & is_in_dormant() +bilibili_rich = sv.on_message( +    rule=is_block() & is_in_dormant()  ) +sv.manual_reg_service("监听b站小程序")  @bilibili_rich.handle()  async def _bilibili_rich(bot: Bot, event: MessageEvent) -> None: diff --git a/ATRI/plugins/rich/data_source.py b/ATRI/plugins/rich/data_source.py index d3e7d6e..32ac219 100644 --- a/ATRI/plugins/rich/data_source.py +++ b/ATRI/plugins/rich/data_source.py @@ -1,19 +1,3 @@ -#!/usr/bin/env python3 -# -*- coding:utf-8 -*- -''' -File: data_source.py -Created Date: 2021-02-07 09:34:31 -Author: Kyomotoi -Email: Kyomotoiowo@gmail.com -License: GPLv3 -Project: https://github.com/Kyomotoi/ATRI --------- -Last Modified: Sunday, 7th March 2021 3:14:31 pm -Modified By: Kyomotoi (kyomotoiowo@gmail.com) --------- -Copyright (c) 2021 Kyomotoi -''' -  table = 'fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF'  tr = {}  for i in range(58): diff --git a/ATRI/plugins/status.py b/ATRI/plugins/status.py index fe10dea..c3b033c 100644 --- a/ATRI/plugins/status.py +++ b/ATRI/plugins/status.py @@ -1,36 +1,30 @@ -#!/usr/bin/env python3 -# -*- coding:utf-8 -*- -''' -File: status.py -Created Date: 2021-02-19 21:52:56 -Author: Kyomotoi -Email: Kyomotoiowo@gmail.com -License: GPLv3 -Project: https://github.com/Kyomotoi/ATRI --------- -Last Modified: Sunday, 7th March 2021 3:11:30 pm -Modified By: Kyomotoi (kyomotoiowo@gmail.com) --------- -Copyright (c) 2021 Kyomotoi -''' -  import psutil - -from nonebot.plugin import on_command  from nonebot.adapters.cqhttp import Bot, MessageEvent -from ATRI.rule import is_in_banlist +from ATRI.log import logger as log +from ATRI.service import Service as sv +from ATRI.rule import is_block  from ATRI.exceptions import GetStatusError +from ATRI.utils.apscheduler import scheduler +from ATRI.config import nonebot_config -ping = on_command("/ping", rule=is_in_banlist()) +ping = sv.on_command( +    name="测试机器人", +    cmd="/ping", +    rule=is_block() +)  @ping.handle()  async def _ping(bot: Bot, event: MessageEvent) -> None:      await ping.finish("I'm fine.") -status = on_command("/status", rule=is_in_banlist()) +status = sv.on_command( +    name="检查机器人状态", +    cmd="/status", +    rule=is_block() +)  @status.handle()  async def _status(bot: Bot, event: MessageEvent) -> None: @@ -64,3 +58,48 @@ async def _status(bot: Bot, event: MessageEvent) -> None:      ) + msg      await status.finish(msg0) + + +@scheduler.scheduled_job( +    'interval', +    minutes=5, +    misfire_grace_time=10 +) +async def _(): +    log.info("开始自检") +    try: +        cpu = psutil.cpu_percent(interval=1) +        mem = psutil.virtual_memory().percent +        disk = psutil.disk_usage("/").percent +        inteSENT = psutil.net_io_counters().bytes_sent / 1000000 # type: ignore +        inteRECV = psutil.net_io_counters().bytes_sent / 1000000 # type: ignore +    except GetStatusError: +        raise GetStatusError("Failed to get status.") +     +    msg = "" +    if cpu > 80:  # type: ignore +        msg = "咱感觉有些头晕..." +        if mem > 80: +            msg = "咱感觉有点头晕并且有点累..." +    elif mem > 80: +        msg = "咱感觉有点累..." +    elif disk > 80: +        msg = "咱感觉身体要被塞满了..." +    else: +        log.info("运作正常") +        return +     +    msg0 = ( +        "Self status:\n" +        f"* CPU: {cpu}%\n" +        f"* MEM: {mem}%\n" +        f"* DISK: {disk}%\n" +        f"* netSENT: {inteSENT}MB\n" +        f"* netRECV: {inteRECV}MB\n" +    ) + msg +     +    for sup in nonebot_config["superusers"]: +        await sv.NetworkPost.send_private_msg( +            user_id=sup, +            message=msg0 +        ) diff --git a/ATRI/plugins/utils/__init__.py b/ATRI/plugins/utils/__init__.py index 47c3b47..10b3317 100644 --- a/ATRI/plugins/utils/__init__.py +++ b/ATRI/plugins/utils/__init__.py @@ -1,26 +1,9 @@ -#!/usr/bin/env python3 -# -*- coding:utf-8 -*- -''' -File: __init__.py -Created Date: 2021-02-04 21:14:48 -Author: Kyomotoi -Email: Kyomotoiowo@gmail.com -License: GPLv3 -Project: https://github.com/Kyomotoi/ATRI --------- -Last Modified: Sunday, 7th March 2021 3:14:16 pm -Modified By: Kyomotoi (kyomotoiowo@gmail.com) --------- -Copyright (c) 2021 Kyomotoi -''' -  import re - -from nonebot.plugin import on_command  from nonebot.adapters.cqhttp import Bot, MessageEvent +from ATRI.service import Service as sv  from ATRI.rule import ( -    is_in_banlist, +    is_block,      is_in_dormant,      is_in_service  ) @@ -29,9 +12,10 @@ from .data_source import roll_dice  __plugin_name__ = "roll" -roll = on_command( -    "/roll", -    rule=is_in_banlist() & is_in_dormant() +roll = sv.on_command( +    name="roll一下", +    cmd="/roll", +    rule=is_block() & is_in_dormant()      & is_in_service(__plugin_name__)  ) @@ -50,18 +34,3 @@ async def _(bot: Bot, event: MessageEvent, state: dict) -> None:          await roll.finish("请输入正确的参数!!\ndemo:1d10 或 2d10+2d10")      await roll.finish(roll_dice(resu)) - - -# __plugin_name__ = "fakemsg" - -# fakemsg = on_command( -#     "/fakemsg", -#     rule=is_in_banlist() & is_in_dormant() -#     & is_in_service(__plugin_name__) -# ) - -# @fakemsg.handle() -# async def _fakemsg(bot: Bot, event: MessageEvent, state: dict) -> None: -#     ... - -# @fakemsg.got()
\ No newline at end of file diff --git a/ATRI/plugins/utils/data_source.py b/ATRI/plugins/utils/data_source.py index 6d018f1..f41a1d1 100644 --- a/ATRI/plugins/utils/data_source.py +++ b/ATRI/plugins/utils/data_source.py @@ -1,19 +1,3 @@ -#!/usr/bin/env python3 -# -*- coding:utf-8 -*- -''' -File: data_source.py -Created Date: 2021-02-04 21:14:59 -Author: Kyomotoi -Email: Kyomotoiowo@gmail.com -License: GPLv3 -Project: https://github.com/Kyomotoi/ATRI --------- -Last Modified: Sunday, 7th March 2021 3:14:22 pm -Modified By: Kyomotoi (kyomotoiowo@gmail.com) --------- -Copyright (c) 2021 Kyomotoi -''' -  import re  import random | 
