Spaces:
Running
Running
Upload autobanch.py
Browse files- chatbot/plugins/autobanch.py +92 -0
chatbot/plugins/autobanch.py
ADDED
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 time
|
21 |
+
import json
|
22 |
+
import asyncio
|
23 |
+
import io
|
24 |
+
import os
|
25 |
+
import re
|
26 |
+
|
27 |
+
from pyrogram import *
|
28 |
+
from pyrogram.enums import ChatMemberStatus
|
29 |
+
from pyrogram import enums
|
30 |
+
from pyrogram import Client, filters
|
31 |
+
from pyrogram.types import *
|
32 |
+
from pyrogram.errors import *
|
33 |
+
from database import db
|
34 |
+
from logger import LOGS
|
35 |
+
|
36 |
+
@Client.on_callback_query(filters.regex("^unbanch_"))
|
37 |
+
async def unbanch_usert(client: Client, cb: CallbackQuery):
|
38 |
+
data = cb.data.split("_")
|
39 |
+
user_id = int(data[1])
|
40 |
+
try:
|
41 |
+
if cb.from_user.id == 1191668125:
|
42 |
+
await client.unban_chat_member(
|
43 |
+
"RendyProjects",
|
44 |
+
user_id,
|
45 |
+
)
|
46 |
+
await cb.edit_message_text(
|
47 |
+
f"you {user_id} have been unbanned from Rendy Projects",
|
48 |
+
disable_web_page_preview=True,
|
49 |
+
)
|
50 |
+
else:
|
51 |
+
await cb.answer("Only Developer", True)
|
52 |
+
except Exception as e:
|
53 |
+
await cb.answer(f"Error: {e}", True)
|
54 |
+
|
55 |
+
@Client.on_chat_member_updated(filters.chat("RendyProjects"))
|
56 |
+
async def auto_banned_ch(client: Client, event: ChatMemberUpdated):
|
57 |
+
if event.old_chat_member and event.old_chat_member.status == ChatMemberStatus.LEFT:
|
58 |
+
try:
|
59 |
+
keyboard_button = InlineKeyboardMarkup(
|
60 |
+
[
|
61 |
+
[
|
62 |
+
InlineKeyboardButton(
|
63 |
+
text="⚠️ Unban",
|
64 |
+
callback_data=f"unbanch_{event.from_user.id}"
|
65 |
+
)
|
66 |
+
]
|
67 |
+
]
|
68 |
+
)
|
69 |
+
text_ban = f"User {event.from_user.first_name} was banned from {event.chat.title}."
|
70 |
+
await client.ban_chat_member(
|
71 |
+
event.chat.id,
|
72 |
+
event.from_user.id,
|
73 |
+
)
|
74 |
+
await client.send_message(
|
75 |
+
1191668125,
|
76 |
+
text_ban,
|
77 |
+
reply_markup=keyboard_button
|
78 |
+
)
|
79 |
+
except Exception as e:
|
80 |
+
await client.send_message(1191668125, str(e))
|
81 |
+
|
82 |
+
elif event.new_chat_member and event.new_chat_member.status == ChatMemberStatus.MEMBER:
|
83 |
+
try:
|
84 |
+
if await db.is_gbanned(event.from_user.id):
|
85 |
+
text_ban = f"User {event.from_user.first_name} was banned from {event.chat.title}."
|
86 |
+
await client.ban_chat_member(
|
87 |
+
event.chat.id,
|
88 |
+
event.from_user.id,
|
89 |
+
)
|
90 |
+
await client.send_message(1191668125, text_ban)
|
91 |
+
except Exception as e:
|
92 |
+
await client.send_message(1191668125, str(e))
|