@@ -120,16 +120,15 @@ async def _(event):
120
120
logger .info (str (e ))
121
121
return False
122
122
res = ""
123
- current_db_locks = get_locks (event .chat_id )
124
- if not current_db_locks :
125
- res = "There are no DataBase locks in this chat"
126
- else :
123
+ if current_db_locks := get_locks (event .chat_id ):
127
124
res = "Following are the DataBase locks in this chat: \n "
128
125
res += "👉 `bots`: `{}`\n " .format (current_db_locks .bots )
129
126
res += "👉 `commands`: `{}`\n " .format (current_db_locks .commands )
130
127
res += "👉 `email`: `{}`\n " .format (current_db_locks .email )
131
128
res += "👉 `forward`: `{}`\n " .format (current_db_locks .forward )
132
129
res += "👉 `url`: `{}`\n " .format (current_db_locks .url )
130
+ else :
131
+ res = "There are no DataBase locks in this chat"
133
132
current_chat = await event .get_chat ()
134
133
try :
135
134
current_api_locks = current_chat .default_banned_rights
@@ -163,9 +162,8 @@ async def check_incoming_messages(event):
163
162
return
164
163
peer_id = event .chat_id
165
164
if is_locked (peer_id , "commands" ):
166
- entities = event .message .entities
167
165
is_command = False
168
- if entities :
166
+ if entities := event . message . entities :
169
167
for entity in entities :
170
168
if isinstance (entity , types .MessageEntityBotCommand ):
171
169
is_command = True
@@ -186,9 +184,8 @@ async def check_incoming_messages(event):
186
184
)
187
185
update_lock (peer_id , "forward" , False )
188
186
if is_locked (peer_id , "email" ):
189
- entities = event .message .entities
190
187
is_email = False
191
- if entities :
188
+ if entities := event . message . entities :
192
189
for entity in entities :
193
190
if isinstance (entity , types .MessageEntityEmail ):
194
191
is_email = True
@@ -201,9 +198,8 @@ async def check_incoming_messages(event):
201
198
)
202
199
update_lock (peer_id , "email" , False )
203
200
if is_locked (peer_id , "url" ):
204
- entities = event .message .entities
205
201
is_url = False
206
- if entities :
202
+ if entities := event . message . entities :
207
203
for entity in entities :
208
204
if isinstance (entity , (types .MessageEntityTextUrl , types .MessageEntityUrl )):
209
205
is_url = True
@@ -227,34 +223,31 @@ async def _(event):
227
223
return False
228
224
if await slitu .is_admin (event .client , event .chat_id , event .action_message .sender_id ):
229
225
return
230
- if is_locked (event .chat_id , "bots" ):
231
- # bots are limited Telegram accounts,
232
- # and cannot join by themselves
233
- if event .user_added :
234
- users_added_by = event .action_message .sender_id
235
- is_ban_able = False
236
- rights = types .ChatBannedRights (
237
- until_date = None ,
238
- view_messages = True
226
+ if is_locked (event .chat_id , "bots" ) and event .user_added :
227
+ users_added_by = event .action_message .sender_id
228
+ is_ban_able = False
229
+ rights = types .ChatBannedRights (
230
+ until_date = None ,
231
+ view_messages = True
232
+ )
233
+ added_users = event .action_message .action .users
234
+ for user_id in added_users :
235
+ user_obj = await event .client .get_entity (user_id )
236
+ if user_obj .bot :
237
+ is_ban_able = True
238
+ try :
239
+ await event .client (functions .channels .EditBannedRequest (
240
+ event .chat_id ,
241
+ user_obj ,
242
+ rights
243
+ ))
244
+ except Exception as e :
245
+ await event .reply (
246
+ "I don't seem to have ADMIN permission here. \n `{}`" .format (str (e ))
247
+ )
248
+ update_lock (event .chat_id , "bots" , False )
249
+ break
250
+ if Config .G_BAN_LOGGER_GROUP is not None and is_ban_able :
251
+ ban_reason_msg = await event .reply (
252
+ "!warn [user](tg://user?id={}) Please Do Not Add BOTs to this chat." .format (users_added_by )
239
253
)
240
- added_users = event .action_message .action .users
241
- for user_id in added_users :
242
- user_obj = await event .client .get_entity (user_id )
243
- if user_obj .bot :
244
- is_ban_able = True
245
- try :
246
- await event .client (functions .channels .EditBannedRequest (
247
- event .chat_id ,
248
- user_obj ,
249
- rights
250
- ))
251
- except Exception as e :
252
- await event .reply (
253
- "I don't seem to have ADMIN permission here. \n `{}`" .format (str (e ))
254
- )
255
- update_lock (event .chat_id , "bots" , False )
256
- break
257
- if Config .G_BAN_LOGGER_GROUP is not None and is_ban_able :
258
- ban_reason_msg = await event .reply (
259
- "!warn [user](tg://user?id={}) Please Do Not Add BOTs to this chat." .format (users_added_by )
260
- )
0 commit comments