-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
90 lines (57 loc) · 2.5 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import os
import asyncio
import config
import logging
from pyrogram import Client, filters
from core.checker import video_checker,image_checker
from pyrogram.types import Message
logging.basicConfig(format='[%(levelname) 5s/%(asctime)s] %(name)s: %(message)s',
level=logging.INFO)
app = Client("Linux64",api_id=config.API_ID,api_hash=config.API_HASH,bot_token=config.BOT_TOKEN,in_memory=True)
@app.on_message(filters.chat(config.GROUP_ID))
async def group_handler(client:Client,message:Message):
logging.info("GROUP_HANDLER TRIGGERED")
if message.photo:
logging.info("Analyzing Photo")
file_path = await message.download()
if image_checker(file_path=file_path):
logging.info("NSFW Detected")
resp = await message.reply("Analyzing...")
await asyncio.sleep(2)
await resp.edit_text("NSFW Detected")
await message.delete()
await resp.edit_text("Message Removed")
await asyncio.sleep(2)
await client.delete_messages(message.chat.id,resp.id)
os.remove(file_path)
# Delete
if message.video :
logging.info("Analyzing Video")
file_path = await message.download()
if video_checker(file_path=file_path):
logging.info("NSFW Detected")
resp = await message.reply("Analyzing...")
await asyncio.sleep(2)
await resp.edit_text("NSFW Detected")
await message.delete()
await resp.edit_text("Message Removed")
await asyncio.sleep(2)
await client.delete_messages(message.chat.id,resp.id)
os.remove(file_path)
if message.from_user.is_fake:
await client.ban_chat_member(config.GROUP_ID,message.from_user.id)
if message.from_user.is_scam:
await client.ban_chat_member(config.GROUP_ID,message.from_user.id)
if message.from_user.is_bot:
await client.ban_chat_member(config.GROUP_ID,message.from_user.id)
if config.BAN_ACCOUNT_WITHOUT_PROFILE_PIC:
if not message.from_user.dc_id:
await client.ban_chat_member(config.GROUP_ID,message.from_user.id)
return None
@app.on_message(filters.new_chat_members)
async def new_member(client:Client,message:Message):
logging.info("NEW MEMBER JOINED")
if message.from_user.is_bot:
logging.info("BOT_DETECTED")
await client.ban_chat_member(config.GROUP_ID,message.from_user.id)
app.run()