File size: 5,021 Bytes
ca4eb6d
 
 
af1662b
ca4eb6d
007891e
 
ca4eb6d
af1662b
ca4eb6d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5b0b8d7
 
 
 
ca4eb6d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c3ccb7b
 
ca4eb6d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
147
148
149
from html import escape
from pyrogram import filters
from Powers.bot_class import Gojo
from Powers import LOGGER, HELP_COMMANDS
from Powers.database.disable_db import Disabling
from pyrogram.types import (
    Message, CallbackQuery, InlineKeyboardButton, InlineKeyboardMarkup)
from Powers.utils.custom_filters import (
    command, admin_filter, owner_filter, can_change_filter)


@Gojo.on_message(command("disable") & can_change_filter)
async def disableit(_, m: Message):
    if len(m.text.split()) < 2:
        return await m.reply_text("What to disable?")
    disable_cmd_keys = sorted(
        k
        for j in [HELP_COMMANDS[i]["disablable"] for i in list(HELP_COMMANDS.keys())]
        for k in j
    )

    db = Disabling(m.chat.id)
    disable_list = db.get_disabled()
    LOGGER.info(f"{m.from_user.id} used disabled cmd in {m.chat.id}")

    if str(m.text.split(None, 1)[1]) in disable_list:
        return await m.reply_text("It's already disabled!")

    if str((m.text.split(None, 1)[1]).lower()) in disable_cmd_keys:
        db.add_disable((str(m.text.split(None, 1)[1])).lower())
        await m.reply_text(f"Disabled {m.text.split(None, 1)[1]}!")
        return
    await m.reply_text("Can't do it sorry!")
    return


@Gojo.on_message(command("disabledel") & can_change_filter)
async def set_dsbl_action(_, m: Message):
    db = Disabling(m.chat.id)

    status = db.get_action()
    if status == "none":
        cur = False
    else:
        cur = True
    args = m.text.split(" ", 1)

    LOGGER.info(f"{m.from_user.id} disabledel used in {m.chat.id}")

    if len(args) >= 2:
        if args[1].lower() == "on":
            db.set_action("del")
            await m.reply_text("Oke done!")
        elif args[1].lower() == "off":
            db.set_action("none")
            await m.reply_text("Oke i will not delete!")
        else:
            await m.reply_text("what are you trying to do ??")
    else:
        await m.reply_text(f"Current settings:- {cur}")
    return


@Gojo.on_message(command("enable") & can_change_filter)
async def enableit(_, m: Message):
    if len(m.text.split()) < 2:
        return await m.reply_text("What to enable?")
    db = Disabling(m.chat.id)
    disable_list = db.get_disabled()
    if str(m.text.split(None, 1)[1]) not in disable_list:
        return await m.reply_text("It's not disabled!")
    db.remove_disabled((str(m.text.split(None, 1)[1])).lower())
    LOGGER.info(f"{m.from_user.id} enabled something in {m.chat.id}")
    return await m.reply_text(f"Enabled {m.text.split(None, 1)[1]}!")


@Gojo.on_message(command("disableable") & can_change_filter)
async def disabling(_, m: Message):
    disable_cmd_keys = sorted(
        k
        for j in [HELP_COMMANDS[i]["disablable"] for i in list(HELP_COMMANDS.keys())]
        for k in j
    )
    tes = "List of commnds that can be disabled:\n"
    tes += "\n".join(f" • <code>{escape(i)}</code>" for i in disable_cmd_keys)
    LOGGER.info(f"{m.from_user.id} checked disableable {m.chat.id}")
    return await m.reply_text(tes)


@Gojo.on_message(command("disabled") & admin_filter)
async def disabled(_, m: Message):
    db = Disabling(m.chat.id)
    disable_list = db.get_disabled()
    if not disable_list:
        await m.reply_text("No disabled items!")
        return
    tex = "Disabled commands:\n"
    tex += "\n".join(f" • <code>{escape(i)}</code>" for i in disable_list)
    LOGGER.info(f"{m.from_user.id} checked disabled {m.chat.id}")
    return await m.reply_text(tex)


@Gojo.on_message(command("enableall") & owner_filter)
async def rm_alldisbl(_, m: Message):
    db = Disabling(m.chat.id)
    all_dsbl = db.get_disabled()
    if not all_dsbl:
        await m.reply_text("No disabled commands in this chat")
        return
    await m.reply_text(
        "Are you sure you want to enable all?",
        reply_markup=InlineKeyboardMarkup(
            [
                [
                    InlineKeyboardButton(
                        "Confirm",
                        callback_data="enableallcmds",
                    ),
                    InlineKeyboardButton(
                        "Cancel", callback_data="close_admin"),
                ],
            ],
        ),
    )
    return


@Gojo.on_callback_query(filters.regex("^enableallcmds$"))
async def enablealll(_, q: CallbackQuery):
    user_id = q.from_user.id
    user_status = (await q.message.chat.get_member(user_id)).status
    if user_status not in {"creator", "administrator"}:
        await q.answer(
            "You're not even an admin, don't try this explosive shit!",
            show_alert=True,
        )
        return
    if user_status != "creator":
        await q.answer(
            "You're just an admin, not owner\nStay in your limits!",
            show_alert=True,
        )
        return
    db = Disabling(q.message.chat.id)
    db.rm_all_disabled()
    LOGGER.info(f"{user_id} enabled all in {q.message.chat.id}")
    await q.message.edit_text("Enabled all!", show_alert=True)
    return