コード例 #1
0
def authorize_admin(update, context) -> None:
    global bot
    args = context.args
    chatid = update.message.chat_id

    if len(args) != 1:
        send_message(
            chatid,
            "You need to specify the admin password, use the command like /authorize_admin <b>password</b>",
            bot,
            html=True)
        return
    elif admin_pw == "":
        send_message(
            chatid,
            "The admin is disabled, check your telegram bot configuration",
            bot)
        return
    if Utils.admin_check(chatid):
        send_message(chatid, "You already are an admin", bot)
    elif args[0] == admin_pw:
        Utils.alchemy_instance.session.add(Admin(chatid))
        Utils.alchemy_instance.session.commit()
        send_message(chatid, "Admin enabled", bot)
        send_message(
            chatid,
            "Remember to disable the --admin-password if you want to avoid people trying to bruteforce this command",
            bot)
        logging.info(f"{chatid} got admin authorization")
    else:
        send_message(chatid, "The password is wrong", bot)
コード例 #2
0
def send_message_to_everyone(update, context) -> None:
    global bot
    args = context.args
    chatid = update.message.chat_id

    if not Utils.admin_check(chatid):
        send_message(chatid, "You're not authorized to do this", bot)
        return

    chatid_list = []
    message = ""
    start_time = datetime.datetime.now()

    logging.info(f"{chatid} started sending a message to everyone")

    chatid_list = Utils.alchemy_instance.session.query(
        PreferenceUser).filter_by(chat_id=str(chatid)).all()

    for word in args:
        message += f"{word} "
    message = message[:-1]

    for x in chatid_list:
        send_message(x.chat_id, message, bot)
    logging.info(
        f"{chatid} finished sending a message to everyone, took {(datetime.datetime.now() - start_time).total_seconds()} seconds"
    )
コード例 #3
0
def send_message_to_everyone(update, CallbackContext) -> None:
    global bot
    args = CallbackContext.args
    chatid = update.message.chat_id

    if Utils.admin_check(chatid) == False:
        send_message(chatid, "You're not authorized to do this", bot)
        return

    chatid_list = []
    message = ""
    start_time = datetime.datetime.now()

    logging.info(f"{chatid} started sending a message to everyone")

    results = Utils.retrieve_query_results("SELECT DISTINCT CHAT_ID FROM CHATURBATE")
    for row in results:
        chatid_list.append(row[0])

    for word in args:
        message += f"{word} "
    message = message[:-1]

    for x in chatid_list:
        send_message(x, message, bot)
    logging.info(
        f"{chatid} finished sending a message to everyone, took {(datetime.datetime.now() - start_time).total_seconds()} seconds")
コード例 #4
0
def view_stream_image_callback(update, CallbackContext):
    username = CallbackContext.match.string.replace("view_stream_image_callback_", "")
    chatid = update.callback_query.message.chat_id
    messageid = update.callback_query.message.message_id
    if Utils.is_chatid_temp_banned(chatid):
        return
    model_instance = Model(username)

    keyboard = [[InlineKeyboardButton("Watch the live", url=f'http://chaturbate.com/{username}'),
                 InlineKeyboardButton("Update stream image", callback_data='view_stream_image_callback_' + username)]]
    markup = InlineKeyboardMarkup(keyboard)

    try:
        bot.edit_message_media(chat_id=chatid, message_id=messageid,
                               media=telegram.InputMediaPhoto(model_instance.model_image,caption=f"{username} is now <b>online</b>!",parse_mode=telegram.ParseMode.HTML), reply_markup=markup)


    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} image update 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} image update 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} image update because is password protected')

    except (Exceptions.ModelDeleted, Exceptions.ModelBanned, Exceptions.ModelGeoblocked, Exceptions.ModelCanceled,
            Exceptions.ModelOffline):
        keyboard = [[InlineKeyboardButton("Watch the live", url=f'http://chaturbate.com/{username}')]]
        markup = InlineKeyboardMarkup(keyboard)
        bot.edit_message_reply_markup(chat_id=chatid, message_id=messageid, reply_markup=markup) #remove update image button
        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} image update')

    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} image update because of connection issues')

    except Exception as e:
        if hasattr(e, 'message'):
            if "Message is not modified" in e.message:
                send_message(chatid, f"This is the latest update of {username}", bot)
                if not Utils.admin_check(chatid):
                    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, 25)
                        send_message(chatid, "You have been temporarily banned for spamming, try again later", bot)
                        logging.warning(f"Soft banned {chatid} for 25 seconds for spamming image updates")
                    else:
                        Utils.set_last_spam_date(chatid, datetime.datetime.now())
コード例 #5
0
def active_models(update, CallbackContext) -> None:
    global bot
    chatid = update.message.chat_id
    if Utils.admin_check(chatid) == False:
        send_message(chatid, "You're not authorized to do this", bot)
        return

    models_count = Utils.retrieve_query_results("SELECT COUNT(DISTINCT USERNAME) FROM CHATURBATE")[0][0]
    send_message(chatid,f"The active models are {models_count}",bot)
コード例 #6
0
def active_users(update, CallbackContext) -> None:
    global bot
    chatid = update.message.chat_id
    if Utils.admin_check(chatid) == False:
        send_message(chatid, "You're not authorized to do this", bot)
        return

    users_count = Utils.retrieve_query_results("SELECT COUNT(CHAT_ID) FROM PREFERENCES")[0][0]
    send_message(chatid,f"The active users are {users_count}",bot)
コード例 #7
0
def active_models(update, context) -> None:
    global bot
    chatid = update.message.chat_id
    if not Utils.admin_check(chatid):
        send_message(chatid, "You're not authorized to do this", bot)
        return

    models_count = Utils.alchemy_instance.session.query(
        ChaturbateUser.username).distinct().count()
    send_message(chatid, f"The active models are {models_count}", bot)
コード例 #8
0
def active_users(update, context) -> None:
    global bot
    chatid = update.message.chat_id
    if not Utils.admin_check(chatid):
        send_message(chatid, "You're not authorized to do this", bot)
        return

    users_count = Utils.alchemy_instance.session.query(
        PreferenceUser).filter_by(chat_id=str(chatid)).count()
    send_message(chatid, f"The active users are {users_count}", bot)
コード例 #9
0
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')
コード例 #10
0
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')
コード例 #11
0
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')