예제 #1
0
def remove_url(bot, update):
    args = context.args
    if len(args) >= 1:
        tg_chat_id = str(update.effective_chat.id)

        tg_feed_link = args[0]

        link_processed = parse(tg_feed_link)

        if link_processed.bozo == 0:
            user_data = sql.check_url_availability(tg_chat_id, tg_feed_link)

            if user_data:
                sql.remove_url(tg_chat_id, tg_feed_link)

                send_message(
                    update.effective_message,
                    tl(update.effective_message, "URL dihapus dari langganan"))
            else:
                send_message(
                    update.effective_message,
                    tl(update.effective_message,
                       "Anda belum berlangganan ke URL ini"))
        else:
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Tautan ini bukan tautan Umpan RSS"))
    else:
        send_message(update.effective_message,
                     tl(update.effective_message, "URL hilang"))
예제 #2
0
def remove_url(bot, update, args):
    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id, update.effective_message)
    if spam == True:
        return
    if len(args) >= 1:
        tg_chat_id = str(update.effective_chat.id)

        tg_feed_link = args[0]

        link_processed = parse(tg_feed_link)

        if link_processed.bozo == 0:
            user_data = sql.check_url_availability(tg_chat_id, tg_feed_link)

            if user_data:
                sql.remove_url(tg_chat_id, tg_feed_link)

                update.effective_message.reply_text(
                    "URL dihapus dari langganan")
            else:
                update.effective_message.reply_text(
                    "Anda belum berlangganan ke URL ini")
        else:
            update.effective_message.reply_text(
                "Tautan ini bukan tautan Umpan RSS")
    else:
        update.effective_message.reply_text("URL hilang")
예제 #3
0
def rss_update(context):
    job = context.job
    user_data = sql.get_all()

    # this loop checks for every row in the DB
    for row in user_data:
        row_id = row.id
        tg_chat_id = row.chat_id
        tg_is_pinned = row.is_pinned
        tg_feed_link = row.feed_link

        feed_processed = parse(tg_feed_link)

        tg_old_entry_link = row.old_entry_link

        new_entry_links = []
        new_entry_titles = []

        # this loop checks for every entry from the RSS Feed link from the DB row
        for entry in feed_processed.entries:
            # check if there are any new updates to the RSS Feed from the old entry
            if entry.link != tg_old_entry_link:
                new_entry_links.append(entry.link)
                new_entry_titles.append(entry.title)
            else:
                break

        # check if there's any new entries queued from the last check
        if new_entry_links:
            sql.update_url(row_id, new_entry_links)
        else:
            pass

        if len(new_entry_links) < 5:
            # this loop sends every new update to each user from each group based on the DB entries
            for link, title in zip(reversed(new_entry_links),
                                   reversed(new_entry_titles)):
                final_message = "<b>{}</b>\n\n{}".format(
                    html.escape(title), html.escape(link))

                if len(final_message) <= constants.MAX_MESSAGE_LENGTH:
                    try:
                        rssmsg = context.bot.send_message(
                            chat_id=tg_chat_id,
                            text=final_message,
                            parse_mode=ParseMode.HTML)
                        if tg_is_pinned:
                            try:
                                context.bot.pinChatMessage(
                                    tg_chat_id, rssmsg.message_id)
                            except:
                                pass
                    except error.Unauthorized:
                        print("Cannot send msg bcz bot is kicked")
                        sql.remove_url(tg_chat_id, tg_feed_link)
                else:
                    try:
                        context.bot.send_message(
                            chat_id=tg_chat_id,
                            text=tl(
                                tg_chat_id,
                                "<b>Peringatan:</b> Pesan terlalu panjang untuk dikirim"
                            ),
                            parse_mode=ParseMode.HTML)
                    except error.Unauthorized:
                        print("Cannot send msg bcz bot is kicked")
                        sql.remove_url(tg_chat_id, tg_feed_link)
        else:
            for link, title in zip(reversed(new_entry_links[-5:]),
                                   reversed(new_entry_titles[-5:])):
                final_message = "<b>{}</b>\n\n{}".format(
                    html.escape(title), html.escape(link))

                if len(final_message) <= constants.MAX_MESSAGE_LENGTH:
                    try:
                        rssmsg = context.bot.send_message(
                            chat_id=tg_chat_id,
                            text=final_message,
                            parse_mode=ParseMode.HTML)
                        if tg_is_pinned:
                            try:
                                context.bot.pinChatMessage(
                                    tg_chat_id, rssmsg.message_id)
                            except:
                                pass
                    except error.Unauthorized:
                        sql.remove_url(tg_chat_id, tg_feed_link)
                else:
                    try:
                        context.bot.send_message(
                            chat_id=tg_chat_id,
                            text=tl(
                                tg_chat_id,
                                "<b>Peringatan:</b> Pesan terlalu panjang untuk dikirim"
                            ),
                            parse_mode=ParseMode.HTML)
                    except error.Unauthorized:
                        sql.remove_url(tg_chat_id, tg_feed_link)

            try:
                context.bot.send_message(
                    chat_id=tg_chat_id,
                    parse_mode=ParseMode.HTML,
                    text=tl(
                        tg_chat_id,
                        "<b>Peringatan: </b>{} kejadian telah ditinggalkan untuk mencegah spam"
                    ).format(len(new_entry_links) - 5))
            except error.Unauthorized:
                sql.remove_url(tg_chat_id, tg_feed_link)