def check_updates(update): chat = chat_object(update) user = user_object(update) date = datetime.datetime.utcnow().isoformat() if chat.type == "supergroup" or chat.type == "group": data = [(update.update_id, chat.id, user.id, date)] GroupRepository().insert_updates(data)
def init(update, context): user = user_object(update) nickname = "@" + user.username superban = SuperbanRepository().getById(user.id) if superban: msg = "<b>User id:</b> <code>{}</code>\n<b>Nickname:</b> {}\n<b>Blacklist:</b> ✅".format( user.id, nickname or user.first_name) else: msg = "<b>User id:</b> <code>{}</code>\n<b>Nickname:</b> {}\n<b>Blacklist:</b> ❌".format( user.id, nickname or user.first_name) message(update, context, msg)
def init(update, context): languages(update,context) bot = bot_object(update,context) user = user_object(update) get_user_lang = user.language_code if get_user_lang == 'it': message(update,context, "Ciao io mi chiamo {} e sono uno strumento per la gestione dei gruppi con tante funzioni speciali"\ " tutte da scoprire! e sono Open Source! Se vuoi vedere il mio sorgente digita:"\ " /source\nSe hai bisogno di aiuto digita /help".format("@"+bot.username)) else: message(update,context,languages.start.format("@"+bot.username))
def check_status(update,context): chat = chat_object(update) user = user_object(update) get_superban_user_id = update.effective_user.id user_db = UserRepository().getById(user.id) get_superban = SuperbanRepository().getById(get_superban_user_id) default_count_warn = 0 get_group = GroupRepository().getById(chat.id) user_photo = user.get_profile_photos(user.id) user_set_photo = get_group['set_user_profile_picture'] #warn_count = user_db['warn_count'] if user_db is not None else 0 #max_warn = get_group['max_warn'] #if warn_count == max_warn: #ban_user(update,context) #msg = "#Automatic Handler\n<code>{}</code> has reached the maximum number of warns" #message(update,context,msg.format(user.id)) if user.username is None or "": kick_user(update, context) msg = "#Automatic Handler\n<code>{}</code> set a username! You were kicked for safety!" message(update,context,msg.format(user.id)) if user_photo.total_count == 0 and user_set_photo == 1: kick_user(update, context) msg = "#Automatic Handler\n<code>{}</code> set a profile picture! You were kicked for safety!" message(update,context,msg.format(user.id)) if user_db: username = "******"+user.username data = [(username,user.id)] UserRepository().update(data) data_mtm = [(user.id, chat.id, default_count_warn)] UserRepository().add_into_mtm(data_mtm) if user_db is None or "": username = "******"+user.username default_warn = 0 data = [(user.id,username,default_warn)] UserRepository().add(data) data_mtm = [(user.id, chat.id, default_count_warn)] UserRepository().add_into_mtm(data_mtm) if get_superban: msg = 'I got super banned <a href="tg://user?id={}">{}</a>'.format(user.id,user.first_name) message(update,context,msg) delete_message(update,context) ban_user(update,context)
def init(update,context): user = user_object(update) img = 'https://i.imgur.com/CKU9Y75.png' kick_user_by_id(update, context, user.id) messagePhoto(update, context, img, 'You kicked yourself <code>[{}]</code>\nWe only used 15 lines of code to make a free feature, not paid\nPut a stars to our repository => /source'.format(user.id))
def check_status(update, context): # Telegram Variables bot = context.bot chat = chat_object(update) user = user_object(update) get_superban_user_id = update.effective_user.id user_photo = user.get_profile_photos(user.id) #Get Group via Database get_group = GroupRepository().getById(chat.id) #Get User via Database user_db = UserRepository().getById(user.id) #Get User via Database in Many to Many Association get_user = UserRepository().getUserByGroup([user.id, chat.id]) #Get User in Superban Table get_superban = SuperbanRepository().getById(get_superban_user_id) #Get User Warn warn_count = get_user[ 'warn_count'] if get_user is not None else DEFAULT_COUNT_WARN #Get Max Warn in group max_warn = get_group[ 'max_warn'] if get_group is not None else DEFAULT_MAX_WARN if get_group: user_set_photo = get_group['set_user_profile_picture'] type_no_username = get_group['type_no_username'] else: user_set_photo = 0 #Check if the user has a username if he does not have a username I perform a temporary kick and check that the user is not a service account if update.effective_user.id == SERVICE_ACCOUNT: print("Service Account") elif user.username is None or user.username == "": if type_no_username == 1: kick_user(update, context) msg = "#Automatic Handler\n<code>{}</code> set an username! You were kicked for safety!" message(update, context, msg.format(user.id)) elif type_no_username == 2: msg = "#Automatic Handler\n<code>{}</code> set an username!" message(update, context, msg.format(user.id)) elif type_no_username == 3: mute_user_by_id(update, context, user.id, True) msg = "#Automatic Handler\n<code>{}</code> set an username! You were Muted for safety!" message(update, context, msg.format(user.id)) elif type_no_username == 4: ban_user(update, context) msg = "#Automatic Handler\n<code>{}</code> was banned because they didn't have an username" message(update, context, msg.format(user.id)) elif type_no_username == 5: kick_user(update, context) else: print("No action even if you don't have a username") else: #Check if the user exists on the database if it exists makes an update of his username and his latest update if not exist insert it if user_db: #Get the Current Time current_time = datetime.datetime.utcnow().isoformat() username = "******" + user.username data = [(username, current_time, user.id)] UserRepository().update(data) data_mtm = [(user.id, chat.id, DEFAULT_COUNT_WARN)] UserRepository().add_into_mtm(data_mtm) else: #Get the Current Time current_time = datetime.datetime.utcnow().isoformat() username = "******" + user.username data = [(user.id, username, current_time, current_time)] UserRepository().add(data) data_mtm = [(user.id, chat.id, DEFAULT_COUNT_WARN)] UserRepository().add_into_mtm(data_mtm) #Check if the user has a profile photo if user_photo.total_count == 0 and user_set_photo == 1: kick_user(update, context) msg = "#Automatic Handler\n<code>{}</code> set a profile picture! You were kicked for safety!" message(update, context, msg.format(user.id)) #Check if the user has been blacklisted if get_superban: superban_reason = get_superban['motivation_text'] msg = '#Automatic Handler\nI got super banned <a href="tg://user?id={}">{}</a> <code>[{}]</code>\nFor the following Reason: {}'.format( user.id, user.first_name, user.id, superban_reason) message(update, context, msg) delete_message(update, context) ban_user(update, context) #Check if the user has reached the maximum number of warns and ban him if warn_count == max_warn: ban_user(update, context) msg = "#Automatic Handler\n<code>{}</code> has reached the maximum number of warns" message(update, context, msg.format(user.id)) if flood_manager.check_flood_wait( update) == 1 and get_group['set_antiflood'] == 1: bot.delete_message(update.effective_message.chat_id, update.message.message_id) kick_user(update, context) msg = "#Automatic Handler\n<code>{}</code> has been kicked for flood".format( user.id) message(update, context, msg.format(user.id))
def check_status(update, context): bot = context.bot chat_title = update.effective_chat.title chat_id = update.effective_chat.id get_bot = bot.getChatMember(chat_id, bot.id) get_group = GroupRepository().getById(chat_id) record_title = GroupRepository.SET_GROUP_NAME entities = list(update.effective_message.entities) get_chat_tg = bot.getChat(chat_id=chat_id) linked_chat = get_chat_tg.linked_chat_id group_members_count = update.effective_chat.get_member_count() #buttons = list(update.effective_message.reply_markup.inline_keyboard) """ This function updates the group id on the database when a group changes from group to supergroup """ if update.effective_message.migrate_from_chat_id is not None: old_chat_id = update.message.migrate_from_chat_id new_chat_id = update.message.chat.id data = [(new_chat_id, old_chat_id)] GroupRepository().update(data) message( update, context, "<b>#Automatic handler:</b>\nThe chat has been migrated to <b>supergroup</b> the bot has made the modification on the database.\n<i>It is necessary to put the bot admin</i>" ) debug_channel( update, context, "[DEBUG_LOGGER] La chat {} è stata modifica da Gruppo a Supergruppo il suo nuovo id è: {}" .format(old_chat_id, new_chat_id)) """ This function saves the group to the database when the bot is added as soon as a group or supergroup is created """ if update.effective_message.group_chat_created == True or update.effective_message.supergroup_chat_created == True: welcome_bot(update, context) l_txt = "#Log <b>Bot added to group</b> {}\nId: <code>{}</code>".format( chat_title, chat_id) telegram_loggers(update, context, l_txt) """ This feature changes the chat title on the database when it is changed """ if update.effective_message.new_chat_title: data = [(chat_title, chat_id)] GroupRepository().update_group_settings(record_title, data) debug_channel( update, context, "[DEBUG_LOGGER] La chat <code>[{}]</code> ha cambiato titolo". format(chat_id)) """ When a chat room changes group image it is saved to the webserver like this: example.com/group_photo/-100123456789.jpg (url variable) """ if update.effective_message.new_chat_photo: chat = chat_object(update) if chat.type == "supergroup" or chat.type == "group": file_id = update.message.new_chat_photo[2].file_id newFile = bot.get_file(file_id) newFile.download( '/var/www/naos.hersel.it/group_photo/{}.jpg'.format(chat_id)) url = "https://naos.hersel.it/group_photo/{}.jpg".format(chat_id) data = [(url, chat_id)] record = GroupRepository.SET_GROUP_PHOTO GroupRepository().update_group_settings(record, data) formatter = "New Url: {}".format(url) sys_loggers("[UPDATE_GROUP_PHOTO_LOGS]", formatter, False, True) debug_channel( update, context, "[DEBUG_LOGGER] La chat <code>[{}]</code> ha cambiato foto\nIl suo nuovo URL è: {}" .format(chat_id, url)) """ This function saves the number of users in the group in the database """ if group_members_count > 0: record_count = GroupRepository.SET_GROUP_MEMBERS_COUNT data = [(group_members_count, chat_id)] GroupRepository().update_group_settings(record_count, data) """ This function checks if the group is present in the blacklist if it is present the bot leaves the group """ if check_group_blacklist(update) == True: message( update, context, "<b>#Automatic handler:</b>\nThe group is blacklisted the bot will automatically exit the chat" ) log_txt = "#Log <b>Bot removed from group</b> {}\nId: <code>{}</code>".format( chat_title, chat_id) telegram_loggers(update, context, log_txt) time.sleep(2) bot.leave_chat(chat_id) debug_channel( update, context, "[DEBUG_LOGGER] Il bot è stato rimosso dalla chat <code>[{}]</code> perchè il gruppo è in Blacklist" .format(chat_id)) """ This function checks the badwords of the group """ if check_group_badwords(update) == True: user = user_object(update) bot.delete_message(update.effective_message.chat_id, update.message.message_id) message( update, context, "<b>#Automatic handler:</b>\n<code>{}</code> You used a forbidden word!" .format(user.id)) debug_channel( update, context, "[DEBUG_LOGGER] L'utente <code>{}</code> ha usato una parola proibita" .format(user.id)) """ This function checks if there is a badword in a link """ if entities is not None: for x in entities: if x['url'] is not None: bad_word = x['url'] row = GroupRepository().get_group_badwords([bad_word, chat_id]) if row: user = user_object(update) bot.delete_message(update.effective_message.chat_id, update.message.message_id) message( update, context, "<b>#Automatic handler:</b>\n<code>{}</code> You used a forbidden word!" .format(user.id)) """ This function checks if messages are arriving from a channel and deletes them """ if update.effective_message.sender_chat and get_group[ 'sender_chat_block'] == 1: sender_chat_obj = update.effective_message.sender_chat if update.effective_message.voice_chat_started: return elif update.effective_message.voice_chat_ended: return elif get_chat_tg.type == "channel": return elif sender_chat_obj.id == linked_chat: return else: message( update, context, "<b>#Automatic Handler:</b>\nIn this group <code>[{}]</code> it is not allowed to write with the\n{} <code>[{}]</code> channel" .format(chat_id, sender_chat_obj.title, sender_chat_obj.id)) bot.delete_message(update.effective_message.chat_id, update.message.message_id) """ This function checks that the bot is an administrator and sends an alert """ if get_bot.status == 'member': message( update, context, "I am not an administrator of this group, you have to make me an administrator to function properly!" ) debug_channel( update, context, "[DEBUG_LOGGER] Il bot non è un amministratore della chat {}". format(chat_id)) """ This function is used to filter messages with spoiler type and delete them if the group owner puts the block at 1 """ for a in entities: type_entities = a['type'] if type_entities is not None: if type_entities == "spoiler" and get_group['spoiler_block'] == 1: message( update, context, "<b>#Automatic Handler:</b>\nIn this chat the use of spoilers is not allowed!" ) bot.delete_message(update.effective_message.chat_id, update.message.message_id) #TODO NONETYPE PROBLEM """if buttons is not None: for url in buttons: if url[0]['url'] is not None: bad_word = url[0]['url'] or url[0]['text'] row = GroupRepository().get_group_badwords([bad_word, chat_id]) if row: user = user_object(update) bot.delete_message(update.effective_message.chat_id, update.message.message_id) message(update,context,"<b>#Automatic handler:</b>\n<code>{}</code> You used a forbidden word!".format(user.id)) else: print("no button")""" """ Voice audio blocking """ if update.effective_message.voice is not None and get_group[ 'set_no_vocal'] == 1: message( update, context, "<b>#Automatic Handler:</b>\nIs not allowed to use vocals in this chat!" ) bot.delete_message(update.effective_message.chat_id, update.message.message_id)