File size: 15,727 Bytes
768892d
d7e1221
1b5719b
5a78342
1b5719b
 
aa9c445
9ab31c1
4fbd28b
 
1b5719b
b978403
3580517
 
1b5719b
a3f3b83
98ab4e9
1b5719b
 
9ab31c1
d808ebe
 
058dd88
328dfd9
7956eb0
 
 
 
 
b002286
417cfd4
 
 
0d65a40
417cfd4
89c3556
058dd88
0d65a40
89c3556
2097a34
7956eb0
 
 
 
 
 
 
f574c0a
7956eb0
 
 
 
 
f574c0a
7956eb0
 
 
 
 
 
 
 
 
 
 
 
 
 
711b749
ef853d9
a3f3b83
 
7956eb0
 
4056428
7956eb0
 
 
058dd88
7956eb0
 
 
 
d808ebe
7956eb0
a3f3b83
ef853d9
 
 
 
 
 
 
 
a3f3b83
 
d720c41
 
 
 
 
 
 
 
a3f3b83
058dd88
a3f3b83
058dd88
 
 
 
 
 
 
 
a3f3b83
 
 
 
 
 
 
 
 
 
 
 
3c9449b
a3f3b83
 
 
058dd88
a3f3b83
3c9449b
058dd88
 
 
 
 
7956eb0
b002286
058dd88
3c05ff4
417cfd4
0d65a40
5a78342
328dfd9
0d65a40
2097a34
0d65a40
7956eb0
 
 
 
 
 
058dd88
 
 
 
 
8ee0322
058dd88
 
 
 
 
 
 
 
 
 
 
7956eb0
 
 
 
058dd88
7956eb0
b002286
058dd88
3c05ff4
417cfd4
0d65a40
5a78342
89c3556
a69162f
0d65a40
7956eb0
 
 
 
 
 
 
 
 
058dd88
1b5719b
b2e9960
7956eb0
b002286
058dd88
3c05ff4
417cfd4
321432c
af89290
 
b978403
af89290
0d65a40
a69162f
0d65a40
b002286
7956eb0
 
 
 
0d65a40
2097a34
b002286
 
7956eb0
 
 
 
 
058dd88
7956eb0
4056428
ef853d9
d808ebe
7956eb0
 
058dd88
 
7956eb0
 
711b749
809532c
f0a2848
 
 
0d65a40
2097a34
4996434
0206afd
2374ea1
7956eb0
 
 
b002286
0d65a40
2097a34
5a76014
ee9f38a
7956eb0
058dd88
 
 
8ee0322
058dd88
 
7956eb0
 
f147cb7
7956eb0
711b749
 
1b5719b
b2e9960
b002286
058dd88
3c05ff4
417cfd4
321432c
 
7956eb0
f147cb7
 
058dd88
 
 
8ee0322
058dd88
 
f147cb7
7956eb0
89c3556
b002286
0d65a40
2097a34
4996434
7956eb0
 
 
 
 
058dd88
4056428
2e265b6
 
 
 
 
 
 
 
 
 
 
 
 
3c9449b
 
 
 
2e265b6
 
 
 
 
 
 
 
 
3c9449b
 
 
 
2e265b6
 
 
 
 
 
3c9449b
 
 
 
 
 
 
 
 
2e265b6
3c9449b
 
2e265b6
4056428
 
2e265b6
 
 
 
 
 
3c9449b
2e265b6
 
 
 
 
 
 
 
d7e1221
 
 
 
 
 
090f162
d7e1221
090f162
 
 
 
d7e1221
 
 
 
7956eb0
058dd88
b2e9960
f865f48
7956eb0
 
7d0866c
7956eb0
1b5719b
f865f48
058dd88
 
 
 
 
f865f48
2e265b6
 
 
3588d38
 
2e265b6
7956eb0
 
9ab31c1
058dd88
9ab31c1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3c9449b
9ab31c1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4056428
 
9ab31c1
 
058dd88
 
 
 
 
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
from random import choice
from time import gmtime, strftime, time

from pyrogram import enums, filters
from pyrogram.enums import ChatMemberStatus as CMS
from pyrogram.enums import ChatType
from pyrogram.errors import (MediaCaptionTooLong, MessageNotModified,
                             QueryIdInvalid, RPCError, UserIsBlocked)
from pyrogram.types import (CallbackQuery, InlineKeyboardButton,
                            InlineKeyboardMarkup, Message)

from Powers import (DEV_USERS, HELP_COMMANDS, LOGGER, OWNER_ID, PREFIX_HANDLER,
                    PYROGRAM_VERSION, PYTHON_VERSION, SUDO_USERS, UPTIME,
                    VERSION, WHITELIST_USERS)
from Powers.bot_class import Gojo
from Powers.database.captcha_db import CAPTCHA_DATA
from Powers.utils.custom_filters import command
from Powers.utils.extras import StartPic
from Powers.utils.kbhelpers import ikb
from Powers.utils.parser import mention_html
from Powers.utils.start_utils import (gen_cmds_kb, gen_start_kb, get_help_msg,
                                      get_private_note, get_private_rules)
from Powers.utils.string import encode_decode


@Gojo.on_message(
    command("donate") & (filters.group | filters.private),
)
async def donate(_, m: Message):
    cpt = """
Hey Thanks for your thought of donating me!
When you donate, all the fund goes towards my development which makes on fast and responsive.
Your donation might also me get me a new feature or two, which I wasn't able to get due to server limitations.

All the fund would be put into my services such as database, storage and hosting!

You can donate by contacting my owner: [Captain D. Ezio](http://t.me/iamgojoof6eyes)
     """

    await m.reply_photo(photo=str(choice(StartPic)), caption=cpt)
    return


@Gojo.on_callback_query(filters.regex("^close_admin$"))
async def close_admin_callback(_, q: CallbackQuery):
    user_id = q.from_user.id
    user_status = (await q.message.chat.get_member(user_id)).status
    if user_status not in {CMS.OWNER, CMS.ADMINISTRATOR}:
        await q.answer(
            "You're not even an admin, don't try this explosive shit!",
            show_alert=True,
        )
        return
    if user_status != CMS.OWNER:
        await q.answer(
            "You're just an admin, not owner\nStay in your limits!",
            show_alert=True,
        )
        return
    await q.message.edit_text("Closed!")
    await q.answer("Closed menu!", show_alert=True)
    return


@Gojo.on_message(
    command("start") & (filters.group | filters.private),
)
async def start(c: Gojo, m: Message):
    if m.chat.type == ChatType.PRIVATE:
        if len(m.text.strip().split()) > 1:
            arg = m.text.split(None, 1)[1]
            help_option = arg.lower()

            if help_option.startswith("note") and (
                    help_option not in ("note", "notes")
            ):
                await get_private_note(c, m, help_option)
                return

            if help_option.startswith("rules"):
                await get_private_rules(c, m, help_option)
                return

            help_msg, help_kb = await get_help_msg(c, m, help_option)

            if help_msg:
                await m.reply_photo(
                    photo=str(choice(StartPic)),
                    caption=help_msg,
                    parse_mode=enums.ParseMode.MARKDOWN,
                    reply_markup=help_kb,
                    quote=True,
                )
                return
            if len(arg.split("_", 1)) >= 2:
                if arg.split("_")[1] == "help":
                    await m.reply_photo(
                        photo=str(choice(StartPic)),
                        caption=help_msg,
                        parse_mode=enums.ParseMode.MARKDOWN,
                        reply_markup=help_kb,
                        quote=True,
                    )
                    return
                elif arg.split("_", 1)[0] == "qr":
                    decoded = encode_decode(
                        arg.split("_", 1)[1], "decode")
                    decode = decoded.split(":")
                    chat = decode[0]
                    user = decode[1]
                    if m.from_user.id != int(user):
                        await m.reply_text("Not for you Baka")
                        return
                    try:
                        await c.unban_chat_member(int(chat), int(user))
                        msg = CAPTCHA_DATA().del_message_id(chat, user)
                        try:
                            chat_ = await c.get_chat(chat)
                            kb = ikb(
                                [
                                    [
                                        "Link to chat",
                                        f"{chat_.invite_link}",
                                        "url"
                                    ]
                                ]
                            )
                        except Exception:
                            chat_ = False
                            kb = None
                        await m.reply_text("You can now talk in the chat", reply_markup=kb)
                        try:
                            await c.delete_messages(chat, msg)
                        except Exception:
                            pass
                        return
                    except Exception:
                        return

        try:
            cpt = f"""
Hey [{m.from_user.first_name}](http://t.me/{m.from_user.username})! I am {c.me.first_name} ✨.
I'm here to help you manage your group(s)!
Hit /help to find out more about how to use me in my full potential!

Join my [News Channel](https://t.me/gojo_bots_network) to get information on all the latest updates."""

            await m.reply_photo(
                photo=str(choice(StartPic)),
                caption=cpt,
                reply_markup=(await gen_start_kb(m)),
                quote=True,
            )
        except UserIsBlocked:
            LOGGER.warning(f"Bot blocked by {m.from_user.id}")
    else:
        kb = InlineKeyboardMarkup(
            [
                [
                    InlineKeyboardButton(
                        "Connect me to pm",
                        url=f"https://{c.me.username}.t.me/",
                    ),
                ],
            ],
        )

        await m.reply_photo(
            photo=str(choice(StartPic)),
            caption="I'm alive :3",
            reply_markup=kb,
            quote=True,
        )
    return


@Gojo.on_callback_query(filters.regex("^start_back$"))
async def start_back(c: Gojo, q: CallbackQuery):
    try:
        cpt = f"""
Hey [{q.from_user.first_name}](http://t.me/{q.from_user.username})! I am {c.me.first_name} ✨.
I'm here to help you manage your group(s)!
Hit /help to find out more about how to use me in my full potential!

Join my [News Channel](http://t.me/gojo_bots_network) to get information on all the latest updates."""

        await q.edit_message_caption(
            caption=cpt,
            reply_markup=(await gen_start_kb(q.message)),
        )
    except MessageNotModified:
        pass
    await q.answer()
    return


@Gojo.on_callback_query(filters.regex("^commands$"))
async def commands_menu(c: Gojo, q: CallbackQuery):
    ou = await gen_cmds_kb(q.message)
    keyboard = ikb(ou, True)
    try:
        cpt = f"""
Hey **[{q.from_user.first_name}](http://t.me/{q.from_user.username})**! I am {c.me.first_name}✨.
I'm here to help you manage your group(s)!
Commands available:
Γ— /start: Start the bot
Γ— /help: Give's you this message.

You can use {", ".join(PREFIX_HANDLER)} as your prefix handler
"""

        await q.edit_message_caption(
            caption=cpt,
            reply_markup=keyboard,
        )
    except MessageNotModified:
        pass
    except QueryIdInvalid:
        await q.message.reply_photo(
            photo=str(choice(StartPic)), caption=cpt, reply_markup=keyboard
        )

    await q.answer()
    return


@Gojo.on_message(command("help"))
async def help_menu(c: Gojo, m: Message):
    if len(m.text.split()) >= 2:
        textt = m.text.replace(" ", "_", ).replace("_", " ", 1)
        help_option = (textt.split(None)[1]).lower()
        help_msg, help_kb = await get_help_msg(c, m, help_option)

        if not help_msg:
            LOGGER.error(
                f"No help_msg found for help_option - {help_option}!!")
            return

        if m.chat.type == ChatType.PRIVATE:
            if len(help_msg) >= 1026:
                await m.reply_text(
                    help_msg, parse_mode=enums.ParseMode.MARKDOWN, quote=True
                )
            await m.reply_photo(
                photo=str(choice(StartPic)),
                caption=help_msg,
                parse_mode=enums.ParseMode.MARKDOWN,
                reply_markup=help_kb,
                quote=True,
            )
        else:

            await m.reply_photo(
                photo=str(choice(StartPic)),
                caption=f"Press the button below to get help for <i>{help_option}</i>",
                reply_markup=InlineKeyboardMarkup(
                    [
                        [
                            InlineKeyboardButton(
                                "Help",
                                url=f"t.me/{c.me.username}?start={help_option}",
                            ),
                        ],
                    ],
                ),
            )
    else:

        if m.chat.type == ChatType.PRIVATE:
            ou = await gen_cmds_kb(m)
            keyboard = ikb(ou, True)
            msg = f"""
Hey **[{m.from_user.first_name}](http://t.me/{m.from_user.username})**!I am {c.me.first_name}✨.
I'm here to help you manage your group(s)!
Commands available:
Γ— /start: Start the bot
Γ— /help: Give's you this message."""
        else:
            keyboard = InlineKeyboardMarkup(
                [
                    [
                        InlineKeyboardButton(
                            "Help",
                            url=f"t.me/{c.me.username}?start=start_help",
                        ),
                    ],
                ],
            )
            msg = "Contact me in PM to get the list of possible commands."

        await m.reply_photo(
            photo=str(choice(StartPic)),
            caption=msg,
            reply_markup=keyboard,
        )

    return


async def get_divided_msg(plugin_name: str, page: int = 1, back_to_do=None):
    msg = HELP_COMMANDS[plugin_name]["help_msg"]
    msg = msg.split("\n")
    l = len(msg)
    new_msg = ""
    total = l // 10
    first = 10 * (page - 1)
    last = 10 * page

    if not first:
        for i in msg[first:last]:
            new_msg += f"{i}\n"
        kb = [
            [
                (
                    "Next page ▢️",
                    f"iter_page_{plugin_name}_{f'{back_to_do}_' if back_to_do else ''}{page + 1}",
                )
            ]
        ]
    else:
        first += 1
        if page == total:
            for i in msg[first:]:
                new_msg += f"{i}\n"
            kb = [
                [
                    (
                        "◀️ Previous page",
                        f"iter_page_{plugin_name}_{f'{back_to_do}_' if back_to_do else ''}{page - 1}",
                    )
                ]
            ]
        else:
            for i in msg[first:last]:
                new_msg += f"{i}\n"
            kb = [
                [
                    (
                        "◀️ Previous page",
                        f"iter_page_{plugin_name}_{f'{back_to_do}_' if back_to_do else ''}{page - 1}",
                    ),
                    (
                        "Next page ▢️",
                        f"iter_page_{plugin_name}_{f'{back_to_do}_' if back_to_do else ''}{page + 1}",
                    ),
                ]
            ]
    kb = ikb(kb, True, back_to_do) if back_to_do else ikb(kb)
    return new_msg, kb


@Gojo.on_callback_query(filters.regex(r"^iter_page_.*[0-9]$"))
async def helppp_page_iter(c: Gojo, q: CallbackQuery):
    data = q.data.split("_")
    plugin_ = data[2]
    try:
        back_to = data[-2]
    except Exception:
        back_to = None
    curr_page = int(data[-1])
    msg, kb = await get_divided_msg(plugin_, curr_page, back_to_do=back_to)

    await q.edit_message_caption(msg, reply_markup=kb)
    return


@Gojo.on_callback_query(filters.regex("^bot_curr_info$"))
async def give_curr_info(c: Gojo, q: CallbackQuery):
    start = time()
    up = strftime("%Hh %Mm %Ss", gmtime(time() - UPTIME))
    x = await c.send_message(q.message.chat.id, "Pinging..")
    delta_ping = time() - start
    await x.delete()
    txt = f"""
πŸ“ Ping : {delta_ping * 1000:.3f} ms
πŸ“ˆ Uptime : {up}
πŸ€– Bot's version: {VERSION}
🐍 Python's version: {PYTHON_VERSION}
πŸ”₯ Pyrogram's version : {PYROGRAM_VERSION}
    """
    await q.answer(txt, show_alert=True)
    return


@Gojo.on_callback_query(filters.regex("^plugins."))
async def get_module_info(c: Gojo, q: CallbackQuery):
    module = q.data.split(".", 1)[1]

    help_msg = HELP_COMMANDS[f"plugins.{module}"]["help_msg"]

    help_kb = HELP_COMMANDS[f"plugins.{module}"]["buttons"]
    try:
        await q.edit_message_caption(
            caption=help_msg,
            parse_mode=enums.ParseMode.MARKDOWN,
            reply_markup=ikb(help_kb, True, todo="commands"),
        )
    except MediaCaptionTooLong:
        caption, kb = await get_divided_msg(f"plugins.{module}", back_to_do="commands")
        await q.edit_message_caption(
            caption,
            enums.ParseMode.MARKDOWN,
            kb
        )
    await q.answer()
    return


@Gojo.on_callback_query(filters.regex("^give_bot_staffs$"))
async def give_bot_staffs(c: Gojo, q: CallbackQuery):
    try:
        owner = await c.get_users(OWNER_ID)
        reply = f"<b>🌟 Owner:</b> {(await mention_html(owner.first_name, OWNER_ID))} (<code>{OWNER_ID}</code>)\n"
    except RPCError:
        pass
    true_dev = list(set(DEV_USERS) - {OWNER_ID})
    reply += "\n<b>Developers ⚑️:</b>\n"
    if not true_dev:
        reply += "No Dev Users\n"
    else:
        for each_user in true_dev:
            user_id = int(each_user)
            try:
                user = await c.get_users(user_id)
                reply += f"β€’ {(await mention_html(user.first_name, user_id))} (<code>{user_id}</code>)\n"
            except RPCError:
                pass
    true_sudo = list(set(SUDO_USERS) - set(DEV_USERS))
    reply += "\n<b>Sudo Users πŸ‰:</b>\n"
    if not true_sudo:
        reply += "No Sudo Users\n"
    else:
        for each_user in true_sudo:
            user_id = int(each_user)
            try:
                user = await c.get_users(user_id)
                reply += f"β€’ {(await mention_html(user.first_name, user_id))} (<code>{user_id}</code>)\n"
            except RPCError:
                pass
    reply += "\n<b>Whitelisted Users 🐺:</b>\n"
    if WHITELIST_USERS == []:
        reply += "No additional whitelisted users\n"
    else:
        for each_user in WHITELIST_USERS:
            user_id = int(each_user)
            try:
                user = await c.get_users(user_id)
                reply += f"β€’ {(await mention_html(user.first_name, user_id))} (<code>{user_id}</code>)\n"
            except RPCError:
                pass

    await q.edit_message_caption(reply,
                                 reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("Β« Back", "start_back")]]))
    return


@Gojo.on_callback_query(filters.regex("^DELETEEEE$"))
async def delete_back(_, q: CallbackQuery):
    await q.message.delete()
    return