/rank 默认只对管理有效,增加开关
增加私有模式开关
This commit is contained in:
parent
8af81b178c
commit
f21bd065bd
29
README.md
29
README.md
@ -85,21 +85,34 @@ docker run -d --net=host world_cloud_bot:latest
|
|||||||
|
|
||||||
### 将机器人设置为仅自己群组可用
|
### 将机器人设置为仅自己群组可用
|
||||||
|
|
||||||
如果您不想让别人使用你的机器人,那么可以将 func.py 文件中的
|
如何编辑 Docker 容器中的文件请自行 Google
|
||||||
```angular2html
|
|
||||||
# if chat_id not in ["1231242141"]:
|
如果您不想让别人使用你的机器人,那么可以将 `config.py` 文件中的 `EXCLUSIVE_MODE = 0`改为 `EXCLUSIVE_MODE = 1`
|
||||||
# return
|
|
||||||
```
|
![DGbSy.png](https://s3.jpg.cm/2021/05/09/DGbSy.png)
|
||||||
该段注释取消,并将自己的群组ID加入到列表中。
|
|
||||||
|
编辑 `/root/word_cloud_bot/func.py`,在 94 行左右,将自己的 群组ID 加入到列表中。
|
||||||
|
这里的`EXCLUSIVE_MODE = 1`不要改动,注意区分!
|
||||||
|
|
||||||
|
|
||||||
例如我两个的群组ID分别为:-127892174935、-471892571924
|
例如我两个的群组ID分别为:-127892174935、-471892571924
|
||||||
|
|
||||||
那么修改后为:
|
那么修改后为:
|
||||||
```angular2html
|
```angular2html
|
||||||
if chat_id not in ["-127892174935", "-471892571924"]:
|
if EXCLUSIVE_MODE == 1 and chat_id not in ["-127892174935", "-471892571924"]:
|
||||||
return
|
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)
|
![xW3jh.png](https://s3.jpg.cm/2021/05/05/xW3jh.png)
|
||||||
|
@ -5,3 +5,6 @@ LIMIT_COUNT = 10
|
|||||||
|
|
||||||
# 私有模式,仅授权群组可用 0:关闭 1:打开
|
# 私有模式,仅授权群组可用 0:关闭 1:打开
|
||||||
EXCLUSIVE_MODE = 0
|
EXCLUSIVE_MODE = 0
|
||||||
|
|
||||||
|
# 主动触发命令仅管理员有效 0:否 1:是
|
||||||
|
RANK_COMMAND_MODE = 1
|
||||||
|
18
func.py
18
func.py
@ -3,7 +3,7 @@ import time
|
|||||||
import connector
|
import connector
|
||||||
import telegram
|
import telegram
|
||||||
from telegram.ext import CommandHandler, MessageHandler, Filters
|
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
|
import schedule
|
||||||
from task import add_task
|
from task import add_task
|
||||||
|
|
||||||
@ -38,6 +38,19 @@ def rank(update, context):
|
|||||||
if chat_type != "supergroup":
|
if chat_type != "supergroup":
|
||||||
update.message.reply_text("此命令只有在群组中有效")
|
update.message.reply_text("此命令只有在群组中有效")
|
||||||
return
|
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)):
|
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)
|
r.setrange("{}_frequency_limit".format(chat_id), 0, int(r.get("{}_frequency_limit".format(chat_id))) + 1)
|
||||||
else:
|
else:
|
||||||
@ -78,7 +91,8 @@ def chat_content_exec(update, context):
|
|||||||
if len(text) > 80:
|
if len(text) > 80:
|
||||||
return
|
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
|
return
|
||||||
try:
|
try:
|
||||||
username = update.effective_user.username
|
username = update.effective_user.username
|
||||||
|
2
task.py
2
task.py
@ -29,8 +29,6 @@ def schedule_task():
|
|||||||
try:
|
try:
|
||||||
# 网任务队列中添加任务
|
# 网任务队列中添加任务
|
||||||
task_queue.put(group)
|
task_queue.put(group)
|
||||||
# threading.Thread(target=generate, args=(group,)).start()
|
|
||||||
# time.sleep(0.5)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("群组:{} | 词云数据分析生成失败,请查看报错信息".format(group))
|
print("群组:{} | 词云数据分析生成失败,请查看报错信息".format(group))
|
||||||
print(e)
|
print(e)
|
||||||
|
Loading…
Reference in New Issue
Block a user