From f21bd065bde0a3b3da9ba34653a23e5cc126742c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=BA=E5=99=A8=E4=BA=BA=E6=80=BB=E5=8A=A8=E5=91=98?= <73592731+devourbots@users.noreply.github.com> Date: Sun, 9 May 2021 22:58:10 +0800 Subject: [PATCH] =?UTF-8?q?/rank=20=E9=BB=98=E8=AE=A4=E5=8F=AA=E5=AF=B9?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E6=9C=89=E6=95=88=EF=BC=8C=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=BC=80=E5=85=B3=20=E5=A2=9E=E5=8A=A0=E7=A7=81=E6=9C=89?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=E5=BC=80=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 29 +++++++++++++++++++++-------- config.py | 3 +++ func.py | 18 ++++++++++++++++-- task.py | 2 -- 4 files changed, 40 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 8c6f425..7bd1a30 100644 --- a/README.md +++ b/README.md @@ -85,21 +85,34 @@ docker run -d --net=host world_cloud_bot:latest ### 将机器人设置为仅自己群组可用 -如果您不想让别人使用你的机器人,那么可以将 func.py 文件中的 -```angular2html - # if chat_id not in ["1231242141"]: - # return -``` -该段注释取消,并将自己的群组ID加入到列表中。 +如何编辑 Docker 容器中的文件请自行 Google + +如果您不想让别人使用你的机器人,那么可以将 `config.py` 文件中的 `EXCLUSIVE_MODE = 0`改为 `EXCLUSIVE_MODE = 1` + +![DGbSy.png](https://s3.jpg.cm/2021/05/09/DGbSy.png) + +编辑 `/root/word_cloud_bot/func.py`,在 94 行左右,将自己的 群组ID 加入到列表中。 +这里的`EXCLUSIVE_MODE = 1`不要改动,注意区分! + 例如我两个的群组ID分别为:-127892174935、-471892571924 那么修改后为: ```angular2html - if chat_id not in ["-127892174935", "-471892571924"]: - return +if EXCLUSIVE_MODE == 1 and chat_id not in ["-127892174935", "-471892571924"]: + print(chat_id + " 为未认证群组,取消入库") + return ``` +![DGHR5.png](https://s3.jpg.cm/2021/05/09/DGHR5.png) + +### 设置 /rank 指令对普通用户开放 + +编辑 `/root/word_cloud_bot/config.py`, 将 `RANK_COMMAND_MODE = 1` 改为 `RANK_COMMAND_MODE = 0` + +![DGJuC.png](https://s3.jpg.cm/2021/05/09/DGJuC.png) + + ### 信息推送密度 ![xW3jh.png](https://s3.jpg.cm/2021/05/05/xW3jh.png) diff --git a/config.py b/config.py index ad3d082..ca2bc4b 100644 --- a/config.py +++ b/config.py @@ -5,3 +5,6 @@ LIMIT_COUNT = 10 # 私有模式,仅授权群组可用 0:关闭 1:打开 EXCLUSIVE_MODE = 0 + +# 主动触发命令仅管理员有效 0:否 1:是 +RANK_COMMAND_MODE = 1 diff --git a/func.py b/func.py index 4423ed7..853055d 100644 --- a/func.py +++ b/func.py @@ -3,7 +3,7 @@ import time import connector import telegram from telegram.ext import CommandHandler, MessageHandler, Filters -from config import TOKEN, LIMIT_COUNT, EXCLUSIVE_MODE +from config import TOKEN, LIMIT_COUNT, EXCLUSIVE_MODE, RANK_COMMAND_MODE import schedule from task import add_task @@ -38,6 +38,19 @@ def rank(update, context): if chat_type != "supergroup": update.message.reply_text("此命令只有在群组中有效") return + if RANK_COMMAND_MODE == 1: + try: + chat_member = bot.get_chat_member(chat_id, user_id) + status = chat_member["status"] + print("此用户在群组中身份为: {}".format(status)) + if status == "creator" or status == "administrator": + print("用户权限正确") + else: + update.message.reply_text("此命令仅对管理员开放") + return + except Exception as e: + print(e) + print("获取用户身份失败") if r.exists("{}_frequency_limit".format(chat_id)): r.setrange("{}_frequency_limit".format(chat_id), 0, int(r.get("{}_frequency_limit".format(chat_id))) + 1) else: @@ -78,7 +91,8 @@ def chat_content_exec(update, context): if len(text) > 80: return # 独享模式(仅授权群组可用) - if chat_id not in ["1231242141"] and EXCLUSIVE_MODE == 1: + if EXCLUSIVE_MODE == 1 and chat_id not in ["1231242141"]: + print(chat_id + " 为未认证群组,取消入库") return try: username = update.effective_user.username diff --git a/task.py b/task.py index 7f0ec8e..b262bd0 100644 --- a/task.py +++ b/task.py @@ -29,8 +29,6 @@ def schedule_task(): try: # 网任务队列中添加任务 task_queue.put(group) - # threading.Thread(target=generate, args=(group,)).start() - # time.sleep(0.5) except Exception as e: print("群组:{} | 词云数据分析生成失败,请查看报错信息".format(group)) print(e)