def init(update, context): if update.message.reply_to_message: user = user_reply_object(update) row = SuperbanRepository().getWhitelistById(user.id) get_superban = SuperbanRepository().getById(user.id) if get_superban: buttons = [] buttons.append( InlineKeyboardButton('Remove Superban', callback_data='removeBL')) buttons.append( InlineKeyboardButton('Close', callback_data='closed')) menu = build_menu(buttons, 2) msg = "Attention the user is blacklisted! do you want to remove it?" update.message.reply_to_message.reply_text( msg, reply_markup=InlineKeyboardMarkup(menu), parse_mode='HTML') else: if row: message(update, context, "You have already whitelisted this user") else: user_username = "******" + user.username data = [(user.id, user_username)] SuperbanRepository().addWhitelist(data) message( update, context, "You have entered the user {} in the Whitelist".format( user_username)) else: message(update, context, "This message can only be used in response to a user")
def update_superban(update, context): bot = context.bot query = update.callback_query save_date = datetime.datetime.utcnow().isoformat() if query.data.startswith("m"): #Variables chat_id = query.message.chat_id operator_id = query.from_user.id operator_username = "******" + query.from_user.username user_id = query.message.reply_to_message.from_user.id motivation = query.data[1:] row = SuperbanRepository().getById(user_id) whitelist = SuperbanRepository().getWhitelistById(user_id) if whitelist: text_w = "This user is whitelisted you cannot blacklist!" query.edit_message_text(text_w, parse_mode='HTML') elif row: text = "Attention already superbanned user!" query.edit_message_text(text, parse_mode='HTML') else: data = [(user_id, motivation, save_date, operator_id)] SuperbanRepository().add(data) #Ban the User bot.ban_chat_member(chat_id, user_id) #Edit Message Text after push the button msg = 'You got super banned <a href="tg://user?id={}">{}</a>\nFor the following reason: <b>{}</b>\nGo to: https://squirrel-network.online/knowhere?q={} to search for blacklisted users'.format( user_id, user_id, motivation, user_id) query.edit_message_text(msg, parse_mode='HTML') #Telegram Logs logs_text = Strings.SUPERBAN_LOG.format(user_id, motivation, save_date, operator_username, operator_id) messageWithId(update, context, Config.DEFAULT_LOG_CHANNEL, logs_text) #System Logs formatter = "Superban eseguito da: {}".format(operator_id) sys_loggers("[SUPERBAN_LOGS]", formatter, False, False, True) debug_channel(update, context, "[DEBUG_LOGGER] {}".format(formatter)) if query.data == "removeSuperban": user_id = query.message.reply_to_message.from_user.id row = SuperbanRepository().getById(user_id) if row: data = [(user_id)] SuperbanRepository().remove(data) msg = "I removed the superban to user <code>{}</code>".format( user_id) query.edit_message_text(msg, parse_mode='HTML') else: query.edit_message_text("Attention this user not super banned!!!", parse_mode='HTML') if query.data == 'closeMenu': query.edit_message_text("You have closed the Menu", parse_mode='HTML')
def check_group_blacklist(update): chat_id = update.effective_chat.id row = SuperbanRepository().getGroupBlacklistById(chat_id) if row: return True else: return False
def remove_blacklist(update, context): query = update.callback_query user_id = query.message.reply_to_message.from_user.id if query.data == 'removeBL': user_id = query.message.reply_to_message.from_user.id row = SuperbanRepository().getById(user_id) if row: data = [(user_id)] SuperbanRepository().remove(data) msg = "I removed the superban to user <code>{}</code>".format( user_id) query.edit_message_text(msg, parse_mode='HTML') else: query.edit_message_text("Attention this user not super banned!!!", parse_mode='HTML') if query.data == 'closed': query.edit_message_text("You have closed the Menu", parse_mode='HTML')
def init(update, context): #Variables text = update.message.text operator_id = update.message.from_user.id operator_username = "******" + update.message.from_user.username save_date = datetime.datetime.utcnow().isoformat() #Build a Keyboard Buttons buttons = [] buttons.append(InlineKeyboardButton('Spam', callback_data='mSpam')) buttons.append(InlineKeyboardButton('Scam', callback_data='mScam')) buttons.append(InlineKeyboardButton('Userbot', callback_data='mUserbot')) buttons.append(InlineKeyboardButton('P**n', callback_data='mPorn')) buttons.append(InlineKeyboardButton('Other', callback_data='mOther')) buttons.append( InlineKeyboardButton('Illegal Content', callback_data='mIllegal_Content')) buttons.append( InlineKeyboardButton('Remove Superban', callback_data='removeSuperban')) buttons.append(InlineKeyboardButton('Close', callback_data='closeMenu')) menu = build_menu(buttons, 2) if update.message.reply_to_message: user_id = update.message.reply_to_message.from_user.id update.message.reply_to_message.reply_text( "Select a reason for the Superban", reply_markup=InlineKeyboardMarkup(menu)) else: input_user_id = text[2:].strip().split(" ", 1) user_id = input_user_id[0] if user_id != "": number = re.search(Regex.HAS_NUMBER, user_id) if number is None: message(update, context, "Attention you must enter a number not letters!") else: default_motivation = "Other" data = [(user_id, default_motivation, save_date, operator_id)] SuperbanRepository().add(data) msg = 'You got super banned <a href="tg://user?id={}">{}</a>\nFor the following reason: <b>{}</b>\nGo to: https://squirrel-network.online/knowhere/?q={} to search for blacklisted users'.format( user_id, user_id, default_motivation, user_id) message(update, context, msg) logs_text = Strings.SUPERBAN_LOG.format( user_id, default_motivation, save_date, operator_username, operator_id) messageWithId(update, context, Config.DEFAULT_LOG_CHANNEL, logs_text) formatter = "Superban eseguito da: {}".format(operator_id) sys_loggers("[SUPERBAN_LOGS]", formatter, False, False, True) debug_channel(update, context, "[DEBUG_LOGGER] {}".format(formatter)) else: message( update, context, "Attention you can not superbanned without entering an TELEGRAM ID!" )
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 multi_superban(update, context): txt = update.message.text x = re.findall(r'\d+', txt) string = "MultiSuperban eseguito! dei seguenti id:\n" for a in x: save_date = datetime.datetime.utcnow().isoformat() default_motivation = "MultiSuperban" operator_id = update.message.from_user.id data = [(a, default_motivation, save_date, operator_id)] SuperbanRepository().add(data) string += "▪️ {}\n".format(a) message(update, context, string)
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): motivation = update.message.text[2:].strip() reply = update.message.reply_to_message if reply is not None: if motivation != "": user_id = reply.from_user.id save_date = datetime.datetime.utcnow().isoformat() operator_id = update.message.from_user.id data = [(user_id,motivation,save_date,operator_id)] SuperbanRepository().add(data) ban_user_reply(update,context) delete_message_reply(update,context) logs_text = Strings.SUPERBAN_LOG.format(user_id,motivation,save_date,operator_id) msg = 'You got super banned <a href="tg://user?id={}">{}</a>\nGo to: https://squirrel-network.online/knowhere'.format(user_id,user_id) message(update,context,msg) telegram_loggers(update,context,logs_text) formatter = "Superban eseguito da: {}".format(update.message.from_user.id) sys_loggers("[SUPERBAN_LOGS]",formatter,False,False,True) else: message(update,context,"You need to specify a reason for the <b>superban!</b>") else: message(update,context,"You must use this command in response to a user!")
def is_in_blacklist(uid): return not not SuperbanRepository().getById(uid)
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))