13
13
import d_chat
14
14
import d_gag
15
15
import hashlib
16
+ import time
17
+ import datetime
16
18
17
19
print ('正在初始化...' )
20
+ starttime = datetime .datetime .now ()
18
21
19
22
c_TGTOKEN = '*:*-*'
20
23
c_REDIS = ['127.0.0.1' , 6379 , '*' ]
34
37
host = c_REDIS [0 ], port = c_REDIS [1 ], password = c_REDIS [2 ], db = c_REDISDB [1 ])
35
38
36
39
37
- def isPermission (chatID : int ) -> bool :
40
+ def isPermission (chatID : int , chatTitle : str ) -> bool :
38
41
"""檢查該會話是否有許可權使用此機器人"""
39
42
redisConnect = redis .Redis (connection_pool = redisPool0 )
40
43
rediskey = 'can_' + str (chatID )
41
44
isPass = redisConnect .get (rediskey )
42
45
redisConnect .close ()
43
46
if isPass != None and isPass == b'1' :
44
47
return True
45
- print ('不能提供服务 ' + str (chatID ))
48
+ title = ''
49
+ if chatTitle != None :
50
+ title = chatTitle
51
+ print ('不能提供服务 (' + str (chatID ) + ') ' + title )
46
52
return False
47
53
48
54
@@ -61,7 +67,7 @@ def start(update: Update, context: CallbackContext):
61
67
62
68
def echo (update : Update , context : CallbackContext ):
63
69
"""收到的所有非命令文字訊息"""
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 :
65
71
return
66
72
text : str = update .message .text
67
73
if len (text ) == 0 or text [0 ] == '/' :
@@ -73,7 +79,7 @@ def echo(update: Update, context: CallbackContext):
73
79
74
80
def new_member (update , context ):
75
81
"""新成員加入"""
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 :
77
83
return
78
84
# print(update.message.from_user.username)
79
85
for member in update .message .new_chat_members :
@@ -95,7 +101,13 @@ def new_member(update, context):
95
101
96
102
def gag (update : Update , context : CallbackContext ):
97
103
"""為他人佩戴口球"""
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 :
99
111
return
100
112
d_gag .add (update , context , redisPool0 , c_CHAR )
101
113
@@ -106,6 +118,12 @@ def gag(update: Update, context: CallbackContext):
106
118
107
119
def about (update : Update , context : CallbackContext ):
108
120
"""幫助"""
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
109
127
f = open ('help_about.txt' , 'r' , encoding = 'utf_8' )
110
128
txt = f .read ()
111
129
f .close ()
0 commit comments