Skip to content
This repository was archived by the owner on Jun 10, 2022. It is now read-only.

Commit cf3728e

Browse files
防止群组内请求输出较长帮助信息导致刷屏
由于信息内容比较长,为了防止长信息刷屏,请和我私聊并重新发送此命令。
1 parent 7980621 commit cf3728e

File tree

4 files changed

+43
-13
lines changed

4 files changed

+43
-13
lines changed

d_gag.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ def enable(update: Update, context: CallbackContext, redisPool: redis.Connection
8585

8686

8787
def help(update: Update, context: CallbackContext, c_CHAR: list[list[str]]):
88+
if update.message.chat.type != 'private':
89+
alert = '由于信息内容比较长,为了防止长信息刷屏,请和我*私聊*并重新发送此命令。'
90+
context.bot.send_message(chat_id=update.effective_chat.id, text=alert)
91+
return
8892
f = open('help_gag.txt', 'r', encoding='utf_8')
8993
txt = f.read()
9094
f.close()
@@ -100,8 +104,7 @@ def help(update: Update, context: CallbackContext, c_CHAR: list[list[str]]):
100104
gagInfoArr = c_GAGTYPES[gagName]
101105
addNum: str = str(gagInfoArr[0])
102106
canNum: str = str(gagInfoArr[1])
103-
newLine: str = '「'+gagName+'」,需要「绒度」至少 '+canNum + \
104-
' 才能被用,每次「佩戴」或「加固」增加「挣扎」所需次数 '+addNum+' 次。'
107+
newLine: str = '「'+gagName+'」,需要对方绒度 '+canNum+' ,增加所需挣扎次数 '+addNum+' 。'
105108
gagInfos.append(newLine)
106109
t3: str = '\n'.join(gagInfos)
107110
txt = txt.replace('<t1>', t1).replace('<t2>', t2).replace('<t3>', t3)
@@ -112,16 +115,25 @@ def add(update: Update, context: CallbackContext, redisPool0: redis.ConnectionPo
112115
"""為他人佩戴"""
113116
argsLen = len(context.args)
114117
if argsLen == 0:
115-
help(update, context, c_CHAR)
118+
alert = '使用方式: `/gag @username 口塞名`\n有关详细使用规则和可用口塞名,请*私聊*我发送 `/gag help` 了解。'
119+
print(alert)
120+
context.bot.send_message(
121+
chat_id=update.effective_chat.id, text=alert)
116122
return
117123
gagTypesKeys = list(c_GAGTYPES.keys())
118124
gagName: str = gagTypesKeys[0]
119-
selectGagInfo = c_GAGTYPES[gagName]
120-
selectGagAdd: int = selectGagInfo[0]
121-
selectGagNeed: int = selectGagInfo[1]
122125
if argsLen == 2:
123126
if gagName in gagTypesKeys:
124127
gagName = context.args[1]
128+
else:
129+
alert = '你使了我这里没有的口塞呢……\n要了解都有哪些口塞可以使用及规则,请*私聊*我发送 `/gag help` 了解。'
130+
print(alert)
131+
context.bot.send_message(
132+
chat_id=update.effective_chat.id, text=alert)
133+
return
134+
selectGagInfo = c_GAGTYPES[gagName]
135+
selectGagAdd: int = selectGagInfo[0]
136+
selectGagNeed: int = selectGagInfo[1]
125137
toUser: str = context.args[0]
126138
if toUser == 'help':
127139
help(update, context, c_CHAR)

help_about.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
===== 关于本 BOT ====
22
本 bot 为绒布球相关指定群组提供服务。
3-
功能只在指定的群组中生效,不要将其添加到其他群组中或私聊,将会拒绝服务。
3+
功能只在指定的群组中生效,不要将其添加到其他群组中,将会拒绝服务。
44
注意:要使用本 bot ,你的 Telegram 账户必须已经设置 username 用户名(以 @ 开头,不是 display name 显示名称)。
55
===== 隐私权 =====
66
本 bot 不会主动收集聊天内容。但本 bot 所回复和被回复的消息、以及程序出错时的报错调试信息可能会被后台命令行输出,以用作调试等情况,因此遭到命令行临时性地记录,但不会永久保存在硬盘中。

rbqbot.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@
1313
import d_chat
1414
import d_gag
1515
import hashlib
16+
import time
17+
import datetime
1618

1719
print('正在初始化...')
20+
starttime = datetime.datetime.now()
1821

1922
c_TGTOKEN = '*:*-*'
2023
c_REDIS = ['127.0.0.1', 6379, '*']
@@ -34,15 +37,18 @@
3437
host=c_REDIS[0], port=c_REDIS[1], password=c_REDIS[2], db=c_REDISDB[1])
3538

3639

37-
def isPermission(chatID: int) -> bool:
40+
def isPermission(chatID: int, chatTitle:str) -> bool:
3841
"""檢查該會話是否有許可權使用此機器人"""
3942
redisConnect = redis.Redis(connection_pool=redisPool0)
4043
rediskey = 'can_' + str(chatID)
4144
isPass = redisConnect.get(rediskey)
4245
redisConnect.close()
4346
if isPass != None and isPass == b'1':
4447
return True
45-
print('不能提供服务 ' + str(chatID))
48+
title = ''
49+
if chatTitle != None:
50+
title = chatTitle
51+
print('不能提供服务 (' + str(chatID) + ') '+title)
4652
return False
4753

4854

@@ -61,7 +67,7 @@ def start(update: Update, context: CallbackContext):
6167

6268
def echo(update: Update, context: CallbackContext):
6369
"""收到的所有非命令文字訊息"""
64-
if update == None or update.message == None or update.message.chat == None or update.message.from_user == None or update.message.from_user.username == None or update.message.from_user.is_bot == None or update.message.from_user.is_bot or isPermission(update.message.chat.id) == False:
70+
if update == None or update.message == None or update.message.chat == None or update.message.from_user == None or update.message.from_user.username == None or update.message.from_user.is_bot == None or update.message.from_user.is_bot or isPermission(update.message.chat.id,update.message.chat.title) == False:
6571
return
6672
text: str = update.message.text
6773
if len(text) == 0 or text[0] == '/':
@@ -73,7 +79,7 @@ def echo(update: Update, context: CallbackContext):
7379

7480
def new_member(update, context):
7581
"""新成員加入"""
76-
if update.message.chat == None or isPermission(update.message.chat.id) == False:
82+
if update.message.chat != None and isPermission(update.message.chat.id,update.message.chat.title) == False:
7783
return
7884
# print(update.message.from_user.username)
7985
for member in update.message.new_chat_members:
@@ -95,7 +101,13 @@ def new_member(update, context):
95101

96102
def gag(update: Update, context: CallbackContext):
97103
"""為他人佩戴口球"""
98-
if update.message.chat == None or isPermission(update.message.chat.id) == False:
104+
if update.message.chat == None or update.message.chat.type == None:
105+
return
106+
# group, supergroup, private, channel
107+
if update.message.chat.type == 'private' and len(context.args) > 0 and context.args[0] == 'help':
108+
d_gag.add(update, context, redisPool0, c_CHAR)
109+
return
110+
if isPermission(update.message.chat.id,update.message.chat.title) == False:
99111
return
100112
d_gag.add(update, context, redisPool0, c_CHAR)
101113

@@ -106,6 +118,12 @@ def gag(update: Update, context: CallbackContext):
106118

107119
def about(update: Update, context: CallbackContext):
108120
"""幫助"""
121+
if update.message.chat == None or update.message.chat.type == None:
122+
return
123+
if update.message.chat.type != 'private':
124+
alert = '由于信息内容比较长,为了防止长信息刷屏,请和我*私聊*并重新发送此命令。'
125+
context.bot.send_message(chat_id=update.effective_chat.id, text=alert)
126+
return
109127
f = open('help_about.txt', 'r', encoding='utf_8')
110128
txt = f.read()
111129
f.close()

test/msg_text.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"date": 8888888888,
1010
"photo": [],
1111
"chat": {
12-
"type": "supergroup",
12+
"type": "supergroup", // Group, SuperGroup, Private, Channel
1313
"title": "雅诗测试用组",
1414
"id": -8888888888888
1515
},

0 commit comments

Comments
 (0)