File size: 4,538 Bytes
b6dee3b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bafc641
b6dee3b
 
f63fe40
b6dee3b
 
 
 
 
 
 
bafc641
 
 
b6dee3b
 
 
bafc641
 
 
 
 
 
 
 
b6dee3b
 
 
04c7715
b6dee3b
 
 
bafc641
b6dee3b
 
bafc641
b6dee3b
bafc641
 
b6dee3b
 
bafc641
 
7bb8ae4
 
 
 
517fe3a
 
 
04c7715
517fe3a
b6dee3b
bafc641
 
 
97e8b15
 
7bb8ae4
 
 
 
 
 
 
 
 
f4d0d61
7bb8ae4
f4d0d61
7bb8ae4
f4d0d61
 
b6dee3b
7bb8ae4
b6dee3b
bafc641
 
b6dee3b
 
bafc641
b6dee3b
04c7715
bafc641
b6dee3b
04c7715
bafc641
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 2020-2024 (c) Randy W @xtdevs, @xtsea
#
# from : https://github.com/TeamKillerX
# Channel : @RendyProjects
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

import time
import json
import asyncio
import io
import os
import re
import logging

from pyrogram import *
from pyrogram.enums import ChatMemberStatus, ChatType
from pyrogram import enums
from pyrogram import Client, filters
from pyrogram.types import *
from pyrogram.errors import *
from database import db
from logger import LOGS

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

@Client.on_callback_query(filters.regex("^unbanch_"))
async def unbanch_usert(client: Client, cb: CallbackQuery):
    data = cb.data.split("_")
    if len(data) != 2:
        await cb.answer("Invalid data format.", True)
        return
    try:
        user_id = int(data[1])
    except ValueError:
        await cb.answer("Invalid user ID.", True)
        return
    try:
        if cb.from_user.id == 1191668125:
            await client.unban_chat_member(
                "RendyProjects",
                user_id,
            )
            await cb.edit_message_text(
                f"User {user_id} has been unbanned from Rendy Projects.",
                disable_web_page_preview=True,
            )
            logger.info(f"User {user_id} has been unbanned by admin {cb.from_user.id}.")
        else:
            await cb.answer("Only the Developer can perform this action.", True)
            logger.warning(f"Unauthorized unban attempt by user {cb.from_user.id}.")
    except Exception as e:
        await cb.answer(f"Error: {e}", True)
        logger.error(f"Error unbanning user {user_id}: {e}")

def create_button_unban(user_id):
    return InlineKeyboardMarkup(
        [[InlineKeyboardButton(
            text="⚠️ Unban", callback_data=f"unbanch_{user_id}")]]
    )

@Client.on_chat_member_updated(
    filters.chat("RendyProjects")
)
async def auto_banned_ch(client: Client, event: ChatMemberUpdated):
    logger.info(f"Chat member update: {event}")
    old_status = event.old_chat_member.status if event.old_chat_member else None
    new_status = event.new_chat_member.status if event.new_chat_member else None
    if old_status == ChatMemberStatus.MEMBER:
        if event.chat.type == ChatType.CHANNEL:
            try:
                text_ban = f"User {event.from_user.first_name} (ID: {event.from_user.id}) was banned from {event.chat.title}."
                await client.ban_chat_member(
                    event.chat.id,
                    event.from_user.id,
                )
                await client.send_message(
                    "KillerXSupport",
                    text_ban,
                    reply_markup=create_button_unban(event.from_user.id)
                )
                logger.info(f"User {event.from_user.id} has been banned for leaving the chat.")
            except Exception as e:
                await client.send_message("KillerXSupport", f"Error banning user {event.from_user.id}: {e}")
                logger.error(f"Error banning user {event.from_user.id}: {e}")

    if new_status == ChatMemberStatus.MEMBER and event.new_chat_member.status == ChatMemberStatus.MEMBER:
        try:
            if await db.is_gbanned(user_id):
                text_ban = f"User {user_first_name} (ID: {user_id}) was banned from {event.chat.title} due to global ban."
                await client.ban_chat_member(
                    event.chat.id,
                    user_id,
                )
                await client.send_message("KillerXSupport", text_ban)
                logger.info(f"User {user_id} was globally banned and has been banned from the chat.")
        except Exception as e:
            await client.send_message("KillerXSupport", f"Error banning user {user_id}: {e}")
            logger.error(f"Error banning user {user_id}: {e}")