File size: 3,763 Bytes
21bc372
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import asyncio
from pyrogram import *
from pyrogram.types import *
from prettytable import PrettyTable
from pyrogram import Client, enums, filters
from pyrogram.types import Message
from pyrogram.errors import *
from config import *
from akn import CMD_HELP, app, log_detailed_error
from akn.utils.handler import *
from akn.utils.helps import *
from akn.utils.prefixprem import command
from akn.Akeno.helper.PyroHelpers import ReplyCheck
from akn.Akeno.helper.utility import split_list

@Akeno(
    ~filters.scheduled
    & command(["help"])
    & filters.me
    & ~filters.forwarded
)
async def help_cmd(_, message: Message):
    args, _ = get_args(message)
    try:
        if not args:
            msg_edited = False

            for text in modules_help.help():
                if msg_edited:
                    await message.reply(text, disable_web_page_preview=True)
                else:
                    await message.edit(text, disable_web_page_preview=True)
                    msg_edited = True
        elif args[0] in modules_help.modules:
            await message.edit(modules_help.module_help(args[0]), disable_web_page_preview=True)
        else:
            await message.edit(modules_help.command_help(args[0]), disable_web_page_preview=True)
    except ValueError as e:
        await message.edit(e)

async def edit_or_reply(message: Message, *args, **kwargs) -> Message:
    xyz = (
        message.edit_text
        if bool(message.from_user and message.from_user.is_self or message.outgoing)
        else (message.reply_to_message or message).reply_text
    )
    return await xyz(*args, **kwargs)

@Akeno(
    ~filters.scheduled
    & command(["menu"])
    & filters.me
    & ~filters.forwarded
)
async def module_help(client: Client, message: Message):
    cmd = message.command
    user_id = message.from_user.id
    help_arg = ""
    bot_username = (await app.get_me()).username
    if len(cmd) > 1:
        help_arg = " ".join(cmd[1:])
    elif not message.reply_to_message and len(cmd) == 1:
        await message.edit_text("⚑️")
        try:
            nice = await client.get_inline_bot_results(bot=bot_username, query="helper")
            await asyncio.gather(
                message.delete(),
                client.send_inline_bot_result(
                    message.chat.id, nice.query_id, nice.results[0].id
                ),
            )
        except BotResponseTimeout:
            await message.edit_text("Error BotResponseTimeout")
        except BaseException as e:
            await log_detailed_error(e, where=client.me.id, who=message.chat.title)
            return
    if help_arg:
        if help_arg in CMD_HELP:
            username = "©️ Copyright 2020-2023"
            commands: dict = CMD_HELP[help_arg]
            this_command = f"β”€β”€γ€Œ **Help For {str(help_arg).upper()}** 」──\n\n"
            for x in commands:
                this_command += f"  β€’  **Command:** `.{str(x)}`\n  β€’  **Function:** `{str(commands[x])}`\n\n"
            this_command += "{}".format(username)
            await edit_or_reply(
                message, this_command, parse_mode=enums.ParseMode.MARKDOWN
            )
        else:
            await edit_or_reply(
                message,
                f"`{help_arg}` **Not a Valid Module Name.**",
            )

def add_command_help(module_name, commands):
    if module_name in CMD_HELP.keys():
        command_dict = CMD_HELP[module_name]
    else:
        command_dict = {}
    for x in commands:
        for y in x:
            if y is not x:
                command_dict[x[0]] = x[1]

    CMD_HELP[module_name] = command_dict

module = modules_help.add_module("help", __file__)
module.add_command("help", "Get common/module/command help.")