Upload antinsfw.py
Browse files- Akeno/plugins/antinsfw.py +95 -0
Akeno/plugins/antinsfw.py
ADDED
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
# -*- coding: utf-8 -*-
|
3 |
+
# Copyright 2020-2024 (c) Randy W @xtdevs, @xtsea
|
4 |
+
#
|
5 |
+
# from : https://github.com/TeamKillerX
|
6 |
+
# Channel : @RendyProjects
|
7 |
+
# This program is free software: you can redistribute it and/or modify
|
8 |
+
# it under the terms of the GNU Affero General Public License as published by
|
9 |
+
# the Free Software Foundation, either version 3 of the License, or
|
10 |
+
# (at your option) any later version.
|
11 |
+
#
|
12 |
+
# This program is distributed in the hope that it will be useful,
|
13 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
+
# GNU Affero General Public License for more details.
|
16 |
+
#
|
17 |
+
# You should have received a copy of the GNU Affero General Public License
|
18 |
+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
19 |
+
|
20 |
+
import logging
|
21 |
+
import os
|
22 |
+
|
23 |
+
from pyrogram import Client, enums, filters, idle
|
24 |
+
from pyrogram.enums.parse_mode import ParseMode
|
25 |
+
from pyrogram.types import Chat, ChatMember, ChatPrivileges, Message
|
26 |
+
|
27 |
+
from Akeno.utils.database import db
|
28 |
+
from Akeno.utils.handler import *
|
29 |
+
from config import CMD_HANDLER
|
30 |
+
|
31 |
+
ANTINSFW_GROUPS = 12
|
32 |
+
|
33 |
+
async def can_delete(client: Client, bot_id: int) -> bool:
|
34 |
+
member = await client.get_member(bot_id)
|
35 |
+
if member.status in [enums.ChatMemberStatus.ADMINISTRATOR, enums.ChatMemberStatus.OWNER]:
|
36 |
+
return True
|
37 |
+
else:
|
38 |
+
return False
|
39 |
+
|
40 |
+
def check_anti_nsfw(media) -> bool:
|
41 |
+
url = "https://akeno.randydev.my.id/akeno/anti-nsfw"
|
42 |
+
with open(media, "rb") as file:
|
43 |
+
files = {"file": file}
|
44 |
+
response = requests.post(url, files=files)
|
45 |
+
if response.status_code == 200:
|
46 |
+
results = response.json()
|
47 |
+
return results["randydev"]["results"]["result"]["content"].get("isNsfw", False)
|
48 |
+
return False
|
49 |
+
|
50 |
+
@Akeno(
|
51 |
+
~filters.scheduled & filters.command(["antinsfw"], CMD_HANDLER) & filters.me & ~filters.forwarded
|
52 |
+
)
|
53 |
+
async def antinsfw_setting(client: Client, message: Message):
|
54 |
+
args = message.text.lower().split()[1:]
|
55 |
+
chat = message.chat
|
56 |
+
if chat.type != "private":
|
57 |
+
if args:
|
58 |
+
if args[0] in ("yes", "on", "true"):
|
59 |
+
await db.set_chat_setting_antinsfw(chat.id, True)
|
60 |
+
await message.reply_text("Turned on AntiNFSW! Messages sent by any non-admin that contain anti nsfw media will be deleted.")
|
61 |
+
|
62 |
+
elif args[0] in ("no", "off", "false"):
|
63 |
+
await db.set_chat_setting_antinsfw(chat.id, False)
|
64 |
+
await message.reply_text("Turned off AntiNFSW! Messages containing anti nsfw media won't be deleted.")
|
65 |
+
else:
|
66 |
+
reply_text = f"AntiNsfw Mode: {'On' if await db.chat_antinsfw(chat.id) else 'Off'}"
|
67 |
+
await message.reply_text(reply_text, parse_mode=ParseMode.MARKDOWN)
|
68 |
+
|
69 |
+
@Akeno(
|
70 |
+
filters.group
|
71 |
+
& ~filters.private
|
72 |
+
& ~filters.bot
|
73 |
+
& ~filters.service,
|
74 |
+
group=ANTINSFW_GROUPS
|
75 |
+
)
|
76 |
+
async def antinsfw_filter(client: Client, message: Message):
|
77 |
+
chat = message.chat
|
78 |
+
user = message.from_user
|
79 |
+
if not await db.chat_antinsfw(chat.id):
|
80 |
+
return
|
81 |
+
if not user or user.id == 777000:
|
82 |
+
return
|
83 |
+
if not message.photo:
|
84 |
+
return
|
85 |
+
me = await client.get_me()
|
86 |
+
if message.photo:
|
87 |
+
file_id = message.photo.file_id
|
88 |
+
media = await client.download_media(file_id)
|
89 |
+
if check_anti_nsfw(media):
|
90 |
+
if await can_delete(chat, me.id):
|
91 |
+
return await message.delete()
|
92 |
+
os.remove(media)
|
93 |
+
|
94 |
+
module = modules_help.add_module("antinsfw", __file__)
|
95 |
+
module.add_command("antinsfw", "to anti nsfw auto delete messages")
|