def get_muted_chats(bot: Bot, update: Update, leave: bool = False):

    chat_id = update.effective_chat.id
    chats = user_sql.get_all_chats()
    muted_chats, progress = 0, 0
    chat_list = []
    progress_message = None

    for chat in chats:

        if ((100 * chats.index(chat)) / len(chats)) > progress:
            progress_bar = f"{progress}% completed in getting muted chats."
            if progress_message:
                try:
                    bot.editMessageText(progress_bar, chat_id,
                                        progress_message.message_id)
                except:
                    pass
            else:
                progress_message = bot.sendMessage(chat_id, progress_bar)
            progress += 5

        id = chat.chat_id
        sleep(0.1)

        try:
            bot.send_chat_action(id, "TYPING", timeout=60)
        except (BadRequest, Unauthorized):
            muted_chats += +1
            chat_list.append(id)
        except:
            pass

    try:
        progress_message.delete()
    except:
        pass

    if not leave:
        return muted_chats
    else:
        for muted_chat in chat_list:
            sleep(0.1)
            try:
                bot.leaveChat(muted_chat, timeout=60)
            except:
                pass
            user_sql.rem_chat(muted_chat)
        return muted_chats
Beispiel #2
0
def rem_chat(bot: Bot, update: Update):
    msg = update.effective_message
    chats = sql.get_all_chats()
    kicked_chats = 0
    for chat in chats:
        id = chat.chat_id
        sleep(0.1) # Reduce floodwait
        try:
            bot.get_chat(id, timeout=60)
        except (BadRequest, Unauthorized):
            kicked_chats += 1
            sql.rem_chat(id)
    if kicked_chats >= 1:
        msg.reply_text("Done! {} chats were removed from the database!".format(kicked_chats))
    else:
        msg.reply_text("No chats had to be removed from the database!")
Beispiel #3
0
def get_invalid_chats(update: Update,
                      context: CallbackContext,
                      remove: bool = False):
    bot = context.bot
    chat_id = update.effective_chat.id
    chats = user_sql.get_all_chats()
    kicked_chats, progress = 0, 0
    chat_list = []
    progress_message = None

    for chat in chats:

        if ((100 * chats.index(chat)) / len(chats)) > progress:
            progress_bar = f"{progress}% completed in getting invalid chats."
            if progress_message:
                try:
                    bot.editMessageText(progress_bar, chat_id,
                                        progress_message.message_id)
                except:
                    pass
            else:
                progress_message = bot.sendMessage(chat_id, progress_bar)
            progress += 5

        cid = chat.chat_id
        sleep(0.1)
        try:
            bot.get_chat(cid, timeout=60)
        except (BadRequest, Unauthorized):
            kicked_chats += 1
            chat_list.append(cid)
        except:
            pass

    try:
        progress_message.delete()
    except:
        pass

    if not remove:
        return kicked_chats
    else:
        for muted_chat in chat_list:
            sleep(0.1)
            user_sql.rem_chat(muted_chat)
        return kicked_chats
def dbcleanup(bot: Bot, update: Update):

    msg = update.effective_message
    msg.reply_text("Cleaning up chats ...")

    chats = user_sql.get_all_chats()
    kicked_chats = 0

    for chat in chats:
        id = chat.chat_id
        sleep(0.1)  # Reduce floodwait
        try:
            bot.get_chat(id, timeout=60)
        except (BadRequest, Unauthorized):
            kicked_chats += 1
            user_sql.rem_chat(id)

    if kicked_chats >= 1:
        msg.reply_text("Done! {} chats were removed from the database!".format(
            kicked_chats))
    else:
        msg.reply_text("No chats had to be removed from the database!")

    msg.reply_text("Cleaning up gbans ...")

    banned = gban_sql.get_gban_list()
    ungbanned_users = 0

    for user in banned:
        user_id = user["user_id"]
        sleep(0.1)
        try:
            bot.get_chat(user_id)
        except BadRequest:
            ungbanned_users += 1
            gban_sql.ungban_user(user_id)

    if ungbanned_users >= 1:
        msg.reply_text("Done! {} users were removed from the database!".format(
            ungbanned_users))
    else:
        msg.reply_text("No users had to be removed from the database!")