Don't allow Bot to be added in channels.

pull/38/head
J-Rios 2020-04-04 14:28:48 +02:00
rodzic 93dbbe2420
commit 21e26393c3
15 zmienionych plików z 63 dodań i 9 usunięć

Wyświetl plik

@ -12,7 +12,7 @@ Creation date:
Last modified date:
05/03/2020
Version:
1.7.0
1.7.1
'''
####################################################################################################
@ -115,7 +115,7 @@ CONST = {
"DEV_BTC" : "3N9wf3FunR6YNXonquBeWammaBZVzTXTyR",
# Bot version
"VERSION" : "1.7.0 (05/03/2020)"
"VERSION" : "1.7.1 (04/04/2020)"
}

Wyświetl plik

@ -13,9 +13,9 @@ Author:
Creation date:
09/09/2018
Last modified date:
05/03/2020
04/04/2020
Version:
1.7.0
1.7.1
'''
####################################################################################################
@ -463,6 +463,18 @@ def tlg_check_chat_type(bot, chat_id_or_alias):
printts("[{}] {}".format(chat_id_or_alias, str(e)))
return chat_type
def tlg_leave_chat(bot, chat_id):
'''Telegram Bot try to leave a chat.'''
left = False
try:
if bot.leave_chat(chat_id):
left = True
except Exception as e:
printts("[{}] {}".format(chat_id, str(e)))
return left
####################################################################################################
### Received Telegram not-command messages handlers ###
@ -471,14 +483,17 @@ def msg_new_user(bot, update):
'''New member join the group event handler'''
global to_delete_join_messages_list
global new_users_list
# Ignore if message comes from a channel
msg = getattr(update, "message", None)
if msg.chat.type == "channel":
return
# Get message data
chat_id = update.message.chat_id
# Determine configured bot language in actual chat
lang = get_chat_config(chat_id, "Language")
# Leave the chat if it is a channel
msg = getattr(update, "message", None)
if msg.chat.type == "channel":
print("Bot try to be added to a channel")
tlg_send_selfdestruct_msg_in(bot, chat_id, TEXT[lang]["BOT_LEAVE_CHANNEL"], 1)
tlg_leave_chat(bot, chat_id)
return
# For each new user that join or has been added
for join_user in update.message.new_chat_members:
join_user_id = join_user.id
@ -1480,7 +1495,7 @@ def main():
# Check if Bot Token has been set or has default value
if CONST["TOKEN"] == "XXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX":
printts("Error: Bot Token has not been set.")
printts("Please add your Bot Token to the constants.py file.")
printts("Please add your Bot Token to constants.py file.")
printts("Exit.\n")
exit(0)
printts("Bot started.")

Wyświetl plik

@ -140,6 +140,9 @@
"OTHER_CAPTCHA_BTN_TEXT" :
"Mostra un altre captcha",
"BOT_LEAVE_CHANNEL" :
"Aquest bot no es pot utilitzar en canals, només en grups.",
"ENABLE" :
"S'ha activat la protecció per captcha. Podeu desactivar-la amb l'ordre /disable.",

Wyświetl plik

@ -140,6 +140,9 @@
"OTHER_CAPTCHA_BTN_TEXT" :
"Anderes Captcha",
"BOT_LEAVE_CHANNEL" :
"This Bot can't be used in channels, just in groups.\n\n[This text needs translate to actual configured language]",
"ENABLE" :
"Captcha-Schutz aktiviert. Deaktivieren Sie es mit dem /disable Befehl.",

Wyświetl plik

@ -140,6 +140,9 @@
"OTHER_CAPTCHA_BTN_TEXT" :
"Other Captcha",
"BOT_LEAVE_CHANNEL" :
"This Bot can't be used in channels, just in groups.",
"ENABLE" :
"Captcha protection enabled. Disable it with /disable command.",

Wyświetl plik

@ -140,6 +140,9 @@
"OTHER_CAPTCHA_BTN_TEXT" :
"Otro Captcha",
"BOT_LEAVE_CHANNEL" :
"Este Bot no puede ser utilizado en canales, solo en grupos.",
"ENABLE" :
"Protección captcha activada. Desactívala con el comando /disable.",

Wyświetl plik

@ -140,6 +140,9 @@
"OTHER_CAPTCHA_BTN_TEXT" :
"Beste captcha bat",
"BOT_LEAVE_CHANNEL" :
"This Bot can't be used in channels, just in groups.\n\n[This text needs translate to actual configured language]",
"ENABLE" :
"Captcha babesa aktibatuta. Desaktibatzeko /disable komandoa erabili.",

Wyświetl plik

@ -140,6 +140,9 @@
    "OTHER_CAPTCHA_BTN_TEXT" :
        "دیگر کپچا",
"BOT_LEAVE_CHANNEL" :
"This Bot can't be used in channels, just in groups..\n\n[This text needs translate to actual configured language]",
"ENABLE" :
        "محافظت از کد کپچا فعال است. آن را با دستور /غیرفعال کردن غیرفعال کنید.",

Wyświetl plik

@ -140,6 +140,9 @@
"OTHER_CAPTCHA_BTN_TEXT" :
"Autres captcha",
"BOT_LEAVE_CHANNEL" :
"This Bot can't be used in channels, just in groups.\n\n[This text needs translate to actual configured language]",
"ENABLE" :
"Captcha activé. Désactiver le avec la commande /disable",

Wyświetl plik

@ -140,6 +140,9 @@
"OTHER_CAPTCHA_BTN_TEXT" :
"Otro Captcha",
"BOT_LEAVE_CHANNEL" :
"This Bot can't be used in channels, just in groups.\n\n[This text needs translate to actual configured language]",
"ENABLE" :
"Protección captcha activada. Desactívaa co comando /disable.",

Wyświetl plik

@ -140,6 +140,9 @@
"OTHER_CAPTCHA_BTN_TEXT" :
"Captcha lainnya",
"BOT_LEAVE_CHANNEL" :
"This Bot can't be used in channels, just in groups.\n\n[This text needs translate to actual configured language]",
"ENABLE" :
"Proteksi Captcha diaktifkan. Nonaktifkan captcha dengan perintah /disable ",

Wyświetl plik

@ -140,6 +140,9 @@
"OTHER_CAPTCHA_BTN_TEXT" :
"Altro captcha",
"BOT_LEAVE_CHANNEL" :
"This Bot can't be used in channels, just in groups.\n\n[This text needs translate to actual configured language]",
"ENABLE" :
"Protezione captcha abilitata. Disabilitala con il comando /disable.",

Wyświetl plik

@ -140,6 +140,9 @@
"OTHER_CAPTCHA_BTN_TEXT" :
"Outro Captcha",
"BOT_LEAVE_CHANNEL" :
"This Bot can't be used in channels, just in groups.\n\n[This text needs translate to actual configured language]",
"ENABLE" :
"Proteção Captcha ativada. Desative com o comando /disable.",

Wyświetl plik

@ -140,6 +140,9 @@
"OTHER_CAPTCHA_BTN_TEXT" :
"Другие капчи",
"BOT_LEAVE_CHANNEL" :
"This Bot can't be used in channels, just in groups.\n\n[This text needs translate to actual configured language]",
"ENABLE" :
"Защита от спама включена. Отключите его с помощью команды /disable",

Wyświetl plik

@ -140,6 +140,9 @@
"OTHER_CAPTCHA_BTN_TEXT" :
"其他验证码",
"BOT_LEAVE_CHANNEL" :
"This Bot can't be used in channels, just in groups.\n\n[This text needs translate to actual configured language]",
"ENABLE" :
"启用了验证码保护。 使用 /disable 命令禁用它。",