forked from samadii/remove-all-members
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
60 lines (46 loc) · 1.84 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
'''
this code by yeuda by https://t.me/m100achuz
pip install Pyrogram
https://github.com/pyrogram/pyrogram.git
'''
import os
from pyrogram import Client
from pyrogram import filters
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, Message
app_id = int(os.environ.get("API_ID", 12345))
app_key = os.environ.get('API_HASH')
token = os.environ.get('BOT_TOKEN')
channel_id = os.environ.get("CHANNEL_ID")
app = Client("remove", app_id, app_key, bot_token=token)
STARTED = 'start removing users...'
FINISH = 'done, {} users were removed from group'
ERROR = 'something failed!'
ADMIN_NEEDED = "i need to be admin!"
PRIVATE = '''Hi, I'm a robot to help you remove all users from your group.
Now add me to a group and don't forget to give me the permissions.
Then send /kick in the group and I will start my work.'''
@app.on_message(filters.group & filters.command("kick"))
def main(_, msg: Message):
chat = msg.chat
me = chat.get_member(app.get_me().id)
if chat.get_member(msg.from_user.id).can_manage_chat and me.can_restrict_members and me.can_delete_messages:
try:
msg.reply(STARTED.format(chat.members_count))
count_kicks = 0
for member in chat.iter_members():
if not member.can_manage_chat:
chat.kick_member(member.user.id)
count_kicks += 1
msg.reply(FINISH.format(count_kicks))
except Exception as e:
msg.reply(ERROR.format(str(e)))
else:
msg.reply(ADMIN_NEEDED)
# @app.on_message(filters.group & filters.service, group=2)
# def service(c, m):
# m.delete()
@app.on_message(filters.private)
def start(_, msg: Message):
msg.reply(PRIVATE, reply_markup=InlineKeyboardMarkup([[
InlineKeyboardButton("Source Code", url="https://www.github.com/samadii/remove-all-members")]]))
app.run()