You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.5 KiB

import telebot
from telebot import types,util
###### IMPORT TOKEN ######
import json
with open('db.json', 'r') as openfile:
db = json.load(openfile)
bot = telebot.TeleBot(db['token'])
############# FUNCTIONS ##
def get_admins(message):
try:
if bot.get_chat(message.chat.id).type == "private":
return []
else:
admins = bot.get_chat_administrators(chat_id=message.chat.id)
true_admins = []
for i in admins:
if i.status == "creator" or i.can_restrict_members == True:
true_admins.append(i.user.id)
return true_admins
except:
catch_error(message)
return None
# Fix for anon admins, all anon (not premium) users == admins
def is_anon(message):
if message.from_user.username == "Channel_Bot" and message.from_user.is_premium == None:
return True
else:
return False
########CATCH LINKS######
def catch(message):
try:
if message.from_user.id not in get_admins(message) and not is_anon(message):
if 'https://t.me/' in message.text or ( hasattr(message, 'entities') and hasattr(message.entities[0], 'url') and message.entities[0].url != None ):
bot.delete_message(message.chat.id, message.id)
bot.send_message(message.chat.id, f"Пользователь {telebot.util.user_link(message.from_user)} пытался отправить ссылку на группу/чат.", parse_mode='HTML')
except:
pass
@bot.message_handler()
def catch_all_messages(message):
catch(message)
@bot.edited_message_handler()
def catch_edited_messages(message):
catch(message)
bot.polling()