Exemple #1
0
def leaver(app, message):
    chat_id = message.chat.id
    try:
        text = message.text.split(" ", 1)[1]
        message.edit(f"**{text}**")
    except:
        message.edit("**До связи**")
    app.leave_chat(chat_id)
def leave_chat(client: Client, cid: int, delete: bool = False) -> bool:
    # Leave a channel
    try:
        flood_wait = True
        while flood_wait:
            flood_wait = False
            try:
                client.leave_chat(chat_id=cid, delete=delete)
            except FloodWait as e:
                flood_wait = True
                wait_flood(e)
            except (PeerIdInvalid, ChannelInvalid, ChannelPrivate):
                return False

        return True
    except Exception as e:
        logger.warning(f"Leave chat {cid} error: {e}", exc_info=True)

    return False
Exemple #3
0
def leave_chat(client: Client, cid: int, delete: bool = False) -> bool:
    # Leave a channel
    result = False

    try:
        result = client.leave_chat(chat_id=cid, delete=delete) or True
    except FloodWait as e:
        raise e
    except (ChannelInvalid, ChannelPrivate, PeerIdInvalid):
        return False
    except Exception as e:
        logger.warning(f"Leave chat {cid} error: {e}", exc_info=True)

    return result
Exemple #4
0
         #     break
         sleep(random() / 77.7)
         with open("{}.txt".format(chat.title), "a") as file:
             if message.text:
                 file.write("<message views='{}'>\t{}\n".format(
                     message.views,
                     " ".join(message.text.splitlines())))
             elif message.media:
                 file.write("<media_m views='{}'>\t{}\n".format(
                     message.views,
                     " ".join(message.caption.splitlines())
                     if message.caption else ""))
             else:
                 continue
                 # file.write("<s_fuck>\t{}\n".format(str(message)))
     app.leave_chat(channel_code)
     b = time()
     with open("_speed_stats.txt", "a") as file:
         file.write("{\n\t")
         file.write("\n\t".join([
             chat.title, "{}s {}ms".format(int(b - a),
                                           int((b - a) * 1000) % 1000),
             "{} messages".format(messages_count)
         ]))
         file.write("\n}\n\n")
     # print(chat.title, "{}s".format(b - a), messages_count)
 except Exception as e:
     with open("_speed_stats.txt", "a") as file:
         file.write("notfound '{}'\n\n".format(channel_code))
     # print("{} doesn't not exists at this point".format(channel_code))
     print(Exception(e))
Exemple #5
0
from pyrogram import Client

# Bot will leave all of non admin right group.
app = Client("silencert")
app.start()
dialogs = app.iter_dialogs()
me = app.get_me()
for d in dialogs:
    try:
        member = app.get_chat_member(d.chat.id, me.id)
        if member.status != "administrator":
            print("LEAVE", d.chat.title)
            app.leave_chat(d.chat.id)
        else:
            print('STAY', d.chat.title)
    except Exception as e:
        print('ERROR', d.chat.title)
app.stop()