File size: 8,479 Bytes
c68d102
f0f9ad9
 
2aca525
f0f9ad9
af1662b
f0f9ad9
af1662b
f0f9ad9
cbec4fb
e241f2e
ca4eb6d
af1662b
 
f72d3ee
ca4eb6d
 
 
 
 
af1662b
6087453
 
 
191552d
6087453
11170eb
6087453
191552d
11170eb
191552d
af1662b
ca4eb6d
 
 
 
 
 
 
5bc27d3
ca4eb6d
 
 
 
 
5bc27d3
ca4eb6d
 
 
 
 
 
 
 
 
 
 
 
 
 
c1d601a
 
ca4eb6d
 
 
 
 
 
 
 
 
e241f2e
ca4eb6d
 
 
 
 
 
 
 
191552d
7c42912
a211a48
5ec9c41
ca4eb6d
 
 
 
 
af1662b
6087453
 
 
191552d
6087453
f72d3ee
191552d
7c42912
191552d
ca4eb6d
 
 
 
 
 
af1662b
 
 
 
 
 
 
 
 
 
 
1d0457e
 
e8087b9
1d0457e
ca4eb6d
 
 
 
 
 
 
 
af1662b
6087453
 
 
191552d
6087453
11170eb
2abd373
191552d
ca4eb6d
 
 
 
 
 
 
 
 
 
8780a10
 
 
 
ca4eb6d
af1662b
6087453
 
 
 
 
191552d
2abd373
191552d
af1662b
ca4eb6d
 
 
 
191552d
af1662b
 
 
ca4eb6d
 
 
 
 
 
 
 
 
 
 
e241f2e
ca4eb6d
 
 
 
 
c1d601a
 
096ee5f
66ec5ae
 
 
191552d
7c42912
a211a48
5ec9c41
ca4eb6d
 
 
 
af1662b
191552d
7c42912
1320006
ca4eb6d
 
 
 
 
 
 
 
 
 
 
 
 
c1d601a
 
68742ae
 
 
8780a10
af1662b
6087453
 
 
 
 
ca4eb6d
 
 
 
11170eb
af1662b
191552d
7c42912
a211a48
ca4eb6d
 
 
 
 
 
8780a10
ca4eb6d
 
 
af1662b
ca4eb6d
 
11170eb
ca4eb6d
2abd373
a211a48
5ec9c41
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
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
from random import choice
from Powers.vars import Config
from Powers.bot_class import Gojo
from pyrogram import enums, filters
from Powers.utils.kbhelpers import ikb
from Powers import LOGGER, HELP_COMMANDS
from Powers.utils.extras import StartPic
from Powers.utils.custom_filters import command
from pyrogram.types import Message, CallbackQuery
from pyrogram.enums import ChatType, ChatMemberStatus as CMS
from pyrogram.errors import UserIsBlocked, QueryIdInvalid, MessageNotModified
from Powers.utils.start_utils import (
    gen_cmds_kb, gen_start_kb, get_help_msg, get_private_note,
    get_private_rules)


@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 Ezio](http://t.me/iamgojoof6eyes)
     """

    LOGGER.info(f"{m.from_user.id} fetched donation text in {m.chat.id}")
    await m.reply_photo(photo=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.split()) > 1:
            help_option = (m.text.split(None, 1)[1]).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"):
                LOGGER.info(f"{m.from_user.id} fetched privaterules in {m.chat.id}")
                await get_private_rules(c, m, help_option)
                return

            help_msg, help_kb = await get_help_msg(m, help_option)

            if not help_msg:
                return

            await m.reply_photo(
                photo=choice(StartPic),
                caption=help_msg,
                parse_mode=enums.ParseMode.MARKDOWN,
                reply_markup=ikb(help_kb),
                quote=True,
            )
            return
        try:
            cpt = f"""
Hey [{m.from_user.first_name}](http://t.me/{m.from_user.username})! My self Gojo ✨.
I'm here to help you manage your groups!
Hit /help to find out more about how to use me in my full potential!

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

            await m.reply_photo(
                photo=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 = ikb(
            [
                [
                    (
                        "Connect me to pm",
                        f"https://t.me/{Config.BOT_USERNAME}?start=start",
                        "url",
                    )
                ]
            ]
        )
        await m.reply_photo(
            photo=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(_, q: CallbackQuery):
    try:
        cpt = f"""
Hey [{q.from_user.first_name}](http://t.me/{q.from_user.username})! My name is Gojo ✨.
I'm here to help you manage your groups!
Hit /help to find out more about how to use me in my full potential!

Join my [News Channel](http://t.me/gojo_updates) 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(_, q: CallbackQuery):
    cmds = sorted(list(HELP_COMMANDS.keys()))
    kb = [cmd.lower() for cmd in cmds]
    ou = [kb[i : i + 3] for i in range(0, len(kb), 3)]
    keyboard = ikb(ou, True)
    try:
        cpt = f"""
Hey **[{q.from_user.first_name}](http://t.me/{q.from_user.username})**! My name is Gojo✨.
I'm here to help you manage your groups!
Commands available:
* /start: Start the bot
* /help: Give's you this message."""

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

    await q.answer()
    return


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

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

        LOGGER.info(
            f"{m.from_user.id} fetched help for '{help_option}' text in {m.chat.id}",
        )

        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=choice(StartPic),
                caption=help_msg,
                parse_mode=enums.ParseMode.MARKDOWN,
                reply_markup=ikb(help_kb),
                quote=True,
            )
        else:

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

        if m.chat.type == ChatType.PRIVATE:
            cmds = sorted(list(HELP_COMMANDS.keys()))
            kb = [cmd.lower() for cmd in cmds]
            ou = [kb[i : i + 3] for i in range(0, len(kb), 3)]
            keyboard = ikb(ou, True)
            msg = f"""
Hey **[{m.from_user.first_name}](http://t.me/{m.from_user.username})**!My name is Gojo✨.
I'm here to help you manage your groups!
Commands available:
* /start: Start the bot
* /help: Give's you this message."""
        else:
            keyboard = ikb(
                [[("Help", f"t.me/{Config.BOT_USERNAME}?start=help", "url")]],
            )
            msg = "Contact me in PM to get the list of possible commands."

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

    return


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

    help_msg = (f"**{str(module)}:**\n\n" + HELP_COMMANDS[module]["help_msg"],)

    help_kb = HELP_COMMANDS[module]["buttons"] + [
        [("« " + "Back", "commands")],
    ]
    await q.edit_message_caption(
        caption=help_msg,
        parse_mode=enums.ParseMode.MARKDOWN,
        reply_markup=ikb(help_kb),
    )
    await q.answer()
    return