├── LICENSE ├── README.md ├── dist ├── nonebot_plugin_addFriend-2.1.1.tar.gz ├── nonebot_plugin_addFriend-2.2.0.tar.gz ├── nonebot_plugin_addFriend-2.2.1.tar.gz ├── nonebot_plugin_addFriend-2.2.2.tar.gz ├── nonebot_plugin_addFriend-2.2.3.tar.gz ├── nonebot_plugin_addFriend-2.2.4.tar.gz ├── nonebot_plugin_addFriend-2.2.5.tar.gz ├── nonebot_plugin_addFriend-2.3.0.tar.gz ├── nonebot_plugin_addFriend-2.3.2.tar.gz ├── nonebot_plugin_addFriend-2.3.3.tar.gz ├── nonebot_plugin_addFriend-2.4.0.tar.gz ├── nonebot_plugin_addFriend-2.4.1.tar.gz ├── nonebot_plugin_addfriend-2.4.2-py3-none-any.whl ├── nonebot_plugin_addfriend-2.4.2.tar.gz ├── nonebot_plugin_addfriend-2.4.3-py3-none-any.whl ├── nonebot_plugin_addfriend-2.4.3.tar.gz ├── nonebot_plugin_addfriend-2.4.4-py3-none-any.whl ├── nonebot_plugin_addfriend-2.4.4.tar.gz ├── nonebot_plugin_addfriend-2.4.5-py3-none-any.whl ├── nonebot_plugin_addfriend-2.4.5.tar.gz ├── nonebot_plugin_addfriend-2.4.6-py3-none-any.whl ├── nonebot_plugin_addfriend-2.4.6.tar.gz ├── nonebot_plugin_addfriend-2.4.7-py3-none-any.whl ├── nonebot_plugin_addfriend-2.4.7.tar.gz ├── nonebot_plugin_addfriend-2.5.0-py3-none-any.whl ├── nonebot_plugin_addfriend-2.5.0.tar.gz ├── nonebot_plugin_addfriend-2.5.1-py3-none-any.whl ├── nonebot_plugin_addfriend-2.5.1.tar.gz ├── nonebot_plugin_addfriend-2.5.2-py3-none-any.whl ├── nonebot_plugin_addfriend-2.5.2.tar.gz ├── nonebot_plugin_addfriend-2.5.3-py3-none-any.whl ├── nonebot_plugin_addfriend-2.5.3.tar.gz ├── nonebot_plugin_addfriend-2.5.4-py3-none-any.whl ├── nonebot_plugin_addfriend-2.5.4.tar.gz ├── nonebot_plugin_addfriend-2.5.5-py3-none-any.whl ├── nonebot_plugin_addfriend-2.5.5.tar.gz ├── nonebot_plugin_addfriend-2.5.6-py3-none-any.whl └── nonebot_plugin_addfriend-2.5.6.tar.gz ├── nonebot_plugin_addFriend.egg-info ├── PKG-INFO ├── SOURCES.txt ├── dependency_links.txt ├── requires.txt └── top_level.txt ├── nonebot_plugin_addFriend ├── __init__.py ├── __pycache__ │ └── __init__.cpython-38.pyc ├── config.json ├── configUtil.py ├── num.json ├── requestor.json └── utils.py ├── publish.bat └── pyproject.toml /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 ziru-w 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_addFriend 2 | ## 一个基于NoneBot2的插件,用于处理被请求加QQ好友和QQ群的请求 3 | 4 | 5 | A plug-in based on nonebot2, which is used to process the request to add QQ friends and QQ groups 6 | 7 | ## 如果版本更新请按模板手动配置config.json文件中的新增项和键名更改项,如果不介意原来配置初始化,可以删掉重新生成。修改config.json 时,如果使用vscode的话推荐使用prettier插件格式化,自带的也行 8 | 9 | 下载方法: 10 | 11 | pip install nonebot_plugin_addFriend 12 | 13 | 14 | 15 | 多个机器人配置原理: 16 | 17 | 初始配置文件为{},每多一个机器人触发插件,便会以其id即QQ号为索引在配置中生成该机器人的配置 18 | 19 | 20 | 21 | 总的来说有如下几种主动命令: 22 | 23 | /重载配置 24 | 25 | /更改自动同意,/更改最大加数量,/更改查看加返回数量,/更改加时间,/更改加时间单位(群聊、好友) 26 | 27 | /同意加,/拒绝加,/查看加(群聊、好友) 28 | 29 | /清理请求表 30 | 31 | /重置请求次数(群聊、好友) 32 | 33 | /添加请求接收者,/删除请求接收者 34 | 35 | 36 | 37 | 解释如下: 38 | 39 | 1.该插件运行后会检查配置文件是否存在,并生成默认配置,也可手动复制内容创建文件,创建路径为插件目录,文件名为config.json,其中.json为后缀名,表征文件类型,请不要创建为config.json.json文件, 40 | 41 | 2.可自行设置是否同意自动加好友,命令为/更改自动同意群聊 1、/更改自动同意好友 0、/更改自动同意 1 1 1是同意,0是不同意 42 | 43 | 同时,也可以重置当时间段好友请求的数量 /重置请求次数(群聊、好友) 数量(不写默认重置日被请求次数为零,后缀数字则会重置为该数值,(群聊、好友)是指命令为/重置请求次数群聊和/重置请求次数好友以此区分重置类型。下面类似者,不再赘述), 44 | 45 | 3.该插件会检查添加好友、群的请求,同意自动添加则自动,好友上限默认为2小时5个,群聊8小时2个,群聊加的频繁易风控,具体频率可以自己控制,等下次收到请求时会检查时间,如果是下一个时间段会重置被请求加好友、群次数,并向插件指定qq号发送提示, 46 | 47 | 4.不同意则保存记录等待命令/同意加(好友、群聊) qq号或群号,/拒绝加(好友、群聊) qq号或群号,/查看加(好友、群聊) 查看数量(可不填,默认为配置中的最大值),也可以写一个算法依时清理没有自动添加的好友群聊, 48 | 49 | 5./添加请求接收者 /删除请求接收者 此二者用来添加好友请求处理人,默认配置为前2个超管。 50 | 51 | 6./更改最大加数量(好友、群聊) 数量(正整数) 52 | 53 | /更改加时间(好友、群聊) 时间(正整数) 54 | 55 | /更改加时间单位(好友、群聊) 时/分/天 (刷新时间间隔单位) 56 | 57 | 7./重载配置 重新载入配置文件数据 用于手动修改文件后的重载问题 58 | 59 | 8./更改查看加返回数量 数量 (非负整数,<120) 60 | 61 | 9.黑名单群聊与警告群聊、黑名单群名与警告群名,一个直接拒绝、一个不自动同意,含黑名单、警告词或群号时生效,可以同时转发拉人头兼职群群聊发起者给配置过的好友,一般是该群管理员(自己配置qq号,因为只发给好友,临时会话太危险),暂无机器人接口、请于本插件目录下config.json文件中手动配置 62 | 63 | 10.验证消息,需要验证消息在添加者验证消息中方验证通过,默认空,表示皆通过。手动配置 64 | 65 | 11./清理请求表 清理请求表中已添加过的好友信息 66 | 67 | 12./加好友帮助 返回各命令,忘了命令是哪个就康康。 68 | 69 | 70 | 预期更新,1.优化返回结果,2.改善验证,便于用户自行编写验证方法,3.增加闲余时间自处理多余请求算法 71 | 72 | 配置项模板结构 73 | 74 | { 75 | 76 | "agreeAutoApprove": { "friend": 1, "group": 0 }, 77 | 78 | "recipientList": [], 79 | 80 | "forwardSet":0, 81 | 82 | "numControl": {"useAlgorithm":0, "maxNum": 5, "time": 2, "unit": "h" ,"friend":{"maxNum": 5, "time": 2, "unit": "h" },"group":{"maxNum": 2, "time": 8, "unit": "h" }}, 83 | 84 | "maxViewNum": 20, 85 | 86 | "blackDict":{"friend":{"text":[],"id":[]},"group":{"text":[],"id":[]},"forward":{}}, 87 | 88 | "warnDict":{"friend":{"text":[],"id":[]},"group":{"text":[],"id":[]},"forward":{}}, 89 | 90 | "allowAddFriednText":[], 91 | 92 | "botName": "我", 93 | 94 | "friend_msg": { 95 | 96 | ​ "notice_msg": "请求添加好友,验证消息为", 97 | 98 | ​ "welcome_msg": "我未知的的朋友啊,很高兴你添加我为qq好友哦!\n同时,如果有疑问,可以发送/help哦" 99 | 100 | }, 101 | 102 | "group_msg": { 103 | 104 | ​ "notice_msg": "发送群邀请,验证消息为", 105 | 106 | ​ "welcome_msg": "我亲爱的的朋友啊,很高兴你邀请我哦!" 107 | 108 | }, 109 | 110 | "statusDict":{ 111 | 112 | ​ "blackDict":{"friend":{"status":"拉黑QQ,已拒绝,仅作提示"},"group":{"status":"拉黑群聊,已拒绝,仅作提示"}}, 113 | 114 | ​ "warnDict":{"friend":{"status":"警告QQ,手动同意,是否同意"},"group":{"status":"警告群聊,手动同意,是否同意"}} 115 | 116 | } 117 | 118 | } -------------------------------------------------------------------------------- /dist/nonebot_plugin_addFriend-2.1.1.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ziru-w/nonebot_plugin_addFriend/6f13017c532b7d6edd78585ab8edbd48651613a8/dist/nonebot_plugin_addFriend-2.1.1.tar.gz -------------------------------------------------------------------------------- /dist/nonebot_plugin_addFriend-2.2.0.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ziru-w/nonebot_plugin_addFriend/6f13017c532b7d6edd78585ab8edbd48651613a8/dist/nonebot_plugin_addFriend-2.2.0.tar.gz -------------------------------------------------------------------------------- /dist/nonebot_plugin_addFriend-2.2.1.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ziru-w/nonebot_plugin_addFriend/6f13017c532b7d6edd78585ab8edbd48651613a8/dist/nonebot_plugin_addFriend-2.2.1.tar.gz -------------------------------------------------------------------------------- /dist/nonebot_plugin_addFriend-2.2.2.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ziru-w/nonebot_plugin_addFriend/6f13017c532b7d6edd78585ab8edbd48651613a8/dist/nonebot_plugin_addFriend-2.2.2.tar.gz -------------------------------------------------------------------------------- /dist/nonebot_plugin_addFriend-2.2.3.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ziru-w/nonebot_plugin_addFriend/6f13017c532b7d6edd78585ab8edbd48651613a8/dist/nonebot_plugin_addFriend-2.2.3.tar.gz -------------------------------------------------------------------------------- /dist/nonebot_plugin_addFriend-2.2.4.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ziru-w/nonebot_plugin_addFriend/6f13017c532b7d6edd78585ab8edbd48651613a8/dist/nonebot_plugin_addFriend-2.2.4.tar.gz -------------------------------------------------------------------------------- /dist/nonebot_plugin_addFriend-2.2.5.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ziru-w/nonebot_plugin_addFriend/6f13017c532b7d6edd78585ab8edbd48651613a8/dist/nonebot_plugin_addFriend-2.2.5.tar.gz -------------------------------------------------------------------------------- /dist/nonebot_plugin_addFriend-2.3.0.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ziru-w/nonebot_plugin_addFriend/6f13017c532b7d6edd78585ab8edbd48651613a8/dist/nonebot_plugin_addFriend-2.3.0.tar.gz -------------------------------------------------------------------------------- /dist/nonebot_plugin_addFriend-2.3.2.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ziru-w/nonebot_plugin_addFriend/6f13017c532b7d6edd78585ab8edbd48651613a8/dist/nonebot_plugin_addFriend-2.3.2.tar.gz -------------------------------------------------------------------------------- /dist/nonebot_plugin_addFriend-2.3.3.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ziru-w/nonebot_plugin_addFriend/6f13017c532b7d6edd78585ab8edbd48651613a8/dist/nonebot_plugin_addFriend-2.3.3.tar.gz -------------------------------------------------------------------------------- /dist/nonebot_plugin_addFriend-2.4.0.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ziru-w/nonebot_plugin_addFriend/6f13017c532b7d6edd78585ab8edbd48651613a8/dist/nonebot_plugin_addFriend-2.4.0.tar.gz -------------------------------------------------------------------------------- /dist/nonebot_plugin_addFriend-2.4.1.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ziru-w/nonebot_plugin_addFriend/6f13017c532b7d6edd78585ab8edbd48651613a8/dist/nonebot_plugin_addFriend-2.4.1.tar.gz -------------------------------------------------------------------------------- /dist/nonebot_plugin_addfriend-2.4.2-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ziru-w/nonebot_plugin_addFriend/6f13017c532b7d6edd78585ab8edbd48651613a8/dist/nonebot_plugin_addfriend-2.4.2-py3-none-any.whl -------------------------------------------------------------------------------- /dist/nonebot_plugin_addfriend-2.4.2.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ziru-w/nonebot_plugin_addFriend/6f13017c532b7d6edd78585ab8edbd48651613a8/dist/nonebot_plugin_addfriend-2.4.2.tar.gz -------------------------------------------------------------------------------- /dist/nonebot_plugin_addfriend-2.4.3-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ziru-w/nonebot_plugin_addFriend/6f13017c532b7d6edd78585ab8edbd48651613a8/dist/nonebot_plugin_addfriend-2.4.3-py3-none-any.whl -------------------------------------------------------------------------------- /dist/nonebot_plugin_addfriend-2.4.3.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ziru-w/nonebot_plugin_addFriend/6f13017c532b7d6edd78585ab8edbd48651613a8/dist/nonebot_plugin_addfriend-2.4.3.tar.gz -------------------------------------------------------------------------------- /dist/nonebot_plugin_addfriend-2.4.4-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ziru-w/nonebot_plugin_addFriend/6f13017c532b7d6edd78585ab8edbd48651613a8/dist/nonebot_plugin_addfriend-2.4.4-py3-none-any.whl -------------------------------------------------------------------------------- /dist/nonebot_plugin_addfriend-2.4.4.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ziru-w/nonebot_plugin_addFriend/6f13017c532b7d6edd78585ab8edbd48651613a8/dist/nonebot_plugin_addfriend-2.4.4.tar.gz -------------------------------------------------------------------------------- /dist/nonebot_plugin_addfriend-2.4.5-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ziru-w/nonebot_plugin_addFriend/6f13017c532b7d6edd78585ab8edbd48651613a8/dist/nonebot_plugin_addfriend-2.4.5-py3-none-any.whl -------------------------------------------------------------------------------- /dist/nonebot_plugin_addfriend-2.4.5.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ziru-w/nonebot_plugin_addFriend/6f13017c532b7d6edd78585ab8edbd48651613a8/dist/nonebot_plugin_addfriend-2.4.5.tar.gz -------------------------------------------------------------------------------- /dist/nonebot_plugin_addfriend-2.4.6-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ziru-w/nonebot_plugin_addFriend/6f13017c532b7d6edd78585ab8edbd48651613a8/dist/nonebot_plugin_addfriend-2.4.6-py3-none-any.whl -------------------------------------------------------------------------------- /dist/nonebot_plugin_addfriend-2.4.6.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ziru-w/nonebot_plugin_addFriend/6f13017c532b7d6edd78585ab8edbd48651613a8/dist/nonebot_plugin_addfriend-2.4.6.tar.gz -------------------------------------------------------------------------------- /dist/nonebot_plugin_addfriend-2.4.7-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ziru-w/nonebot_plugin_addFriend/6f13017c532b7d6edd78585ab8edbd48651613a8/dist/nonebot_plugin_addfriend-2.4.7-py3-none-any.whl -------------------------------------------------------------------------------- /dist/nonebot_plugin_addfriend-2.4.7.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ziru-w/nonebot_plugin_addFriend/6f13017c532b7d6edd78585ab8edbd48651613a8/dist/nonebot_plugin_addfriend-2.4.7.tar.gz -------------------------------------------------------------------------------- /dist/nonebot_plugin_addfriend-2.5.0-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ziru-w/nonebot_plugin_addFriend/6f13017c532b7d6edd78585ab8edbd48651613a8/dist/nonebot_plugin_addfriend-2.5.0-py3-none-any.whl -------------------------------------------------------------------------------- /dist/nonebot_plugin_addfriend-2.5.0.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ziru-w/nonebot_plugin_addFriend/6f13017c532b7d6edd78585ab8edbd48651613a8/dist/nonebot_plugin_addfriend-2.5.0.tar.gz -------------------------------------------------------------------------------- /dist/nonebot_plugin_addfriend-2.5.1-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ziru-w/nonebot_plugin_addFriend/6f13017c532b7d6edd78585ab8edbd48651613a8/dist/nonebot_plugin_addfriend-2.5.1-py3-none-any.whl -------------------------------------------------------------------------------- /dist/nonebot_plugin_addfriend-2.5.1.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ziru-w/nonebot_plugin_addFriend/6f13017c532b7d6edd78585ab8edbd48651613a8/dist/nonebot_plugin_addfriend-2.5.1.tar.gz -------------------------------------------------------------------------------- /dist/nonebot_plugin_addfriend-2.5.2-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ziru-w/nonebot_plugin_addFriend/6f13017c532b7d6edd78585ab8edbd48651613a8/dist/nonebot_plugin_addfriend-2.5.2-py3-none-any.whl -------------------------------------------------------------------------------- /dist/nonebot_plugin_addfriend-2.5.2.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ziru-w/nonebot_plugin_addFriend/6f13017c532b7d6edd78585ab8edbd48651613a8/dist/nonebot_plugin_addfriend-2.5.2.tar.gz -------------------------------------------------------------------------------- /dist/nonebot_plugin_addfriend-2.5.3-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ziru-w/nonebot_plugin_addFriend/6f13017c532b7d6edd78585ab8edbd48651613a8/dist/nonebot_plugin_addfriend-2.5.3-py3-none-any.whl -------------------------------------------------------------------------------- /dist/nonebot_plugin_addfriend-2.5.3.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ziru-w/nonebot_plugin_addFriend/6f13017c532b7d6edd78585ab8edbd48651613a8/dist/nonebot_plugin_addfriend-2.5.3.tar.gz -------------------------------------------------------------------------------- /dist/nonebot_plugin_addfriend-2.5.4-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ziru-w/nonebot_plugin_addFriend/6f13017c532b7d6edd78585ab8edbd48651613a8/dist/nonebot_plugin_addfriend-2.5.4-py3-none-any.whl -------------------------------------------------------------------------------- /dist/nonebot_plugin_addfriend-2.5.4.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ziru-w/nonebot_plugin_addFriend/6f13017c532b7d6edd78585ab8edbd48651613a8/dist/nonebot_plugin_addfriend-2.5.4.tar.gz -------------------------------------------------------------------------------- /dist/nonebot_plugin_addfriend-2.5.5-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ziru-w/nonebot_plugin_addFriend/6f13017c532b7d6edd78585ab8edbd48651613a8/dist/nonebot_plugin_addfriend-2.5.5-py3-none-any.whl -------------------------------------------------------------------------------- /dist/nonebot_plugin_addfriend-2.5.5.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ziru-w/nonebot_plugin_addFriend/6f13017c532b7d6edd78585ab8edbd48651613a8/dist/nonebot_plugin_addfriend-2.5.5.tar.gz -------------------------------------------------------------------------------- /dist/nonebot_plugin_addfriend-2.5.6-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ziru-w/nonebot_plugin_addFriend/6f13017c532b7d6edd78585ab8edbd48651613a8/dist/nonebot_plugin_addfriend-2.5.6-py3-none-any.whl -------------------------------------------------------------------------------- /dist/nonebot_plugin_addfriend-2.5.6.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ziru-w/nonebot_plugin_addFriend/6f13017c532b7d6edd78585ab8edbd48651613a8/dist/nonebot_plugin_addfriend-2.5.6.tar.gz -------------------------------------------------------------------------------- /nonebot_plugin_addFriend.egg-info/PKG-INFO: -------------------------------------------------------------------------------- 1 | Metadata-Version: 2.1 2 | Name: nonebot-plugin-addFriend 3 | Version: 2.4.1 4 | Summary: A plugin based on nonebot2, which is used to process requests to add QQ friends and QQ requests. 5 | Home-page: https://github.com/ziru-w/nonebot_plugin_addFriend 6 | Author: wziru 7 | License: UNKNOWN 8 | Project-URL: Bug Tracker, https://github.com/ziru-w/nonebot_plugin_addFriend/issues 9 | Platform: UNKNOWN 10 | Classifier: Programming Language :: Python :: 3 11 | Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3) 12 | Classifier: Operating System :: OS Independent 13 | Requires-Python: >=3.7 14 | Description-Content-Type: text/markdown 15 | License-File: LICENSE 16 | 17 | # nonebot_plugin_addFriend 18 | 一个基于NoneBot2的插件,用于处理被请求加QQ好友和QQ群的请求 19 | 20 | 21 | A plug-in based on nonebot2, which is used to process the request to add QQ friends and QQ groups 22 | 23 | 24 | 下载方法 pip install nonebot_plugin_addFriend 25 | 26 | 1.该插件运行后会检查配置文件是否存在,并生成默认配置,也可手动复制内容创建文件,创建路径为插件目录,文件名为config.json,其中.json为后缀名,表征文件类型,请不要创建为config.json.json文件, 27 | 28 | 命令起始符列表最好不要是空的,起始符最好长度都一样,不一样请更改parseDifferentCommandStart()函数以调和统一不一样的命令起始符,因为我用的切片去除起始符,闲了看看别人咋处理的,欸嘿 29 | 30 | 2.可自行设置是否同意自动加好友,命令为/更改自动同意群聊 1或0、/更改自动同意好友 1或0、/更改自动同意 1或0 1或0 31 | 32 | 同时,也可以重置当日好友请求的数量 /重置好友请求 数量(不写默认重置日被请求加好友、群次数为零,后缀数字则会重置为该数值), 33 | 34 | 3.该插件会检查添加好友、群的请求,同意自动添加则自动,上限默认为一日五个,下次收到请求时会检查时间不是一天会重置日被请求加好友、群次数,并向插件指定qq号发送提示, 35 | 36 | 4.不同意则保存记录等待命令/同意加 qq号或群号,/拒绝加 qq号或群号,/查看加 查看数量(可不填,默认为配置中的最大值) 37 | 38 | 5./添加请求接收者 /删除请求接收者 此二者用来添加好友请求处理人,默认配置为前2个超管。 39 | 40 | 6./更改最大日加好友数量 数量(正整数) /更改查看加返回数量 数量 (非负整数,<120) /重载配置 重新载入配置文件数据 用于直接修改文件后的重载问题 41 | 42 | 7./设置群成员更易通知 已开时会关闭、已关会开 群号自动获取为当前群 43 | 44 | 8./设置bot私聊转发 45 | 46 | 9.黑名单群聊与警告群聊、黑名单群名与警告群名,一个直接拒绝、一个不自动同意,含黑名单、警告词或群号时生效,可以同时转发拉人头兼职群群聊发起者给配置过的好友,一般是该群管理员,暂无机器人接口、请于本插件目录下config.json文件中手动配置 47 | 48 | 配置项结构 49 | 50 | { 51 | "agreeAutoApprove": { "friend": 1, "group": 0 }, 52 | "maxNum": 5, 53 | "maxViewNum":20, 54 | "recipientList": [], 55 | "groupMemberNumNoticeList":[], 56 | "forwardSet":1, 57 | "botName": "我", 58 | "friend_msg": { 59 | "notice_msg": "请求添加好友,验证消息为", 60 | "welcome_msg": "我未知的的朋友啊,很高兴你添加我为qq好友哦!\n同时,如果有疑问,可以发送/help哦" 61 | }, 62 | "group_msg": { 63 | "notice_msg": "发送群邀请,验证消息为", 64 | "welcome_msg": "我亲爱的的朋友啊,很高兴你邀请我哦!" 65 | } 66 | } 67 | 68 | 69 | -------------------------------------------------------------------------------- /nonebot_plugin_addFriend.egg-info/SOURCES.txt: -------------------------------------------------------------------------------- 1 | LICENSE 2 | README.md 3 | setup.py 4 | nonebot_plugin_addFriend/__init__.py 5 | nonebot_plugin_addFriend/configUtil.py 6 | nonebot_plugin_addFriend/utils.py 7 | nonebot_plugin_addFriend.egg-info/PKG-INFO 8 | nonebot_plugin_addFriend.egg-info/SOURCES.txt 9 | nonebot_plugin_addFriend.egg-info/dependency_links.txt 10 | nonebot_plugin_addFriend.egg-info/requires.txt 11 | nonebot_plugin_addFriend.egg-info/top_level.txt -------------------------------------------------------------------------------- /nonebot_plugin_addFriend.egg-info/dependency_links.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /nonebot_plugin_addFriend.egg-info/requires.txt: -------------------------------------------------------------------------------- 1 | nonebot-adapter-onebot>=2.0.0-beta.1 2 | nonebot2>=2.0.0-beta.1 3 | nonebot_plugin_txt2img 4 | -------------------------------------------------------------------------------- /nonebot_plugin_addFriend.egg-info/top_level.txt: -------------------------------------------------------------------------------- 1 | nonebot_plugin_addFriend 2 | -------------------------------------------------------------------------------- /nonebot_plugin_addFriend/__init__.py: -------------------------------------------------------------------------------- 1 | # python3 2 | # -*- coding: utf-8 -*- 3 | # @Time : 2021/2/15 16:49 4 | # @Author : wziru 5 | # @File : __init__.py.py 6 | # @Software: PyCharm 7 | 8 | from datetime import datetime 9 | import json 10 | 11 | import re 12 | from asyncio import sleep 13 | from os.path import dirname,exists 14 | from typing import Union 15 | from nonebot import on_command,on_request,on_notice,require 16 | from nonebot.adapters.onebot.v11 import Bot, MessageEvent,PrivateMessageEvent,GroupMessageEvent, MessageSegment,RequestEvent,GroupRequestEvent, FriendRequestEvent,NoticeEvent,GroupDecreaseNoticeEvent,GroupIncreaseNoticeEvent 17 | from nonebot.message import event_preprocessor 18 | from nonebot import get_driver 19 | from nonebot.permission import SUPERUSER 20 | from nonebot.adapters.onebot.v11.permission import GROUP_ADMIN, GROUP_OWNER 21 | from nonebot.params import CommandArg 22 | from nonebot.adapters import Message 23 | from .configUtil import check_dict_key_bot_id, config,requestorDict,basedir,configPath,requestorDictPath,writeData,blackLogPath,numDict,numDictPath 24 | from .utils import getReferIdList,sendMsg,getExist,parseMsg,isNormalAdd,writeLog,filterFriend,parseTime,writeTime 25 | # try: 26 | # scheduler = require('nonebot_plugin_apscheduler').scheduler 27 | # except: 28 | # import nonebot_plugin_apscheduler 29 | # scheduler = nonebot_plugin_apscheduler.scheduler 30 | 31 | 32 | #初始化完毕,num文件单独初始化 33 | parseRequest = on_request(priority=1, block=True) 34 | # @event_preprocessor 35 | @parseRequest.handle() 36 | async def _(bot: Bot, event: RequestEvent): 37 | check_dict_key_bot_id(config,requestorDict,numDict,bot) 38 | now=datetime.now() 39 | time=str(now) 40 | if isinstance(event,FriendRequestEvent): 41 | notice_msg=config[bot.self_id]["friend_msg"]["notice_msg"] 42 | welcome_msg=config[bot.self_id]["friend_msg"]["welcome_msg"] 43 | id = str(event.user_id) 44 | autoType='friend' 45 | agreeAutoApprove=config[bot.self_id]['agreeAutoApprove'][autoType] 46 | addInfo=await bot.get_stranger_info(user_id=int(id),no_cache=True) 47 | msg=id+notice_msg+event.comment+'\n时间:{}'.format(time) 48 | elif isinstance(event,GroupRequestEvent): 49 | if event.sub_type!='invite': 50 | print(event.sub_type) 51 | return 52 | print(event.sub_type) 53 | notice_msg=config[bot.self_id]["group_msg"]["notice_msg"] 54 | welcome_msg=config[bot.self_id]["group_msg"]["welcome_msg"] 55 | id = str(event.group_id) 56 | autoType='group' 57 | agreeAutoApprove=config[bot.self_id]['agreeAutoApprove'][autoType] 58 | await sleep(0.5) 59 | try: 60 | addInfo=await bot.get_group_info(group_id=event.group_id,no_cache=True) 61 | except Exception as res: 62 | print("nonebot_plugin_addFriend/init.py61行\n",res) 63 | addInfo={"member_count":0,"max_member_count":0,"group_name":"略过","group_id":event.group_id} 64 | print(autoType,addInfo,agreeAutoApprove) 65 | msg='群号'+id+','+event.get_user_id()+notice_msg+event.comment+'\n时间:{}'.format(time) 66 | if addInfo["member_count"]!=0: 67 | status='\n或因群人数少,已经添加成功' 68 | await sendMsg(bot,config[bot.self_id]['recipientList'],msg+status,0) 69 | await bot.send_private_msg(user_id=event.user_id, message=welcome_msg) 70 | return 71 | else: 72 | return 73 | # num,now,old=read_data(numPath,autoType) 74 | agreeAutoApprove,status=isNormalAdd(config[bot.self_id],autoType,addInfo,agreeAutoApprove) #正常添加判断,过滤无意义添加,类似xx通知群 75 | if agreeAutoApprove==-1: #黑名单结果 76 | await event.reject(bot) 77 | await sendMsg(bot,config[bot.self_id]['recipientList'],msg+status,0) #黑名单警告,转发给设定的人 78 | forwardId=config[bot.self_id]["blackDict"]["forward"].get(id) 79 | if forwardId!=None and autoType=="group": 80 | friendList=await getReferIdList(bot,'user_id') 81 | if forwardId in friendList: 82 | await bot.send_private_msg(user_id=forwardId,message=msg+status) 83 | else: 84 | del config[bot.self_id]["blackDict"]["forward"][id] 85 | writeLog(blackLogPath,msg+status+'\n') 86 | return 87 | if not filterFriend(event.comment,autoType,config[bot.self_id]['allowAddFriednText']): #验证信息 88 | status='\n未通过验证消息,已拒绝' 89 | await sendMsg(bot,config[bot.self_id]['recipientList'],msg+status,0)#不记录 90 | await event.reject(bot) 91 | return 92 | num=parseTime(config[bot.self_id]['numControl'],numDict[bot.self_id][autoType],now) 93 | if agreeAutoApprove==0 or num==-1: 94 | if num==-1: 95 | status='\n此时增满{}人,未能再自动添加'.format(config[bot.self_id]['numControl']['maxNum']) 96 | else: 97 | status='\n未允许自动添加' 98 | requestorDict[bot.self_id][autoType][id]={'flag':event.flag,'comment':event.comment,"notice_msg":notice_msg,'staus':status,'requestorId':event.user_id,'time':time} 99 | writeData(requestorDictPath,requestorDict) 100 | await sendMsg(bot,config[bot.self_id]['recipientList'],msg+status,0) 101 | else: 102 | #既自动添加又条件合适 103 | writeTime(numDictPath,numDict) 104 | await event.approve(bot) 105 | await sendMsg(bot,config[bot.self_id]['recipientList'],msg+status,0) 106 | #等待腾讯服务器更新 107 | await sleep(1.5) 108 | await bot.send_private_msg(user_id=event.user_id, message=welcome_msg) 109 | 110 | 111 | 112 | againReadConfig= on_command("重载配置",aliases={"更改自动同意","更改最大加数量","更改加时间","更改加时间单位","更改查看加返回数量"},priority=5,block=True,permission=SUPERUSER) 113 | @againReadConfig.handle() 114 | async def _(bot: Bot, event: MessageEvent,args: Message = CommandArg()): 115 | global config 116 | #下个版本把其他俩json也重载一下,不知道为啥这次就不想改 117 | with open(configPath,'r',encoding='utf-8') as fp: 118 | config=json.loads(fp.read()) 119 | check_dict_key_bot_id(config,requestorDict,numDict,bot) 120 | text=event.get_plaintext().strip() 121 | argsText=args.extract_plain_text().strip() 122 | commandText=getExist('',text,argsText) 123 | print(argsText) 124 | if '群聊' in argsText: 125 | argsText=argsText.replace('群聊','').strip() 126 | autoType='group' 127 | elif '好友' in argsText: 128 | argsText=argsText.replace('好友','').strip() 129 | autoType='friend' 130 | else: 131 | autoType='all' 132 | if "更改自动同意" in commandText: 133 | print(1) 134 | if argsText.isdigit() and autoType!='all': 135 | if int(argsText)>0: 136 | config[bot.self_id]['agreeAutoApprove'][autoType]=1 137 | else: 138 | config[bot.self_id]['agreeAutoApprove'][autoType]=0 139 | elif autoType=='all': 140 | setList=argsText.split() 141 | i=0 142 | setKeyList=list(config[bot.self_id]['agreeAutoApprove'].keys()) 143 | for set in setList[:2]: 144 | if set.isdigit(): 145 | if int(set)>0: 146 | config[bot.self_id]['agreeAutoApprove'][setKeyList[i]]=1 147 | else: 148 | config[bot.self_id]['agreeAutoApprove'][setKeyList[i]]=0 149 | i+=1 150 | else: 151 | await againReadConfig.finish('格式') 152 | resMsg='更改成功,为\n{}'.format(config[bot.self_id]['agreeAutoApprove']) 153 | 154 | elif "更改最大加数量" in commandText: 155 | print(2) 156 | if argsText.isdigit(): 157 | maxNum=int(argsText) 158 | if maxNum>0: 159 | config[bot.self_id]['numControl'][autoType]['maxNum']=maxNum 160 | else: 161 | config[bot.self_id]['numControl'][autoType]['maxNum']=0 162 | resMsg='更改成功,为{}'.format(config[bot.self_id]['numControl'][autoType]['maxNum']) 163 | elif "更改最大加时间" in commandText: 164 | print(2) 165 | if argsText.isdigit(): 166 | time=int(argsText) 167 | if time>0: 168 | config[bot.self_id]['numControl'][autoType]['time']=time 169 | resMsg='更改成功,为{}'.format(config[bot.self_id]['numControl'][autoType]['time']) 170 | elif "更改加时间单位" in commandText: 171 | print(argsText,1) 172 | if '时' in argsText: 173 | config[bot.self_id]['numControl'][autoType]['unit']='h' 174 | elif '分' in argsText: 175 | config[bot.self_id]['numControl'][autoType]['unit']='m' 176 | else: 177 | config[bot.self_id]['numControl'][autoType]['unit']='d' 178 | resMsg='更改成功,为{}'.format(config[bot.self_id]['numControl'][autoType]['unit']) 179 | elif "更改查看加返回数量" in commandText: 180 | print(3) 181 | if argsText.isdigit(): 182 | maxViewNum=int(argsText) 183 | if maxViewNum>0 and maxViewNum<120: 184 | config[bot.self_id]['maxViewNum']=maxViewNum 185 | resMsg='更改成功,为\n{}'.format(config[bot.self_id]['maxViewNum']) 186 | else: 187 | print(4) 188 | resMsg='重载成功:\n{}'.format(config[bot.self_id]) 189 | if '重载配置' not in commandText: 190 | writeData(configPath,config) 191 | resMsg=await parseMsg(commandText,resMsg) 192 | await againReadConfig.finish(resMsg) 193 | 194 | 195 | addFriend = on_command("同意加",aliases={'拒绝加','查看加'},priority=5,block=True) 196 | @addFriend.handle() 197 | async def _(bot: Bot, event: MessageEvent,args: Message = CommandArg()): 198 | check_dict_key_bot_id(config,requestorDict,numDict,bot) 199 | if event.get_user_id() not in config[bot.self_id]['recipientList']: 200 | await addFriend.finish('无权限') 201 | text=event.get_plaintext().strip() 202 | argsText=args.extract_plain_text().strip() 203 | commandText=getExist("",text,argsText) 204 | print(argsText) 205 | if '群' in argsText: 206 | autoType='group' 207 | argsText=argsText.replace("群聊","").replace("群","").strip() 208 | else: 209 | argsText=argsText.replace("好友","").strip() 210 | autoType='friend' 211 | if "同意加" in commandText: 212 | approve=True 213 | status='添加成功' 214 | elif '拒绝' in commandText: 215 | approve=False 216 | status='拒绝成功' 217 | else: 218 | num=argsText 219 | if num.isdigit(): 220 | num=int(num) 221 | else: 222 | num=config[bot.self_id]['maxViewNum'] 223 | requestorValueList=list(requestorDict[bot.self_id][autoType].items())[:num] 224 | requestorInfos=str(requestorValueList) 225 | print(autoType,requestorInfos) 226 | resMsg=await parseMsg(commandText,requestorInfos) 227 | print(resMsg) 228 | await addFriend.finish(resMsg) 229 | if argsText=='': 230 | await addFriend.finish('格式') 231 | # 预处理完毕,开始设置参数 232 | QQOrGroupId=argsText.split()[0] 233 | print(QQOrGroupId) 234 | if requestorDict[bot.self_id][autoType].get(QQOrGroupId)==None: 235 | await addFriend.finish('没有此请求') 236 | 237 | flag=requestorDict[bot.self_id][autoType][QQOrGroupId]['flag'] 238 | notice_msg=requestorDict[bot.self_id][autoType][QQOrGroupId]['notice_msg'] 239 | comment=requestorDict[bot.self_id][autoType][QQOrGroupId]['comment'] 240 | requestorId=requestorDict[bot.self_id][autoType][QQOrGroupId]['requestorId'] 241 | time=requestorDict[bot.self_id][autoType][QQOrGroupId]['time'] 242 | # 参数设置完毕,开始处理请求 243 | try: 244 | if autoType=="group": 245 | resMsg='群号{},邀请者{}'.format(QQOrGroupId,requestorId)+notice_msg+comment+'\n时间:{}\n'.format(time) 246 | msgType='group_msg' 247 | groupList=await getReferIdList(bot) 248 | 249 | if int(QQOrGroupId) in groupList: 250 | print(1) 251 | status='已经添加成功,勿复添加' 252 | else: 253 | print(2) 254 | await bot.set_group_add_request(flag=flag,approve=approve) 255 | else: 256 | resMsg=QQOrGroupId+notice_msg+comment+'\n{}\n'.format(time) 257 | msgType='friend_msg' 258 | friendList=await getReferIdList(bot,'user_id') 259 | if int(QQOrGroupId) in friendList: 260 | status='已经添加成功,勿复添加' 261 | else: 262 | if len(argsText)>=2 and argsText[1]!='' and approve==True: 263 | remark=argsText[1] 264 | # 备注似乎无用 265 | await bot.set_friend_add_request(flag=flag,approve=approve,remark=remark) 266 | else: 267 | await bot.set_friend_add_request(flag=flag,approve=approve) 268 | except: 269 | status='为何手动添加而后又删好友或退群又来这里同意?' 270 | finally: 271 | # 请求处理完毕,开始更易数据 272 | del requestorDict[bot.self_id][autoType][QQOrGroupId] 273 | writeData(requestorDictPath,requestorDict) 274 | resMsg+=status 275 | # 数据更易完毕,开始用户交互,返回结果,发送欢迎 276 | await addFriend.send(resMsg) 277 | # await bot.send_private_msg(user_id=event.user_id, message=resMsg) 278 | # await sendMsg(bot,config[bot.self_id]['recipientList'],resMsg,0) 279 | if status=='添加成功': 280 | # 等待腾讯数据更新 281 | await sleep(1.5) 282 | welcome_msg=config[bot.self_id][msgType]['welcome_msg'] 283 | await bot.send_private_msg(user_id=requestorId, message=welcome_msg) 284 | 285 | # @scheduler.scheduled_job('interval', hour=1, id='check_outdate', timezone="Asia/Shanghai") 286 | delRequestorDict = on_command("清理请求表",priority=5, block=True,permission=SUPERUSER) 287 | @delRequestorDict.handle() 288 | async def check_outdate(bot:Bot, event: MessageEvent): 289 | check_dict_key_bot_id(config,requestorDict,numDict,bot) 290 | delList=[] 291 | for requestorType in requestorDict: 292 | if requestorType!='friend': 293 | ReferIdList=await getReferIdList(bot,'group_id') 294 | else: 295 | ReferIdList=await getReferIdList(bot,'user_id') 296 | requestorList=list(requestorDict[bot.self_id][requestorType]) 297 | print(ReferIdList) 298 | for requestor in requestorList: 299 | if int(requestor) in ReferIdList: 300 | delList.append(requestor) 301 | del requestorDict[bot.self_id][requestorType][requestor] 302 | writeData(requestorDictPath,requestorDict) 303 | msg='已清理如下:\n'+str(delList)[1:-1].replace(', ',' ') 304 | await delRequestorDict.send(msg) 305 | 306 | 307 | reFriendReqNum = on_command("重置请求次数",block=True,priority=5,permission=SUPERUSER) 308 | @reFriendReqNum.handle() 309 | async def _(bot: Bot, event: MessageEvent,args: Message = CommandArg()): 310 | check_dict_key_bot_id(config,requestorDict,numDict,bot) 311 | # text=event.get_plaintext().strip() 312 | argsText=args.extract_plain_text().strip() 313 | if '群聊' in argsText: 314 | argsText=argsText.replace('群聊','').strip() 315 | autoType='group' 316 | elif '好友' in argsText: 317 | argsText=argsText.replace('好友','').strip() 318 | autoType='friend' 319 | else: 320 | autoType='all' 321 | max=config[bot.self_id]['numControl'][autoType]['maxNum'] 322 | now=datetime.now() 323 | # num,now,old=read_data(numPath) 324 | if parseTime(config[bot.self_id]['numControl'][autoType],numDict[bot.self_id][autoType],now)!=-1: 325 | await reFriendReqNum.send(message='未增满{}人,人数为{}上次添加时间{}'.format(max,numDict[bot.self_id][autoType]['count'],now)) 326 | argsText=argsText.replace('为','').strip() 327 | if argsText.isdigit(): 328 | numDict[bot.self_id][autoType]['count']=int(argsText) 329 | else: 330 | numDict[bot.self_id][autoType]['count']=0 331 | numDict[bot.self_id][autoType]['time']=now 332 | writeTime(numDictPath,numDict) 333 | await reFriendReqNum.finish('重置成功,为{}'.format(numDict[bot.self_id][autoType]['count'])) 334 | 335 | addRecipient = on_command("添加请求接收者",aliases={"删除请求接收者"},block=True,priority=5,permission=SUPERUSER) 336 | @addRecipient.handle() 337 | async def _(bot: Bot, event: MessageEvent,args: Message = CommandArg()): 338 | check_dict_key_bot_id(config,requestorDict,numDict,bot) 339 | friend_list=await getReferIdList(bot,'user_id') 340 | print(friend_list) 341 | text=event.get_plaintext().strip() 342 | argsText=args.extract_plain_text() 343 | recipient=argsText 344 | if recipient=='': 345 | await addRecipient.send('格式') 346 | if int(recipient) in friend_list: 347 | if getExist('添加',text,argsText): 348 | op='添加' 349 | if recipient not in config[bot.self_id]['recipientList']: 350 | config[bot.self_id]['recipientList'].append(recipient) 351 | else: 352 | op='删除' 353 | if recipient in config[bot.self_id]['recipientList']: 354 | config[bot.self_id]['recipientList'].remove(recipient) 355 | writeData(configPath,config) 356 | await addRecipient.send(op+'{}成功'.format(recipient)) 357 | else: 358 | await addRecipient.finish('不是{}的好友或者格式错误'.format(config[bot.self_id]['botName'])) 359 | 360 | friendHelp=on_command("加好友帮助",block=True,priority=5,permission=SUPERUSER) 361 | @friendHelp.handle() 362 | async def _(bot: Bot, event: MessageEvent): 363 | msg='重载配置\n更改自动同意,更改最大加数量,更改查看加返回数量,更改加时间,更改加时间单位(群聊、好友)\n同意加,拒绝加,查看加(群聊、好友)\n清理请求表\n重置请求次数(群聊、好友)\n添加请求接收者,删除请求接收者' 364 | await friendHelp.send(msg) 365 | 366 | 367 | 368 | # agreeForward = on_command("设置bot私聊转发",block=True,priority=5,permission=SUPERUSER) 369 | # @agreeForward.handle() 370 | # async def _(bot: Bot, event: MessageEvent): 371 | # check_dict_key_bot_id(config,requestorDict,numDict,bot) 372 | # # forwardSet=config[bot.self_id]['forwardSet'] 373 | # if config[bot.self_id]['forwardSet']==0: 374 | # config[bot.self_id]['forwardSet']=1 375 | # msg='开启成功哦' 376 | # else: 377 | # config[bot.self_id]['forwardSet']=0 378 | # msg='关闭成功哦' 379 | # writeData(configPath,config) 380 | # await agreeForward.send(msg) 381 | 382 | # msgControl=[0,datetime.now(),1] 383 | # @event_preprocessor 384 | # async def sendPrivate(bot:Bot,event: PrivateMessageEvent): 385 | # check_dict_key_bot_id(config,requestorDict,numDict,bot) 386 | # if config[bot.self_id]['recipientList']==[] or config[bot.self_id]['forwardSet']==0: 387 | # return 388 | # if msgControl[2]==0: # 389 | # if (datetime.now()-msgControl[1]).seconds>20: 390 | # msgControl[2]=1 391 | # else: 392 | # return 393 | # msgControl[0]+=1 394 | # if msgControl[0]/((datetime.now()-msgControl[1]).seconds+1)>10: 395 | # msgControl[2]=0 396 | # msgControl[1]=datetime.now() 397 | # msgControl[0]=0 398 | # if event.get_user_id()!=config[bot.self_id]['recipientList'][0]: 399 | # plaintext=event.get_message() 400 | # await bot.send_private_msg(user_id=int(config[bot.self_id]['recipientList'][0]),message='叮~私聊消息\nqq:{}\n昵称:{}\n消息:{}'.format(event.user_id,event.sender.nickname,plaintext),auto_escape=False) 401 | 402 | 403 | 404 | 405 | -------------------------------------------------------------------------------- /nonebot_plugin_addFriend/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ziru-w/nonebot_plugin_addFriend/6f13017c532b7d6edd78585ab8edbd48651613a8/nonebot_plugin_addFriend/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /nonebot_plugin_addFriend/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "机器人qq": { 3 | "agreeAutoApprove": { "friend": 1, "group": 0 }, 4 | "recipientList": [], 5 | "forwardSet": 0, 6 | "numControl": { 7 | "useAlgorithm": 0, 8 | "maxNum": 6, 9 | "time": 2, 10 | "unit": "h", 11 | "friend": { "maxNum": 6, "time": 2, "unit": "h" }, 12 | "group": { "maxNum": 2, "time": 8, "unit": "h" } 13 | }, 14 | "maxViewNum": 20, 15 | "blackDict": { 16 | "friend": { "text": [], "id": [] }, 17 | "group": { "text": [], "id": [] }, 18 | "forward": {} 19 | }, 20 | "warnDict": { 21 | "friend": { "text": [], "id": [] }, 22 | "group": { "text": [], "id": [] }, 23 | "forward": {} 24 | }, 25 | "allowAddFriednText": [], 26 | "botName": "我", 27 | "friend_msg": { 28 | "notice_msg": "请求添加好友,验证消息为", 29 | "welcome_msg": "我未知的的朋友啊,很高兴你添加我为qq好友哦!\n同时,如果有疑问,可以发送/help哦" 30 | }, 31 | "group_msg": { 32 | "notice_msg": "发送群邀请,验证消息为", 33 | "welcome_msg": "我亲爱的的朋友啊,很高兴你邀请我哦!" 34 | }, 35 | "statusDict": { 36 | "blackDict": { 37 | "friend": { "status": "拉黑QQ,已拒绝,仅作提示" }, 38 | "group": { "status": "拉黑群聊,已拒绝,仅作提示" } 39 | }, 40 | "warnDict": { 41 | "friend": { "status": "警告QQ,手动同意,是否同意" }, 42 | "group": { "status": "警告群聊,手动同意,是否同意" } 43 | } 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /nonebot_plugin_addFriend/configUtil.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | import copy 5 | from datetime import datetime 6 | from os.path import dirname,exists 7 | from nonebot import get_driver 8 | import json 9 | from nonebot.adapters.onebot.v11 import Bot 10 | from .utils import writeTime 11 | basedir = dirname(__file__) 12 | # numDictPath=basedir+'/num.txt' 13 | configPath=basedir+'/config.json' 14 | requestorDictPath=basedir+'/requestor.json' 15 | numDictPath=basedir+'/num.json' 16 | max=6 17 | blackLogPath=basedir+'/blackLog.txt' 18 | 19 | def check_dict_key_bot_id(config:dict,requestorDict:dict,numDict:dict,bot: Bot): 20 | print(1) 21 | if config.get(bot.self_id)==None: 22 | config[bot.self_id]=copy.deepcopy(configModel) 23 | writeData(configPath,config) 24 | if requestorDict.get(bot.self_id)==None: 25 | requestorDict[bot.self_id]=copy.deepcopy(requestorDictModel) 26 | writeData(requestorDictPath,requestorDict) 27 | if numDict.get(bot.self_id)==None: 28 | numDict[bot.self_id]=copy.deepcopy(numDictModel) 29 | for type in numDict[bot.self_id].keys(): 30 | numDict[bot.self_id][type]["time"]=datetime.strptime(numDict[bot.self_id][type]["time"], "%Y-%m-%d %H:%M:%S.%f") 31 | writeTime(numDictPath,numDict) 32 | # return True 33 | def readData(path,content={},update=0)->dict: 34 | if not exists(path): 35 | with open(path,'w',encoding='utf-8') as fp: 36 | json.dump(content,fp,ensure_ascii=False) 37 | with open(path,'r',encoding='utf-8') as fp: 38 | data = json.loads(fp.read()) 39 | return data 40 | def writeData(path,content): 41 | with open(path,'w',encoding='utf-8') as fp: 42 | json.dump(content,fp,ensure_ascii=False) 43 | # if not exists(configPath): 44 | recipientList=list(get_driver().config.superusers) 45 | # recipients=str(recipients)[1:-1].replace(' ','').replace("'",'') 46 | # 可以在这里修改默认模板哦 47 | configModel={ 48 | "agreeAutoApprove": { "friend": 1, "group": 0 }, 49 | "recipientList": recipientList[:2], 50 | "forwardSet":0, 51 | "numControl": {"useAlgorithm":0, "maxNum": 6, "time": 2, "unit": "h" ,"friend":{"maxNum": 6, "time": 2, "unit": "h" },"group":{"maxNum": 2, "time": 8, "unit": "h" }}, 52 | "maxViewNum": 20, 53 | "blackDict":{"friend":{"text":[],"id":[]},"group":{"text":[],"id":[]},"forward":{}},#"群号":"管理员号,转发给其用来揪出在群里拉人头的人" 54 | "warnDict":{"friend":{"text":[],"id":[]},"group":{"text":[],"id":[]},"forward":{}}, 55 | "allowAddFriednText":[], 56 | "botName": "我", 57 | "friend_msg": { 58 | "notice_msg": "请求添加好友,验证消息为", 59 | "welcome_msg": "我未知的的朋友啊,很高兴你添加我为qq好友哦!\n同时,如果有疑问,可以发送/help哦" 60 | }, 61 | "group_msg": { 62 | "notice_msg": "发送群邀请,验证消息为", 63 | "welcome_msg": "我亲爱的的朋友啊,很高兴你邀请我哦!" 64 | }, 65 | "statusDict":{ 66 | "blackDict":{"friend":{"status":"拉黑QQ,已拒绝,仅作提示"},"group":{"status":"拉黑群聊,已拒绝,仅作提示"}}, 67 | "warnDict":{"friend":{"status":"警告QQ,手动同意,是否同意"},"group":{"status":"警告群聊,手动同意,是否同意"}} 68 | } 69 | } 70 | requestorDictModel={"friend":{},"group":{}} 71 | numDictModel={"friend":{"count":0,"time":str(datetime.now())},"group":{"count":0,"time":str(datetime.now())}} 72 | config=readData(configPath) 73 | requestorDict=readData(requestorDictPath) 74 | numDict=readData(numDictPath) 75 | for bot_id in numDict.keys(): 76 | for type in numDict[bot_id].keys(): 77 | numDict[bot_id][type]["time"]=datetime.strptime(numDict[bot_id][type]["time"], "%Y-%m-%d %H:%M:%S.%f") 78 | 79 | 80 | 81 | # if not exists(requestorPath): 82 | # requestorDict={} 83 | # with open(requestorPath,'w',encoding='utf-8') as fp: 84 | # json.dump(requestorDict,fp,ensure_ascii=False) 85 | 86 | # with open(requestorPath,'r',encoding='utf-8') as fp: 87 | # requestorDict=json.loads(fp.read()) 88 | # blackDictFriend=config["blackDict"]['friend'] 89 | # warnDictFriend=config["warnDict"]['friend'] 90 | # blackDictGroup=config["blackDict"]['group'] 91 | # warnDictGroup=config["warnDict"]['group'] 92 | 93 | 94 | # def updateData(path,content:dict={},update=0): 95 | # if update==0: 96 | # return content 97 | # else: 98 | # if content.get("numControl")==None: 99 | # content["numControl"]={"useAlgorithm":0, "maxNum": 5, "time": 2, "unit": "h" ,"friend":{"maxNum": 5, "time": 2, "unit": "h" },"group":{"maxNum": 2, "time": 8, "unit": "h" }} 100 | # else: 101 | # if list(content["numControl"].keys())==["maxNum", "time", "unit"]: 102 | # content["numControl"].update({"useAlgorithm":0,"friend":{"maxNum": 5, "time": 2, "unit": "h" },"group":{"maxNum": 2, "time": 8, "unit": "h" }}) 103 | # elif content.get("recipientList")!=[]: 104 | # return content 105 | # if content.get("recipientList")==[]: 106 | # content["recipientList"]=recipientList[:2] 107 | # with open(path,'w',encoding='utf-8') as fp: 108 | # json.dump(content,fp,ensure_ascii=False) 109 | # return content 110 | -------------------------------------------------------------------------------- /nonebot_plugin_addFriend/num.json: -------------------------------------------------------------------------------- 1 | { 2 | "2337759465": { 3 | "friend": { "count": 0, "time": "2023-08-28 23:55:48.151245" }, 4 | "group": { "count": 0, "time": "2023-08-28 23:55:48.151245" } 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /nonebot_plugin_addFriend/requestor.json: -------------------------------------------------------------------------------- 1 | {"2337759465": {"friend": {}, "group": {}}} -------------------------------------------------------------------------------- /nonebot_plugin_addFriend/utils.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | import copy 8 | import json 9 | from nonebot import get_driver 10 | from nonebot.adapters.onebot.v11 import Bot, MessageSegment 11 | import os 12 | import datetime 13 | 14 | 15 | # from nonebot_plugin_txt2img import Txt2Img 16 | def filterFriend(comment,type,allowTextList): 17 | if type=='friend': 18 | if allowTextList==[]: 19 | return True 20 | for allowText in allowTextList: 21 | if allowText in comment: 22 | return True 23 | return False 24 | else: 25 | return True 26 | 27 | async def parseMsg(commandText,resMsg,font_size = 32,isText=1): 28 | if type(resMsg)==list: 29 | temp='' 30 | for item in resMsg: 31 | temp+=str(item)+'\n' 32 | temp=temp.replace("'","").replace('"','') 33 | resMsg=temp 34 | return resMsg[:400] 35 | # if len(resMsg)<=300 and isText==1: 36 | # return resMsg 37 | # else: 38 | # title = commandText 39 | # img = Txt2Img(font_size) 40 | # pic = img.save(title, resMsg) 41 | # return MessageSegment.image(pic) 42 | 43 | async def getReferIdList(bot:Bot,idName='group_id',no_cache=True): 44 | '''获取朋友或群id列表''' 45 | if idName=='user_id': 46 | referInfoList=await bot.get_friend_list(no_cache=no_cache) 47 | else: 48 | idName='group_id' 49 | referInfoList=await bot.get_group_list(no_cache=no_cache) 50 | referIdList=[] 51 | for temp in referInfoList: 52 | referIdList.append(temp[idName]) 53 | return referIdList 54 | 55 | 56 | async def sendMsg(bot:Bot,recipientList,msg:str,op=0): 57 | '''群发消息''' 58 | if not isinstance(recipientList,list): 59 | if isinstance(recipientList,str) and recipientList.isdigit(): 60 | recipientList=[recipientList] 61 | else: 62 | return 63 | for recipient in recipientList: 64 | recipient=int(recipient) 65 | if op==0: 66 | await bot.send_private_msg(user_id=recipient, message=msg) 67 | else: 68 | await bot.send_group_msg(group_id=recipient, message=msg) 69 | 70 | 71 | def getExist(plainCommandtext:str,wholeMessageText:str,argsText:str): 72 | '''返回命令''' 73 | commandText=wholeMessageText[::-1].replace(argsText[::-1],'',1)[::-1].strip() 74 | if plainCommandtext=='': 75 | return commandText 76 | else: 77 | return plainCommandtext in commandText 78 | 79 | 80 | 81 | # def read_time(numPath:str)->dict: 82 | def readTime(numDict:dict)->dict: 83 | '''读时间''' 84 | # global num,now,old 85 | # if not os.path.exists(numPath): 86 | # now = datetime.datetime.now() 87 | # with open(numPath, "w", encoding="utf-8") as fp: 88 | # fp.write('1'+','+str(now)) 89 | # with open(numPath,'r',encoding='utf-8') as fp: 90 | # data_list=fp.read().split(',') 91 | # if len(data_list)<2: 92 | # now = datetime.datetime.now() 93 | # data_list=['1',str(now)] 94 | # num=int(data_list[0])sssssssss 95 | # old=datetime.datetime.strptime(data[type]["time"], "%Y-%m-%d %H:%M:%S.%f") 96 | # now = datetime.datetime.now() 97 | for id in numDict.keys(): 98 | for type in numDict[id].keys(): 99 | numDict[id][type]["time"]=datetime.datetime.strptime(numDict[id][type]["time"], "%Y-%m-%d %H:%M:%S.%f") 100 | # now = datetime.datetime.now() 101 | return numDict 102 | def writeTime(numDictPath,numDict:dict)->dict: 103 | '''写时间''' 104 | numDictTemp=copy.deepcopy(numDict) 105 | for id in numDictTemp.keys(): 106 | for type in numDictTemp[id].keys(): 107 | numDictTemp[id][type]["time"]=str(numDictTemp[id][type]["time"]) 108 | with open(numDictPath,'w',encoding='utf-8') as fp: 109 | json.dump(numDictTemp,fp,ensure_ascii=False) 110 | # now = datetime.datetime.now() 111 | return numDictTemp 112 | def writeLog(logPath,logContent): 113 | with open(logPath, "a", encoding="utf-8") as fp: 114 | fp.write(logContent) 115 | 116 | def isNormalAdd(config,autoType,addInfo,agreeAutoApprove): 117 | blackDict=config["blackDict"][autoType] 118 | warnDict=config["warnDict"][autoType] 119 | statusDict=config["statusDict"] 120 | blackStatusDict=statusDict["blackDict"][autoType] 121 | warnStatusDict=statusDict["warnDict"][autoType] 122 | if autoType=="group": 123 | name=addInfo["group_name"] 124 | id=addInfo["group_id"] 125 | else: 126 | name=addInfo["nickname"] 127 | id=addInfo["user_id"] 128 | status=blackStatusDict["status"]+"\n昵称"+name 129 | if id in blackDict["id"]: 130 | return -1,status 131 | for balckText in blackDict["text"]: 132 | if balckText in name: 133 | return -1,status 134 | status=warnStatusDict["status"]+"\n昵称{}\n是否同意".format(name) 135 | if id in warnDict["id"]: 136 | return 0,status 137 | for warnText in warnDict["text"]: 138 | if warnText in name: 139 | return 0,status 140 | if agreeAutoApprove==1: 141 | status='\nqq{}昵称{}添加成功'.format(id,name) 142 | return agreeAutoApprove,status 143 | #当初应该没在agreeAutoApprove上区分警告和非自动同意,状态里区分了 144 | status="\n昵称{}\n是否同意".format(name) 145 | return agreeAutoApprove,status 146 | 147 | 148 | def parseTimeInterval(old='2022-06-21 20:57',now='',op='int'): 149 | if isinstance(old,str): 150 | old=datetime.datetime.strptime(old, "%Y-%m-%d %H:%M:%S.%f") 151 | if now=='': 152 | now=datetime.datetime.now() 153 | elif isinstance(now,str): 154 | now=datetime.datetime.strptime(now, "%Y-%m-%d %H:%M:%S.%f") 155 | symbol=1 156 | if now.date()<=old.date(): 157 | temp=datetime.datetime.strptime(str(now.date()), "%Y-%m-%d") 158 | if (now-temp).seconds<(old-temp).seconds: 159 | temp=old 160 | old=now 161 | now=temp 162 | symbol=-1 163 | interval=now-old 164 | days=interval.days 165 | seconds=interval.seconds 166 | if op=='int': 167 | return (days*3600*24+seconds)*symbol 168 | else: 169 | return {'days':days*3600*24*symbol,'seconds':seconds*symbol} 170 | 171 | 172 | def parseTime(numControl:dict,numTypedDict,now): 173 | time=parseTimeInterval(numTypedDict["time"],now) 174 | if numControl['unit']=='h': 175 | if time/3600>numControl['time']: 176 | numTypedDict["count"]=0 177 | elif numControl['unit']=='m': 178 | if time/60>numControl['time']: 179 | numTypedDict["count"]=0 180 | else: 181 | if time/3600/24>numControl['time']: 182 | numTypedDict["count"]=0 183 | if numTypedDict["count"]>=numControl["maxNum"]: 184 | return -1 185 | else: 186 | numTypedDict["count"]=numTypedDict["count"]+1 187 | numTypedDict['time']=now 188 | return numTypedDict["count"] 189 | -------------------------------------------------------------------------------- /publish.bat: -------------------------------------------------------------------------------- 1 | poetry build 2 | poetry publish -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.poetry] 2 | name = "nonebot-plugin-addfriend" 3 | version = "2.5.6" 4 | description = "一个基于NoneBot2的插件,用于处理被请求加QQ好友和QQ群的请求.A plugin based on nonebot2, which is used to process requests to add QQ friends and QQ requests." 5 | authors = ["ziru-w <77319678+ziru-w@users.noreply.github.com>"] 6 | license = "MIT" 7 | readme = "README.md" 8 | packages = [{include = "nonebot_plugin_addfriend"}] 9 | 10 | [tool.poetry.dependencies] 11 | python = "^3.7" 12 | nonebot-adapter-onebot=">=2.0.0-beta.1" 13 | nonebot2=">=2.0.0-beta.1" 14 | 15 | [build-system] 16 | requires = ["poetry-core"] 17 | build-backend = "poetry.core.masonry.api" 18 | --------------------------------------------------------------------------------