-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
66 lines (49 loc) · 2.16 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
61
62
63
64
65
66
import logging
import os
from pyrogram import Client, filters, enums
from pyrogram.enums import ChatMemberStatus
from pyrogram.raw import functions
from pyrogram.types import Message
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)s %(message)s')
api_hash = os.getenv('API_HASH')
api_id = os.getenv('API_ID')
if not api_hash or not api_id:
logging.fatal('Missing API_HASH or API_ID')
app = Client(api_hash=api_hash, api_id=int(api_id), name='userbot')
@app.on_message(filters=filters.group & filters.command(['superban', 'megaban']))
async def ban_via_reaction(client: Client, message: Message):
logging.info(f'Received superban from {message.from_user.id}')
user = await client.get_chat_member(message.chat.id, message.from_user.id)
if user.status not in [ChatMemberStatus.OWNER, ChatMemberStatus.ADMINISTRATOR]:
logging.warning('User is not owner/admin')
return
await message.delete()
r = await client.invoke(functions.messages.GetMessageReactionsList(
peer=await app.resolve_peer(message.chat.id),
id=message.reply_to_message.id,
limit=10,
))
if 'superban' in message.command:
if len(r.reactions) == 0:
await message.reply_text('🤔 Non ci sono reazioni')
return
if len(r.reactions) > 1:
await message.reply_text('❌ È presente più di una reazione')
return
user_id = r.reactions[0].peer_id.user_id
await ban(client, message, user_id)
elif 'megaban' in message.command:
for r in r.reactions:
user_id = r.peer_id.user_id
await ban(client, message, user_id)
async def ban(client: Client, message: Message, user_id: int):
logging.info(f'Banning {user_id}')
try:
await client.ban_chat_member(message.chat.id, user_id)
except:
logging.exception('Could not ban user')
await message.reply_text(f'❌ Non sono riuscito a bannare l\'utente `{user_id}`',
parse_mode=enums.ParseMode.MARKDOWN)
return
await message.reply_text(f'✅ Utente `{user_id}` bannato', parse_mode=enums.ParseMode.MARKDOWN)
app.run()