def remove(bot, update, user_data):
    user = update.message.from_user

    input_text = update.message.text
    rss_list = user_data["rss_list"]

    for rss in rss_list:
        if rss.admin_chat_id == str(
                user.id) and rss.rss_url + rss.channel_user_name == input_text:
            remove_rss(rss)
    update.message.reply_text(BotMessage.remove_success)
    start(bot, update)
    return ConversationHandler.END
def get_rss_and_add_it(bot, update, user_data):
    rss_url = update.message.text
    admin = update.message.from_user
    channel_user_name = user_data["channel_user_name"]
    channel_chat_id = user_data["channel_chat_id"]
    rss = RSS(channel_chat_id,
              channel_user_name,
              admin_chat_id=admin.id,
              admin_user_name=admin.username,
              rss_url=rss_url)
    add_rss(rss)
    update.message.reply_text(BotMessage.rss_added_successfully)
    start(bot, update)
    return ConversationHandler.END
Example #3
0
def get_rss_list(bot, update):
    user = update.message.from_user
    rss_list = get_rss_by_admin_chat_id(user.id)
    if rss_list:
        text = "*لیست فیدخوان های شما* \n"
        for rss in rss_list:
            text += "کانال: {} // فیدخوان: {}\n\n".format(
                rss.channel_user_name, rss.rss_url)
        update.message.reply_text(text)
        start(bot, update)
        return ConversationHandler.END
    else:
        update.message.reply_text(BotMessage.no_rss)
        start(bot, update)
        return ConversationHandler.END
def select_rss(bot, update, user_data):
    user = update.message.from_user
    rss_list = get_rss_by_admin_chat_id(user.id)
    if rss_list:
        user_data["rss_list"] = rss_list
        buttons = []
        for rss in rss_list:
            buttons.append(rss.rss_url + rss.channel_user_name)
        reply_keyboard = [[Keyboards.back_to_main] + buttons]
        reply_markup = ReplyKeyboardMarkup(keyboard=reply_keyboard)
        update.message.reply_text(BotMessage.select_rss,
                                  reply_markup=reply_markup)
        return ConversationStates.RSS
    else:
        update.message.reply_text(BotMessage.no_rss)
        start(bot, update)
        return ConversationHandler.END
def check_is_admin(bot, update, user_data):
    user = update.message.from_user
    input_message = update.message.text
    pattern = re.compile("@([A-Za-z0-9_]+)")
    if not pattern.match(input_message):
        update.message.reply_text(BotMessage.invalid_username)
        start(bot, update)
        return ConversationHandler.END
    if is_admin(user.id, input_message):
        channel_user_name = input_message
        user_data["channel_user_name"] = channel_user_name
        channel_chat = bot.get_chat(channel_user_name)
        user_data["channel_chat_id"] = channel_chat.id
        update.message.reply_text(BotMessage.enter_rss_url)
        return ConversationStates.RSS
    else:
        update.message.reply_text(BotMessage.not_permitted)
        return ConversationHandler.END