├── .gitignore ├── .vscode ├── launch.json └── settings.json ├── LICENSE ├── README.md ├── Telegram-simple-group-admin ├── __init__.py └── __main__.py ├── assets ├── .not_empty └── imgs │ ├── image_AdDMc.png │ ├── image_AkKgx.png │ ├── image_AlwFu.png │ ├── image_Asjxn.png │ ├── image_AxMWi.png │ ├── image_BOoXI.png │ ├── image_CPeVb.png │ ├── image_CYURB.png │ ├── image_DgprN.png │ ├── image_EDtCV.png │ ├── image_EXYgv.png │ ├── image_EXplI.png │ ├── image_FGIUH.png │ ├── image_Flpor.png │ ├── image_Fyoek.png │ ├── image_GPsng.png │ ├── image_GSaic.png │ ├── image_GYgia.png │ ├── image_Getag.png │ ├── image_JDVFA.png │ ├── image_JTEHj.png │ ├── image_JagIC.png │ ├── image_JwRMe.png │ ├── image_KIWnb.png │ ├── image_KeNEj.png │ ├── image_KoCie.png │ ├── image_LXyJa.png │ ├── image_MLAgo.png │ ├── image_NdsKl.png │ ├── image_OISXQ.png │ ├── image_OPRqu.png │ ├── image_OePAM.png │ ├── image_PSaHb.png │ ├── image_PtquB.png │ ├── image_QLisC.png │ ├── image_QjMCf.png │ ├── image_RcHFg.png │ ├── image_RxBmh.png │ ├── image_TSRNI.png │ ├── image_TcZJO.png │ ├── image_UMFrq.png │ ├── image_UMIHV.png │ ├── image_UfWET.png │ ├── image_UxuTa.png │ ├── image_WVxEb.png │ ├── image_WuJPj.png │ ├── image_XQBAT.png │ ├── image_XkrZa.png │ ├── image_XovdI.png │ ├── image_XumDv.png │ ├── image_YNlhA.png │ ├── image_ZBHYs.png │ ├── image_ZixjX.png │ ├── image_eFKLu.png │ ├── image_eOYrT.png │ ├── image_eSIdz.png │ ├── image_earlS.png │ ├── image_faALJ.png │ ├── image_fdZBQ.png │ ├── image_gYjsJ.png │ ├── image_gaSuM.png │ ├── image_gmnrd.png │ ├── image_gwvFf.png │ ├── image_hMXpG.png │ ├── image_htbQc.png │ ├── image_ilEZh.png │ ├── image_irfLA.png │ ├── image_jxWlK.png │ ├── image_ktpyz.png │ ├── image_kuwNB.png │ ├── image_lBJcS.png │ ├── image_lRSUQ.png │ ├── image_lnvpd.png │ ├── image_mCgzT.png │ ├── image_mdKPz.png │ ├── image_nWbet.png │ ├── image_nZHuJ.png │ ├── image_nmVNa.png │ ├── image_oSWyY.png │ ├── image_ofTnM.png │ ├── image_pBsaJ.png │ ├── image_pEaLu.png │ ├── image_pLywk.png │ ├── image_pfcdr.png │ ├── image_qplvW.png │ ├── image_rAxZB.png │ ├── image_rDQbB.png │ ├── image_rTQgs.png │ ├── image_sMiXC.png │ ├── image_smByj.png │ ├── image_tpNnM.png │ ├── image_tpohz.png │ ├── image_tpouC.png │ ├── image_uwgCY.png │ ├── image_vpVOP.png │ ├── image_wGdkx.png │ ├── image_wrqeE.png │ ├── image_xLgWD.png │ ├── image_xrvtc.png │ └── image_zuZhH.png ├── config-example.toml ├── doc ├── image-20240716155547916.png └── image-20240716155729457.png └── requirements.txt /.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 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | *.py,cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | cover/ 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 | .pybuilder/ 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | # For a library or package, you might want to ignore these files since the code is 87 | # intended to run in multiple environments; otherwise, check them in: 88 | # .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # poetry 98 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 99 | # This is especially recommended for binary packages to ensure reproducibility, and is more 100 | # commonly ignored for libraries. 101 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 102 | #poetry.lock 103 | 104 | # pdm 105 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 106 | #pdm.lock 107 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 108 | # in version control. 109 | # https://pdm.fming.dev/latest/usage/project/#working-with-version-control 110 | .pdm.toml 111 | .pdm-python 112 | .pdm-build/ 113 | 114 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 115 | __pypackages__/ 116 | 117 | # Celery stuff 118 | celerybeat-schedule 119 | celerybeat.pid 120 | 121 | # SageMath parsed files 122 | *.sage.py 123 | 124 | # Environments 125 | .env 126 | .venv 127 | env/ 128 | venv/ 129 | ENV/ 130 | env.bak/ 131 | venv.bak/ 132 | 133 | # Spyder project settings 134 | .spyderproject 135 | .spyproject 136 | 137 | # Rope project settings 138 | .ropeproject 139 | 140 | # mkdocs documentation 141 | /site 142 | 143 | # mypy 144 | .mypy_cache/ 145 | .dmypy.json 146 | dmypy.json 147 | 148 | # Pyre type checker 149 | .pyre/ 150 | 151 | # pytype static type analyzer 152 | .pytype/ 153 | 154 | # Cython debug symbols 155 | cython_debug/ 156 | 157 | # PyCharm 158 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 159 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 160 | # and can be added to the global gitignore or merged into this file. For a more nuclear 161 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 162 | #.idea/ 163 | 164 | .env 165 | 166 | config.toml -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // 使用 IntelliSense 了解相关属性。 3 | // 悬停以查看现有属性的描述。 4 | // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "BOT", 9 | "type": "debugpy", 10 | "request": "launch", 11 | "module": "Telegram-simple-group-admin", 12 | "console": "integratedTerminal", 13 | "justMyCode": true, 14 | "env": { 15 | "https_proxy": "http://127.0.0.1:10809" 16 | } 17 | } 18 | ] 19 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.fontSize": 12 3 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Telegram 群管机器人 2 | 3 | ## 简介 4 | 5 | 自用的群管机器人。会陆续开发完善。 6 | 7 | 目前支持功能和尚未完工的功能如下: 8 | 9 | - [ ] 入群管理功能 10 | - [x] 图片识别 11 | - [ ] 管理手动通过/拒绝 12 | - [ ] 关键词识别过滤 13 | - [ ] 禁言 x 秒 14 | - [ ] 踢掉 15 | - [ ] 自动回复(知识库) 16 | - [ ] 开发信息 17 | - [ ] 消息id/raw内容 18 | - [ ] 用户信息in nut 19 | 20 | ![image-20240716155547916](./doc/image-20240716155547916.png) ![image-20240716155729457](./doc/image-20240716155729457.png) 21 | 22 | 23 | ## 准备工作 24 | 25 | 本机器人的主要原理是将客户和机器人的对话,转发到一个群内(自用,最好是私有群),并归纳每个客户的消息到一个子版块。 26 | 所以,在开工前,你需要: 27 | 28 | 1. 找 @BotFather 申请一个机器人。 29 | 2. 获取机器人的token 30 | 3. 建立一个群组(按需设置是否公开) 31 | 4. 将自己的机器人,拉入群组。提升权限为管理员。 32 | 5. 管理权限切记包含`消息管理`。 33 | 6. 通过机器人 @GetTheirIDBot 获取群组的内置ID和管理员用户ID。 34 | 35 | 36 | 37 | ## 部署运行 38 | 39 | ### 1. 修改env 40 | 41 | 打开`config.example.toml`,将自己机器人的Token管理群组ID和管理员ID补全。 42 | 另存`config.example.toml`为`config.toml` 43 | 44 | ### 2. 构建python venv 45 | 46 | ``` 47 | python3 -m venv venv 48 | . venv/bin/activate 49 | pip install -r requirements.txt 50 | ``` 51 | 52 | ### 3. 执行启动 53 | 54 | ``` 55 | python -m Telegram-simple-group-admin 56 | ``` 57 | 58 | **PS:** 正式运营,还是需要类似`PM2`、`supervisor`之类的进程管理工具,配合看门狗来实现不间断运行、自动重启、失效重启等功能。 59 | 60 | 61 | ## 关于 62 | 63 | - 本产品基于Apache协议开源。 64 | - 作者 米哈( @MrMiHa )是一个苦逼程序员,不是煤场奴工,有问题别太理直气壮的跑来下命令。 65 | - 讨论群组是 : https://t.me/DeveloperTeamGroup 欢迎加入后玩耍 66 | - 随意Fork,记得保留`关于`的内容。 67 | - 初版写了2小时。喜欢请打赏。不会部署,群里找我。 68 | - 服务器推荐RackNerd的。实际上,我也确实用这个。够便宜。这款就够:[2核3G--年27刀](https://my.racknerd.com/aff.php?aff=11705&pid=828) 69 | - 实在搞不定部署,可以群里找大家帮忙部署下。服务器也可以找大家共用: https://t.me/DeveloperTeamGroup 70 | -------------------------------------------------------------------------------- /Telegram-simple-group-admin/__init__.py: -------------------------------------------------------------------------------- 1 | import pkg_resources 2 | import os 3 | import sys 4 | import json 5 | import logging 6 | try: 7 | import tomllib 8 | except : 9 | import tomli as tomllib 10 | 11 | # 配置日志记录器 12 | logging.basicConfig( 13 | level=logging.INFO, 14 | format='%(asctime)s %(name)s- %(levelname)s - %(message)s', 15 | handlers=[ 16 | logging.StreamHandler(), 17 | logging.FileHandler('log.txt') 18 | ] 19 | ) 20 | logging.getLogger("httpx").setLevel(logging.ERROR) 21 | current_package = os.path.basename(os.path.dirname(__file__)) 22 | logger = logging.getLogger(current_package) 23 | 24 | 25 | with open("config.toml", "rb") as f: 26 | config = tomllib.load(f) -------------------------------------------------------------------------------- /Telegram-simple-group-admin/__main__.py: -------------------------------------------------------------------------------- 1 | from . import logger, config 2 | from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup 3 | from telegram.ext import ( 4 | ApplicationBuilder, 5 | ContextTypes, 6 | CommandHandler, 7 | MessageHandler, 8 | CallbackQueryHandler, 9 | filters, 10 | PicklePersistence, 11 | ChatJoinRequestHandler, 12 | ) 13 | from telegram.helpers import create_deep_linked_url, mention_html 14 | import telegram 15 | import random 16 | from string import ascii_letters as letters 17 | import os 18 | 19 | 20 | # 延时ban掉用户的回调。 21 | # 如果到时候用户没解封,就踢了。 22 | async def _ban_user_cb(context: ContextTypes.DEFAULT_TYPE): 23 | job = context.job 24 | user_id, _ = job.data.split("-") 25 | user_id = int(user_id) 26 | chat_member = await context.bot.get_chat_member(job.chat_id, user_id) 27 | if chat_member.status == "kicked" or chat_member.status == "restricted": 28 | await context.bot.ban_chat_member(job.chat_id, user_id, 0) 29 | 30 | 31 | # 延时ban掉用户 32 | async def ban_user_later( 33 | delay: float, chat_id, user_id: int, context: ContextTypes.DEFAULT_TYPE 34 | ): 35 | name = f"banjob_{chat_id}_{user_id}" 36 | context.job_queue.run_once( 37 | _ban_user_cb, delay, chat_id=chat_id, name=name, data=f"{user_id}-0" 38 | ) 39 | return name 40 | 41 | 42 | # 延时删除消息的回调 43 | async def _delete_message_cb(context: ContextTypes.DEFAULT_TYPE): 44 | job = context.job 45 | msg_id = job.data 46 | await context.bot.delete_message(job.chat_id, msg_id) 47 | 48 | 49 | # 延时删除用户 50 | async def delete_message_later( 51 | delay: float, chat_id, msg_id: int, context: ContextTypes.DEFAULT_TYPE 52 | ): 53 | name = f"deljob_{chat_id}_{msg_id}" 54 | context.job_queue.run_once( 55 | _delete_message_cb, delay, chat_id=chat_id, name=name, data=msg_id 56 | ) 57 | return name 58 | 59 | 60 | # 删除任务 61 | def remove_job_if_exists(name: str, context: ContextTypes.DEFAULT_TYPE) -> bool: 62 | """Remove job with given name. Returns whether job was removed.""" 63 | current_jobs = context.job_queue.get_jobs_by_name(name) 64 | if not current_jobs: 65 | return False 66 | for job in current_jobs: 67 | job.schedule_removal() 68 | return True 69 | 70 | 71 | # 一般的私聊start指令 72 | # 如果有必要,可以加入管理员的一些特殊菜单。好比重新加载配置之类的。 73 | # 目前没做重新加载,因为貌似这个没必要进行热插拔。 74 | async def start(update: Update, context: ContextTypes.DEFAULT_TYPE): 75 | user = update.effective_user 76 | # check whether is admin 77 | if user.id in config["admin_ids"]: 78 | logger.info(f"{user.first_name}({user.id}) is admin") 79 | try: 80 | bg = await context.bot.get_chat(config["group_id"]) 81 | if bg.type == "supergroup" or bg.type == "group": 82 | logger.info(f"admin group is {bg.title}") 83 | except Exception as e: 84 | logger.error(f"admin group error {e}") 85 | await update.message.reply_html( 86 | f"⚠️⚠️后台管理群组设置错误,请检查配置。⚠️⚠️\n你需要确保已经将机器人 @{context.bot.username} 邀请入管理群组并且给与了管理员权限。\n错误细节:{e}\n请联系 @MrMiHa 获取技术支持。" 87 | ) 88 | 89 | await update.message.reply_html( 90 | f"你好管理员 {user.first_name}({user.id})\n\n欢迎使用 {config['app_name']} 机器人。\n\n 目前你的配置完全正确。可以在群组 {bg.title} 中使用机器人。" 91 | ) 92 | else: 93 | logger.info(f"{user.first_name}({user.id}) is not admin") 94 | await update.message.reply_html( 95 | f"本群机器人并不支持普通用户使用。\n\n请联系管理员 @{config['contact_username']} 获取帮助。" 96 | ) 97 | 98 | 99 | # 利用deeplink区分不同的跳转来源。 100 | # 这个函数响了,代表是用户过来通过验证。 101 | # 用户私聊机器人,走的上面的 start 函数。 102 | async def start_with_deep_link(update: Update, context: ContextTypes.DEFAULT_TYPE): 103 | logger.info( 104 | f"User {update.effective_user.id} start with deep link. {update.message.text}" 105 | ) 106 | user = update.effective_user 107 | prefix, user_id, chat_id = update.message.text.split("_") 108 | if ( 109 | prefix != "/start joingroup" 110 | or user_id != str(user.id) 111 | or chat_id != str(config["group_id"]) 112 | ): 113 | await update.message.reply_html("无效群跳入。") 114 | return 115 | chat_member = await context.bot.get_chat_member(chat_id, user.id) 116 | if chat_member.status == "kicked": 117 | await update.message.reply_html("你已经被禁止加入群组。") 118 | return 119 | await context.bot.delete_message(chat_id, context.user_data.get("srcjoin")) 120 | context.user_data["current_join_group"] = chat_id 121 | # 私信用户, 发送图片。 122 | file_name = random.choice(os.listdir("./assets/imgs")) 123 | code = file_name.replace("image_", "").replace(".png", "") 124 | file = f"./assets/imgs/{file_name}" 125 | codes = ["".join(random.sample(letters, 5)) for _ in range(0, 7)] 126 | codes.append(code) 127 | random.shuffle(codes) 128 | 129 | photo = context.bot_data.get(f"image|{code}") 130 | if not photo: 131 | # 没发送过,就用内置图片。反之,利用发送过的file_id 132 | photo = file 133 | buttons = [ 134 | InlineKeyboardButton(x, callback_data=f"vcode_{x}_{user.id}") for x in codes 135 | ] 136 | button_matrix = [buttons[i : i + 4] for i in range(0, len(buttons), 4)] 137 | sent = await context.bot.send_photo( 138 | user.id, 139 | photo, 140 | f"{mention_html(user.id, user.first_name)}请选择图片中的文字。回答错误永久禁止入群。", 141 | reply_markup=InlineKeyboardMarkup(button_matrix), 142 | parse_mode="HTML", 143 | ) 144 | # 存下已经发送过的图片的file_id,省掉上传速度 145 | biggest_photo = sorted(sent.photo, key=lambda x: x.file_size, reverse=True)[0] 146 | context.bot_data[f"image|{code}"] = biggest_photo.file_id 147 | context.user_data["vcode"] = code 148 | await delete_message_later( 149 | config["ban_after"], sent.chat.id, sent.message_id, context 150 | ) 151 | 152 | 153 | # 删除service消息。 154 | async def status_update(update: Update, context: ContextTypes.DEFAULT_TYPE): 155 | if config["delete_service_message"]: 156 | await update.message.delete() 157 | 158 | 159 | # 加入群组的处理函数 160 | async def join_group(update: Update, context: ContextTypes.DEFAULT_TYPE): 161 | if not update.chat_join_request: 162 | return 163 | logger.info( 164 | f"New user {update.chat_join_request.from_user.id} request to join group {update.effective_chat.id}" 165 | ) 166 | chat = update.effective_chat 167 | user = update.chat_join_request.from_user 168 | # 无条件审批通过这个用户 169 | await update.chat_join_request.approve() 170 | # 限制用户 171 | limitation = telegram.ChatPermissions() 172 | limitation.no_permissions() 173 | await context.bot.restrict_chat_member(chat.id, user.id, limitation, 0) 174 | # 群内提醒用户 175 | button = InlineKeyboardButton( 176 | "点击加入", 177 | url=create_deep_linked_url( 178 | context.bot.username, f"joingroup_{user.id}_{chat.id}" 179 | ), 180 | ) 181 | sent = await context.bot.send_message( 182 | chat.id, 183 | config["msg_new_user_joined_group"].format( 184 | mention_html(user.id, user.full_name) 185 | ), 186 | parse_mode="HTML", 187 | reply_markup=InlineKeyboardMarkup([[button]]), 188 | ) 189 | context.user_data[f"srcjoin"] = sent.id 190 | # 启动延时任务 191 | await delete_message_later(config["ban_after"], chat.id, sent.message_id, context) 192 | await ban_user_later(config["ban_after"], chat.id, user.id, context) 193 | 194 | # 用户状态初始化下 195 | context.user_data["current_join_group"] = None 196 | 197 | 198 | async def callback_query_vcode(update: Update, context: ContextTypes.DEFAULT_TYPE): 199 | # 验证码的点击事件处理 200 | query = update.callback_query 201 | user = query.from_user 202 | code = query.data.split("_")[1] 203 | user_id = query.data.split("_")[2] 204 | if user_id == str(user.id): 205 | # 是正确的人点击 206 | logger.info( 207 | f"User {user.id} clicked {code}, the right code is {context.user_data.get('vcode')}" 208 | ) 209 | if code == context.user_data.get("vcode"): 210 | # 点击合法 211 | logger.info(f"User {user.id} clicked the right code.") 212 | await query.answer(f"正确,欢迎。") 213 | sent = await context.bot.send_message(user.id, f"输入正确,欢迎入群。") 214 | await delete_message_later( 215 | config["ban_after"], sent.chat.id, sent.message_id, context 216 | ) 217 | chat = await context.bot.get_chat(context.user_data["current_join_group"]) 218 | await context.bot.restrict_chat_member( 219 | chat.id, user.id, chat.permissions, 0 220 | ) 221 | remove_job_if_exists(f"banjob_{chat.id}_{user.id}", context) 222 | else: 223 | # 点击错误 224 | logger.info(f"User {user.id} clicked the wrong code.") 225 | await query.answer(f"~错误~,等20分钟后入群。") 226 | await context.bot.send_message( 227 | user.id, f"你的验证码错误,等待20分钟后再次尝试入群。" 228 | ) 229 | await context.bot.ban_chat_member(config["group_id"], user.id, 1200) 230 | await query.message.delete() 231 | 232 | 233 | # 全局异常 234 | async def error_handler(update: object, context: ContextTypes.DEFAULT_TYPE) -> None: 235 | """Log the error and send a telegram message to notify the developer.""" 236 | # Log the error before we do anything else, so we can see it even if something breaks. 237 | logger.error(f"Exception while handling an update: {context.error} ") 238 | logger.debug(f"Exception detail is :", exc_info=context.error) 239 | 240 | 241 | if __name__ == "__main__": 242 | pickle_persistence = PicklePersistence( 243 | filepath=f"./assets/{config['app_name']}.pickle" 244 | ) 245 | application = ( 246 | ApplicationBuilder() 247 | .token(config["bot_token"]) 248 | .persistence(persistence=pickle_persistence) 249 | .build() 250 | ) 251 | # Handler 的添加顺序是不能更改的。要改变,你需要理解 Handler的执行顺序以及优先级。 252 | application.add_handler(MessageHandler(filters.StatusUpdate.ALL, status_update)) 253 | application.add_handler( 254 | CommandHandler("start", start_with_deep_link, filters.Regex(r"joingroup")) 255 | ) 256 | application.add_handler( 257 | CommandHandler( 258 | "start", start, filters.ChatType.PRIVATE & ~filters.Regex(r"joingroup") 259 | ) 260 | ) 261 | application.add_handler(ChatJoinRequestHandler(join_group)) 262 | application.add_handler( 263 | CallbackQueryHandler(callback_query_vcode, pattern="^vcode_") 264 | ) 265 | application.add_error_handler(error_handler) 266 | 267 | application.run_polling() 268 | -------------------------------------------------------------------------------- /assets/.not_empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/.not_empty -------------------------------------------------------------------------------- /assets/imgs/image_AdDMc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_AdDMc.png -------------------------------------------------------------------------------- /assets/imgs/image_AkKgx.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_AkKgx.png -------------------------------------------------------------------------------- /assets/imgs/image_AlwFu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_AlwFu.png -------------------------------------------------------------------------------- /assets/imgs/image_Asjxn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_Asjxn.png -------------------------------------------------------------------------------- /assets/imgs/image_AxMWi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_AxMWi.png -------------------------------------------------------------------------------- /assets/imgs/image_BOoXI.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_BOoXI.png -------------------------------------------------------------------------------- /assets/imgs/image_CPeVb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_CPeVb.png -------------------------------------------------------------------------------- /assets/imgs/image_CYURB.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_CYURB.png -------------------------------------------------------------------------------- /assets/imgs/image_DgprN.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_DgprN.png -------------------------------------------------------------------------------- /assets/imgs/image_EDtCV.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_EDtCV.png -------------------------------------------------------------------------------- /assets/imgs/image_EXYgv.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_EXYgv.png -------------------------------------------------------------------------------- /assets/imgs/image_EXplI.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_EXplI.png -------------------------------------------------------------------------------- /assets/imgs/image_FGIUH.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_FGIUH.png -------------------------------------------------------------------------------- /assets/imgs/image_Flpor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_Flpor.png -------------------------------------------------------------------------------- /assets/imgs/image_Fyoek.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_Fyoek.png -------------------------------------------------------------------------------- /assets/imgs/image_GPsng.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_GPsng.png -------------------------------------------------------------------------------- /assets/imgs/image_GSaic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_GSaic.png -------------------------------------------------------------------------------- /assets/imgs/image_GYgia.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_GYgia.png -------------------------------------------------------------------------------- /assets/imgs/image_Getag.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_Getag.png -------------------------------------------------------------------------------- /assets/imgs/image_JDVFA.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_JDVFA.png -------------------------------------------------------------------------------- /assets/imgs/image_JTEHj.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_JTEHj.png -------------------------------------------------------------------------------- /assets/imgs/image_JagIC.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_JagIC.png -------------------------------------------------------------------------------- /assets/imgs/image_JwRMe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_JwRMe.png -------------------------------------------------------------------------------- /assets/imgs/image_KIWnb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_KIWnb.png -------------------------------------------------------------------------------- /assets/imgs/image_KeNEj.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_KeNEj.png -------------------------------------------------------------------------------- /assets/imgs/image_KoCie.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_KoCie.png -------------------------------------------------------------------------------- /assets/imgs/image_LXyJa.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_LXyJa.png -------------------------------------------------------------------------------- /assets/imgs/image_MLAgo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_MLAgo.png -------------------------------------------------------------------------------- /assets/imgs/image_NdsKl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_NdsKl.png -------------------------------------------------------------------------------- /assets/imgs/image_OISXQ.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_OISXQ.png -------------------------------------------------------------------------------- /assets/imgs/image_OPRqu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_OPRqu.png -------------------------------------------------------------------------------- /assets/imgs/image_OePAM.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_OePAM.png -------------------------------------------------------------------------------- /assets/imgs/image_PSaHb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_PSaHb.png -------------------------------------------------------------------------------- /assets/imgs/image_PtquB.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_PtquB.png -------------------------------------------------------------------------------- /assets/imgs/image_QLisC.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_QLisC.png -------------------------------------------------------------------------------- /assets/imgs/image_QjMCf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_QjMCf.png -------------------------------------------------------------------------------- /assets/imgs/image_RcHFg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_RcHFg.png -------------------------------------------------------------------------------- /assets/imgs/image_RxBmh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_RxBmh.png -------------------------------------------------------------------------------- /assets/imgs/image_TSRNI.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_TSRNI.png -------------------------------------------------------------------------------- /assets/imgs/image_TcZJO.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_TcZJO.png -------------------------------------------------------------------------------- /assets/imgs/image_UMFrq.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_UMFrq.png -------------------------------------------------------------------------------- /assets/imgs/image_UMIHV.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_UMIHV.png -------------------------------------------------------------------------------- /assets/imgs/image_UfWET.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_UfWET.png -------------------------------------------------------------------------------- /assets/imgs/image_UxuTa.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_UxuTa.png -------------------------------------------------------------------------------- /assets/imgs/image_WVxEb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_WVxEb.png -------------------------------------------------------------------------------- /assets/imgs/image_WuJPj.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_WuJPj.png -------------------------------------------------------------------------------- /assets/imgs/image_XQBAT.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_XQBAT.png -------------------------------------------------------------------------------- /assets/imgs/image_XkrZa.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_XkrZa.png -------------------------------------------------------------------------------- /assets/imgs/image_XovdI.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_XovdI.png -------------------------------------------------------------------------------- /assets/imgs/image_XumDv.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_XumDv.png -------------------------------------------------------------------------------- /assets/imgs/image_YNlhA.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_YNlhA.png -------------------------------------------------------------------------------- /assets/imgs/image_ZBHYs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_ZBHYs.png -------------------------------------------------------------------------------- /assets/imgs/image_ZixjX.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_ZixjX.png -------------------------------------------------------------------------------- /assets/imgs/image_eFKLu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_eFKLu.png -------------------------------------------------------------------------------- /assets/imgs/image_eOYrT.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_eOYrT.png -------------------------------------------------------------------------------- /assets/imgs/image_eSIdz.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_eSIdz.png -------------------------------------------------------------------------------- /assets/imgs/image_earlS.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_earlS.png -------------------------------------------------------------------------------- /assets/imgs/image_faALJ.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_faALJ.png -------------------------------------------------------------------------------- /assets/imgs/image_fdZBQ.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_fdZBQ.png -------------------------------------------------------------------------------- /assets/imgs/image_gYjsJ.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_gYjsJ.png -------------------------------------------------------------------------------- /assets/imgs/image_gaSuM.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_gaSuM.png -------------------------------------------------------------------------------- /assets/imgs/image_gmnrd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_gmnrd.png -------------------------------------------------------------------------------- /assets/imgs/image_gwvFf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_gwvFf.png -------------------------------------------------------------------------------- /assets/imgs/image_hMXpG.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_hMXpG.png -------------------------------------------------------------------------------- /assets/imgs/image_htbQc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_htbQc.png -------------------------------------------------------------------------------- /assets/imgs/image_ilEZh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_ilEZh.png -------------------------------------------------------------------------------- /assets/imgs/image_irfLA.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_irfLA.png -------------------------------------------------------------------------------- /assets/imgs/image_jxWlK.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_jxWlK.png -------------------------------------------------------------------------------- /assets/imgs/image_ktpyz.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_ktpyz.png -------------------------------------------------------------------------------- /assets/imgs/image_kuwNB.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_kuwNB.png -------------------------------------------------------------------------------- /assets/imgs/image_lBJcS.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_lBJcS.png -------------------------------------------------------------------------------- /assets/imgs/image_lRSUQ.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_lRSUQ.png -------------------------------------------------------------------------------- /assets/imgs/image_lnvpd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_lnvpd.png -------------------------------------------------------------------------------- /assets/imgs/image_mCgzT.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_mCgzT.png -------------------------------------------------------------------------------- /assets/imgs/image_mdKPz.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_mdKPz.png -------------------------------------------------------------------------------- /assets/imgs/image_nWbet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_nWbet.png -------------------------------------------------------------------------------- /assets/imgs/image_nZHuJ.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_nZHuJ.png -------------------------------------------------------------------------------- /assets/imgs/image_nmVNa.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_nmVNa.png -------------------------------------------------------------------------------- /assets/imgs/image_oSWyY.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_oSWyY.png -------------------------------------------------------------------------------- /assets/imgs/image_ofTnM.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_ofTnM.png -------------------------------------------------------------------------------- /assets/imgs/image_pBsaJ.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_pBsaJ.png -------------------------------------------------------------------------------- /assets/imgs/image_pEaLu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_pEaLu.png -------------------------------------------------------------------------------- /assets/imgs/image_pLywk.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_pLywk.png -------------------------------------------------------------------------------- /assets/imgs/image_pfcdr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_pfcdr.png -------------------------------------------------------------------------------- /assets/imgs/image_qplvW.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_qplvW.png -------------------------------------------------------------------------------- /assets/imgs/image_rAxZB.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_rAxZB.png -------------------------------------------------------------------------------- /assets/imgs/image_rDQbB.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_rDQbB.png -------------------------------------------------------------------------------- /assets/imgs/image_rTQgs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_rTQgs.png -------------------------------------------------------------------------------- /assets/imgs/image_sMiXC.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_sMiXC.png -------------------------------------------------------------------------------- /assets/imgs/image_smByj.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_smByj.png -------------------------------------------------------------------------------- /assets/imgs/image_tpNnM.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_tpNnM.png -------------------------------------------------------------------------------- /assets/imgs/image_tpohz.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_tpohz.png -------------------------------------------------------------------------------- /assets/imgs/image_tpouC.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_tpouC.png -------------------------------------------------------------------------------- /assets/imgs/image_uwgCY.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_uwgCY.png -------------------------------------------------------------------------------- /assets/imgs/image_vpVOP.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_vpVOP.png -------------------------------------------------------------------------------- /assets/imgs/image_wGdkx.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_wGdkx.png -------------------------------------------------------------------------------- /assets/imgs/image_wrqeE.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_wrqeE.png -------------------------------------------------------------------------------- /assets/imgs/image_xLgWD.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_xLgWD.png -------------------------------------------------------------------------------- /assets/imgs/image_xrvtc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_xrvtc.png -------------------------------------------------------------------------------- /assets/imgs/image_zuZhH.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/assets/imgs/image_zuZhH.png -------------------------------------------------------------------------------- /config-example.toml: -------------------------------------------------------------------------------- 1 | # 基本配置 2 | app_name = "chat_group_admin_bot" 3 | bot_token = "73279zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzOAhBywew" 4 | # 测试机器人为: 5 | # https://t.me/chat_group_admin_bot 6 | # 测试群组为: 7 | # https://t.me/miha_groupmanager_bot_test 8 | # 其中,测试群组的最早消息为群组的一些基本信息,包括群组ID等。 9 | 10 | # 业务配置 11 | # 管理员/技术支持人员的用户名,方便用户联系 12 | contact_username = "MrMiHa" 13 | 14 | # 首次加入群组的时候显示的提示消息。注意其中的 {} 会被替换为用户的名字 15 | msg_new_user_joined_group = "欢迎新成员 {} 加入本群!\n你的权限已经被限制。请点击下方按钮,按照指示解锁权限。\n请注意,时间有效期是180s。如果期间内并未按要求完成验证,则会被踢出群组。\n\n 👇👇点击👇👇" 16 | 17 | # 如果用户多久没有成功验证,就会被踢出群组 18 | # 原需求 60s 实际上过于短了。个人建议180s比较合适。 19 | ban_after = 60 20 | 21 | 22 | # 功能配置 23 | # 是否删除 xxx加入群组 xxx离开群组的消息。这是群管机器人的基本功能,所以随手加了。 24 | delete_service_message = true 25 | 26 | # 各类内置ID可以通过 @GetTheirIDBot 获取 27 | # 管理群组的ID 28 | group_id = -1002226718611 29 | 30 | # 管理员的ID 31 | admin_ids = [123456789, 530586633] 32 | -------------------------------------------------------------------------------- /doc/image-20240716155547916.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/doc/image-20240716155547916.png -------------------------------------------------------------------------------- /doc/image-20240716155729457.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiHaKun/Telegram-simple-group-admin/3a89081dbeccf7dbfba0c7d4538d934b3acfe063/doc/image-20240716155729457.png -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | aiolimiter==1.1.0 2 | anyio==4.4.0 3 | APScheduler==3.10.4 4 | cachetools==5.3.3 5 | certifi==2024.6.2 6 | cffi==1.16.0 7 | cryptography==42.0.8 8 | exceptiongroup==1.2.1 9 | h11==0.14.0 10 | h2==4.1.0 11 | hpack==4.0.0 12 | httpcore==1.0.5 13 | httpx==0.27.0 14 | hyperframe==6.0.1 15 | idna==3.7 16 | pycparser==2.22 17 | python-telegram-bot==21.3 18 | pytz==2024.1 19 | six==1.16.0 20 | sniffio==1.3.1 21 | socksio==1.0.0 22 | tomli==2.0.1 23 | tornado==6.4.1 24 | typing_extensions==4.12.2 25 | tzdata==2024.1 26 | tzlocal==5.2 27 | --------------------------------------------------------------------------------