File size: 5,688 Bytes
b6dee3b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bafc641
b6dee3b
 
f63fe40
b6dee3b
 
 
 
 
 
 
bafc641
 
 
b6dee3b
 
 
bafc641
 
 
 
 
 
 
 
b6dee3b
 
 
04c7715
b6dee3b
 
 
bafc641
b6dee3b
 
bafc641
b6dee3b
bafc641
 
b6dee3b
 
bafc641
 
04c7715
517fe3a
 
 
 
 
 
ea68132
517fe3a
 
 
 
 
7fdc3f5
 
493eea3
7fdc3f5
04c7715
7fdc3f5
 
 
04c7715
7fdc3f5
 
 
517fe3a
04c7715
7fdc3f5
517fe3a
 
04c7715
517fe3a
b6dee3b
bafc641
 
 
 
 
 
b6dee3b
 
 
 
 
 
bafc641
b6dee3b
 
 
 
bafc641
b6dee3b
 
bafc641
b6dee3b
 
04c7715
b6dee3b
 
 
bafc641
b6dee3b
04c7715
bafc641
b6dee3b
bafc641
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/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}")

@Client.on_message(filters.left_chat_member & filters.channel)
async def left_ch(client: Client, message: Message):
    keyboard_button = InlineKeyboardMarkup(
        [
            [
                InlineKeyboardButton(
                    text="⚠️ Unban",
                    callback_data=f"unbanch_{message.from_user.id}"
                )
            ]
        ]
    )
    try:
        if message.chat.type == ChatType.CHANNEL:
            if message.chat.id == -1001558215042:
                text_ban = f"User {message.from_user.first_name} (ID: {message.from_user.id}) was banned from {message.chat.title}."
                await client.ban_chat_member(
                    "RendyProjects",
                    message.from_user.id,
                )
                await client.send_message(
                    "KillerXSupport",
                    text_ban,
                    reply_markup=keyboard_button
                )
    except Exception as e:
        await client.send_message("KillerXSupport", f"Error {e}")
        logger.error(f"Error {e}")

@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
    user_id = event.from_user.id
    user_first_name = event.from_user.first_name
    if old_status == ChatMemberStatus.LEFT and new_status != ChatMemberStatus.MEMBER:
        try:
            keyboard_button = InlineKeyboardMarkup(
                [
                    [
                        InlineKeyboardButton(
                            text="⚠️ Unban",
                            callback_data=f"unbanch_{user_id}"
                        )
                    ]
                ]
            )
            text_ban = f"User {user_first_name} (ID: {user_id}) was banned from {event.chat.title}."
            await client.ban_chat_member(
                event.chat.id,
                user_id,
            )
            await client.send_message(
                "KillerXSupport",
                text_ban,
                reply_markup=keyboard_button
            )
            logger.info(f"User {user_id} has been banned for leaving 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}")

    elif 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}")