def remove(update, context) -> None: global bot args = context.args chatid = update.message.chat_id username_message_list = [] usernames_in_database = [] if len(args) < 1: send_message( chatid, "You need to specify an username to follow, use the command like /remove <b>test</b>\n You can also remove multiple users at the same time by separating them using a comma, like /remove <b>username1</b>,<b>username2</b>", bot, html=True) return if len(args) > 1: for username in args: if username != "": username_message_list.append( Utils.sanitize_username(username).replace(",", "")) # len(args)==0 -> only one username or all in one line elif "," in args[0].lower(): for splitted_username in args[0].lower().replace( " ", "").rstrip().split(","): if splitted_username != "": username_message_list.append( Utils.sanitize_username(splitted_username)) else: username_message_list.append(Utils.sanitize_username(args[0])) usernames_in_database = Utils.alchemy_instance.session.query( ChaturbateUser).filter_by(chat_id=str(chatid)).all() if "all" in username_message_list: Utils.alchemy_instance.session.query(ChaturbateUser).filter_by( chat_id=str(chatid)).all().delete(synchronize_session=False) Utils.alchemy_instance.session.commit() send_message(chatid, "All usernames have been removed", bot) logging.info(f"{chatid} removed all usernames") else: for username in username_message_list: if username in usernames_in_database: Utils.alchemy_instance.session.query(ChaturbateUser).filter_by( chat_id=str(chatid), username=str(username)).delete(synchronize_session=False) send_message(chatid, f"{username} has been removed", bot) logging.info(f"{chatid} removed {username}") else: send_message(chatid, f"You aren't following {username}", bot)
def remove(update, CallbackContext) -> None: global bot args = CallbackContext.args chatid = update.message.chat_id username_message_list = [] usernames_in_database = [] if len(args) < 1: send_message( chatid, "You need to specify an username to follow, use the command like /remove <b>test</b>\n You can also remove multiple users at the same time by separating them using a comma, like /remove <b>username1</b>,<b>username2</b>", bot, html=True ) return if len(args) > 1: for username in args: if username != "": username_message_list.append(Utils.sanitize_username(username).replace(",", "")) # len(args)==0 -> only one username or all in one line elif "," in args[0].lower(): for splitted_username in args[0].lower().replace(" ", "").rstrip().split(","): if splitted_username != "": username_message_list.append(Utils.sanitize_username(splitted_username)) else: username_message_list.append(Utils.sanitize_username(args[0])) results = Utils.retrieve_query_results(f"SELECT * FROM CHATURBATE WHERE CHAT_ID='{chatid}'") for row in results: usernames_in_database.append(row[0]) if "all" in username_message_list: Utils.exec_query( f"DELETE FROM CHATURBATE WHERE CHAT_ID='{chatid}'") send_message(chatid, "All usernames have been removed", bot) logging.info(f"{chatid} removed all usernames") else: for username in username_message_list: if username in usernames_in_database: Utils.exec_query(f"DELETE FROM CHATURBATE WHERE USERNAME='******' AND CHAT_ID='{chatid}'") send_message(chatid, f"{username} has been removed", bot) logging.info(f"{chatid} removed {username}") else: send_message(chatid, f"You aren't following {username}", bot)
def stream_image(update, CallbackContext) -> None: global bot args = CallbackContext.args chatid = update.message.chat_id if len(args) < 1: send_message(chatid, "You didn't specify a model to get the stream image of\nUse the command like this: /stream_image <b>username</b>", bot, html=True) return username = Utils.sanitize_username(args[0]) model_instance = Model(username) if not Utils.admin_check(chatid): if Utils.is_chatid_temp_banned(chatid): return if Utils.get_last_spam_date(chatid) == None: Utils.set_last_spam_date(chatid, datetime.datetime.now()) elif (datetime.datetime.now() - Utils.get_last_spam_date(chatid)).total_seconds() <= 3: Utils.temp_ban_chatid(chatid, 10) send_message(chatid,"You have been temporarily banned for spamming, try again later", bot) logging.warning(f"Soft banned {chatid} for 10 seconds for spamming image updates") else: Utils.set_last_spam_date(chatid, datetime.datetime.now()) try: send_image(chatid, model_instance.model_image, bot) logging.info(f'{chatid} viewed {username} stream image') except Exceptions.ModelPrivate: send_message(chatid, f"The model {username} is in private now, try again later", bot) logging.warning(f'{chatid} could not view {username} stream image because is private') except Exceptions.ModelAway: send_message(chatid, f"The model {username} is away, try again later", bot) logging.warning(f'{chatid} could not view {username} stream image because is away') except Exceptions.ModelPassword: send_message(chatid, f"The model {username} cannot be seen because is password protected", bot) logging.warning(f'{chatid} could not view {username} stream image because is password protected') except (Exceptions.ModelDeleted, Exceptions.ModelBanned, Exceptions.ModelGeoblocked, Exceptions.ModelCanceled, Exceptions.ModelOffline): send_message(chatid, f"The model {username} cannot be seen because is {model_instance.status}", bot) logging.warning(f'{chatid} could not view {username} image update because is {model_instance.status}') except Exceptions.ModelNotViewable: send_message(chatid, f"The model {username} is not visible", bot) logging.warning(f'{chatid} could not view {username} stream image') except ConnectionError: send_message(chatid, f"The model {username} cannot be seen because of connection issues, try again later", bot) logging.warning(f'{chatid} could not view {username} stream image because of connection issues')
def crawl(q, model_instances_dict): while not q.empty(): username = Utils.sanitize_username(q.get()[1].username) model_instance = Model(username, autoupdate=False) model_instance.update_model_status() try: model_instance.update_model_image() except Exception: model_instance.model_image = None # set to None just to be secure Todo: this may be extra model_instances_dict[username] = model_instance # signal to the queue that task has been processed q.task_done() return True
def add(update, context) -> None: global bot args = context.args chatid = update.message.chat_id username_message_list = [] if len(args) < 1: send_message( chatid, "You need to specify an username to follow, use the command like /add <b>username</b>\n You can also add multiple users at the same time by separating them using a comma, like /add <b>username1</b>,<b>username2</b>", bot, html=True) return # not lowercase usernames bug the api calls if len(args) > 1: for username in args: if username != "": username_message_list.append( Utils.sanitize_username(username).replace(",", "")) # len(args)==0 -> only one username or all in one line elif "," in args[0].lower(): for splitted_username in args[0].lower().replace( " ", "").rstrip().split(","): if splitted_username != "": username_message_list.append( Utils.sanitize_username(splitted_username)) else: username_message_list.append(Utils.sanitize_username(args[0])) username_message_list = list( dict.fromkeys(username_message_list)) # remove duplicate usernames usernames_in_database = Utils.alchemy_instance.session.query( ChaturbateUser).filter_by(chat_id=str(chatid)).all() # 0 is unlimited usernames if len(usernames_in_database) + len( username_message_list) > user_limit and ( Utils.admin_check(chatid) == False != user_limit != 0): send_message( chatid, "You are trying to add more usernames than your limit permits, which is " + str(user_limit), bot) logging.info( f'{chatid} tried to add more usernames than his limit permits') return for username in username_message_list: model_instance = Model(username) if model_instance.status not in ('deleted', 'banned', 'geoblocked', 'canceled', 'error'): if username not in usernames_in_database: Utils.alchemy_instance.session.add( ChaturbateUser(username=username, chat_id=chatid, online=False)) Utils.alchemy_instance.session.commit() send_message(chatid, f"{username} has been added", bot) logging.info(f'{chatid} added {username}') else: send_message(chatid, f"{username} has already been added", bot) elif model_instance.status == 'deleted': send_message(chatid, f"{username} has not been added because is deleted", bot) logging.info( f"{chatid} could not add {username} because is deleted") elif model_instance.status == 'banned': send_message(chatid, f"{username} has not been added because is banned", bot) logging.info( f"{chatid} could not add {username} because is banned") elif model_instance.status == 'geoblocked': send_message( chatid, f"{username} has not been added because is geoblocked", bot) logging.info( f"{chatid} could not add {username} because is geoblocked") elif model_instance.status == 'canceled': send_message(chatid, f"{username} was not added because it doesn't exist", bot) logging.info( f'{chatid} tried to add {username}, which does not exist') elif model_instance.status == 'error': send_message( chatid, f"{username} was not added because an error happened", bot) logging.info( f'{chatid} could not add {username} because an error happened')
def add(update, CallbackContext) -> None: global bot args = CallbackContext.args chatid = update.message.chat_id username_message_list = [] if len(args) < 1: send_message( chatid, "You need to specify an username to follow, use the command like /add <b>username</b>\n You can also add multiple users at the same time by separating them using a comma, like /add <b>username1</b>,<b>username2</b>", bot, html=True ) return # not lowercase usernames bug the api calls if len(args) > 1: for username in args: if username != "": username_message_list.append(Utils.sanitize_username(username).replace(",", "")) # len(args)==0 -> only one username or all in one line elif "," in args[0].lower(): for splitted_username in args[0].lower().replace(" ", "").rstrip().split(","): if splitted_username != "": username_message_list.append(Utils.sanitize_username(splitted_username)) else: username_message_list.append(Utils.sanitize_username(args[0])) username_message_list = list(dict.fromkeys(username_message_list)) # remove duplicate usernames usernames_in_database = [] # obtain present usernames results = Utils.retrieve_query_results(f"SELECT USERNAME FROM CHATURBATE WHERE CHAT_ID='{chatid}'") for row in results: usernames_in_database.append(row[0]) # 0 is unlimited usernames if len(usernames_in_database) + len(username_message_list) > user_limit and ( Utils.admin_check(chatid) == False != user_limit != 0): send_message(chatid, "You are trying to add more usernames than your limit permits, which is " + str(user_limit), bot) logging.info(f'{chatid} tried to add more usernames than his limit permits') return for username in username_message_list: model_instance=Model(username) if model_instance.status not in ('deleted', 'banned', 'geoblocked', 'canceled', 'error'): if username not in usernames_in_database: Utils.exec_query(f"INSERT INTO CHATURBATE VALUES ('{username}', '{chatid}', 'F')") send_message(chatid, f"{username} has been added", bot) logging.info(f'{chatid} added {username}') else: send_message(chatid,f"{username} has already been added",bot) elif model_instance.status=='deleted': send_message(chatid, f"{username} has not been added because is deleted", bot) logging.info(f"{chatid} could not add {username} because is deleted") elif model_instance.status=='banned': send_message(chatid, f"{username} has not been added because is banned", bot) logging.info(f"{chatid} could not add {username} because is banned") elif model_instance.status=='geoblocked': send_message(chatid, f"{username} has not been added because is geoblocked", bot) logging.info(f"{chatid} could not add {username} because is geoblocked") elif model_instance.status=='canceled': send_message(chatid, f"{username} was not added because it doesn't exist", bot) logging.info(f'{chatid} tried to add {username}, which does not exist') elif model_instance.status=='error': send_message(chatid, f"{username} was not added because an error happened", bot) logging.info(f'{chatid} could not add {username} because an error happened')