├── .gitignore ├── LICENSE ├── README.md ├── nonebot_plugin_eventdone ├── README.md ├── __init__.py ├── __pycache__ │ ├── __init__.cpython-39.pyc │ └── config.cpython-39.pyc ├── config.py └── set.json └── pyproject.toml /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 PadorFelice 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Nonebot_plugin_eventdone 2 | 远程好友申请事件的处理~这是我第一次写插件喵~请多多指教,有问题请尽快联系我喵~ 3 | 4 | 5 | # 使用说明 6 | 1.pip install nonebot_plugin_eventdone 7 | 2.解压放入你的plugin文件夹即可食用喵~(记得查看PS!!!) 8 | 3.set.json文件里的几个QQ号可以删除,是测试的实验号() 9 | 10 | 11 | # PS 12 | 1.罐头是我家猫猫的名字,您当然也可以改成您喜欢的东西的名字 13 | 2.在运行前请先检查import的组件您是否已经准备齐全,超级用户是否在.env中设置完毕 14 | 3.本组件基于nonebot运行,如果您使用的不是nonebot,出错概不负责 15 | 16 | # 有疑问(请事先查看提问的智慧) 17 | 请先自己想一想喵~ 18 | 实在不会的话再issue! 19 | -------------------------------------------------------------------------------- /nonebot_plugin_eventdone/README.md: -------------------------------------------------------------------------------- 1 | # Nonebot_plugin_eventdone 2 | 远程好友申请事件的处理~这是我第一次写插件喵~请多多指教,有问题请尽快联系我喵~ 3 | 4 | 5 | 使用说明 6 | 1.直接下载压缩包/使用git clone gh repo clone PadorFelice/Nonebot_plugin_eventdone 7 | 2.解压放入你的plugin文件夹即可食用喵~(记得查看PS!!!) 8 | 9 | PS:罐头是我家猫猫的名字,您当然也可以改成您喜欢的东西的名字 10 | 在运行前请先检查import的组件您是否已经准备齐全,超级用户是否在.env中设置完毕 11 | 本组件基于nonebot运行,如果您使用的不是nonebot,出错概不负责 12 | 13 | 有疑问(请事先查看提问的智慧) 14 | 自己想 15 | issue 16 | -------------------------------------------------------------------------------- /nonebot_plugin_eventdone/__init__.py: -------------------------------------------------------------------------------- 1 | import time 2 | import json 3 | import aiofiles 4 | from nonebot import get_driver, get_bot 5 | from nonebot.adapters.onebot.v11 import Bot, FriendRequestEvent, PrivateMessageEvent 6 | from nonebot.permission import SUPERUSER 7 | from nonebot.plugin import on_command, on_request 8 | from .config import Config 9 | 10 | # 配置项 11 | config = Config.parse_obj(get_driver().config.dict()) 12 | conf_path = config.conf_path 13 | 14 | # 获取超级用户的id 15 | super_id = get_driver().config.superusers 16 | 17 | 18 | async def friend_request_rule(event: FriendRequestEvent): 19 | async with aiofiles.open(conf_path, "r", encoding="utf-8") as f: 20 | obj = json.loads(await f.read()) 21 | add_qq = int(json.loads(event.json())["user_id"]) 22 | qq_set = set(obj["add_qq_req_list"]["qq"]) 23 | return add_qq not in qq_set 24 | 25 | 26 | 27 | # 超级用户推送添加机器人好友请求事件 28 | add_friend = on_request(friend_request_rule, priority=1, block=True) 29 | 30 | 31 | @add_friend.handle() 32 | async def _(bot: Bot, event: FriendRequestEvent): 33 | try: 34 | async with aiofiles.open(conf_path, "r", encoding="utf-8") as f: 35 | obj = json.loads(await f.read()) 36 | qq_list = list(obj["add_qq_req_list"]["qq"]) 37 | add_req = json.loads(event.json()) 38 | add_qq = add_req["user_id"] 39 | qq_list.append(add_qq) 40 | comment = add_req["comment"] 41 | flag = add_req["flag"] 42 | realtime = time.strftime("%Y年%m月%d日 %H:%M:%S", time.localtime(add_req["time"])) 43 | obj["add_qq_req_list"]["qq"] = qq_list 44 | obj["add_qq_req_list"]["flag"] = flag 45 | async with aiofiles.open(conf_path, "w", encoding="utf-8") as f: 46 | await f.write(json.dumps(obj, indent=4)) 47 | for su_qq in super_id: 48 | await bot.send_private_msg(user_id=int(su_qq), 49 | message=f"QQ:{add_qq} 请求添加罐头为好友!\n请求添加时间:{realtime}\n验证信息为:{comment}") 50 | except Exception as e: 51 | for su_qq in super_id: 52 | await bot.send_private_msg(user_id=int(su_qq), message=f"罐头坏掉了\n错误信息:{e}") 53 | 54 | 55 | # 超级用户使用,同意好友添加机器人请求 56 | agree_qq_add = on_command("同意", permission=SUPERUSER) 57 | 58 | 59 | @agree_qq_add.handle() 60 | async def _(bot: Bot, event: PrivateMessageEvent): 61 | try: 62 | async with aiofiles.open(conf_path, "r", encoding="utf-8") as f: 63 | obj = json.loads(await f.read()) 64 | qq_set = set(obj["add_qq_req_list"]["qq"]) 65 | flag = obj["add_qq_req_list"]["flag"] 66 | user_id = int(event.get_user_id()) 67 | agree_id = int(str(event.get_message()).split("同意")[-1]) #在QQ上同意时请加上申请人QQ号 68 | if agree_id in qq_set: 69 | await bot.send_private_msg(user_id=user_id, message=f"机器人成功添加QQ:{agree_id}为好友!") 70 | await bot.set_friend_add_request(flag=flag, approve=True, remark="") 71 | obj["add_qq_req_list"]["qq"] = list(qq_set) 72 | obj["add_qq_req_list"]["flag"] = "" 73 | async with aiofiles.open(conf_path, "w", encoding="utf-8") as f: 74 | await f.write(json.dumps(obj, indent=4)) 75 | else: 76 | await bot.send_private_msg(user_id=user_id, message=f"QQ:{agree_id}不在好友申请列表!") 77 | except Exception as e: 78 | for su_qq in super_id: 79 | await bot.send_private_msg(user_id=int(su_qq), message=f"罐头出错了\n错误信息:{e}") -------------------------------------------------------------------------------- /nonebot_plugin_eventdone/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PadorFelice/nonebot_plugin_eventdone/de648270e9db9d95a73b525659baadb0d909b44d/nonebot_plugin_eventdone/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /nonebot_plugin_eventdone/__pycache__/config.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PadorFelice/nonebot_plugin_eventdone/de648270e9db9d95a73b525659baadb0d909b44d/nonebot_plugin_eventdone/__pycache__/config.cpython-39.pyc -------------------------------------------------------------------------------- /nonebot_plugin_eventdone/config.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | from pydantic import BaseModel, Extra 3 | 4 | 5 | class Config(BaseModel, extra=Extra.ignore): 6 | conf_path: str = str(Path(__file__).parent / "set.json") -------------------------------------------------------------------------------- /nonebot_plugin_eventdone/set.json: -------------------------------------------------------------------------------- 1 | { 2 | "add_qq_req_list": { 3 | "qq": [], 4 | "flag": "" 5 | } 6 | } -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.poetry] 2 | name = "nonebot_plugin_eventdone" 3 | version = "1.1.1" 4 | description = "" 5 | authors = ["Padro Felice <2659737583@qq.com>"] 6 | license = "MIT" 7 | 8 | [tool.poetry.dependencies] 9 | python = "^3.8" 10 | nonebot2 = "^2.0.0-rc.3" 11 | aiofiles = "^23.1.0" 12 | nonebot-adapter-onebot = "^2.1.3" 13 | 14 | [tool.poetry.dev-dependencies] 15 | 16 | [build-system] 17 | requires = ["poetry-core>=1.0.0"] 18 | build-backend = "poetry.core.masonry.api" 19 | --------------------------------------------------------------------------------