コード例 #1
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())
コード例 #2
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')