Ejemplo n.º 1
0
def gen_cmds_kb():
    plugins = sorted(list(HELP_COMMANDS.keys()))
    cmds = [cmd for cmd in plugins]
    kb = []

    while cmds:
        if cmds:
            cmd = cmds[0]
            a = [
                InlineKeyboardButton(f"{cmd.capitalize()}",
                                     callback_data=f"get_mod.{cmd.lower()}")
            ]
            cmds.pop(0)
        if cmds:
            cmd = cmds[0]
            a.append(
                InlineKeyboardButton(f"{cmd.capitalize()}",
                                     callback_data=f"get_mod.{cmd.lower()}"))
            cmds.pop(0)
        if cmds:
            cmd = cmds[0]
            a.append(
                InlineKeyboardButton(f"{cmd.capitalize()}",
                                     callback_data=f"get_mod.{cmd.lower()}"))
            cmds.pop(0)
        kb.append(a)
    return kb
Ejemplo n.º 2
0
async def gen_cmds_kb(m: Message or CallbackQuery):
    """Generate the keyboard for languages."""
    if isinstance(m, CallbackQuery):
        m = m.message

    cmds = sorted(list(HELP_COMMANDS.keys()))
    kb = [(tlang(m, cmd), f"get_mod.{cmd.lower()}") for cmd in cmds]

    return [kb[i : i + 3] for i in range(0, len(kb), 3)]
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
async def commands_pvt(_, m: Message):

    me = await get_key("BOT_USERNAME")

    if (m.text.split()) != 1:
        help_option = (m.text.split(None, 1)[1]).lower()
        if help_option in sorted([i.lower() for i in list(HELP_COMMANDS.keys())]):
            help_msg = HELP_COMMANDS[help_option]
        if m.chat.type == "private":
            await m.reply_text(help_msg)
        else:
            await m.reply_text(
                tlang(m, "start.public_help").format(help_option=help_option),
                reply_markup=InlineKeyboardMarkup(
                    [
                        [
                            InlineKeyboardButton(
                                "Help",
                                url=f"t.me/{me}?start={help_option}",
                            ),
                        ],
                    ],
                ),
            )
        return
    if m.chat.type == "private":
        keyboard = InlineKeyboardMarkup(
            inline_keyboard=[
                *gen_cmds_kb(),
                [
                    InlineKeyboardButton(
                        f"« {tlang(m, 'general.back_btn')}",
                        callback_data="start_back",
                    ),
                ],
            ],
        )
        msg = tlang(m, "general.commands_available")
    else:
        keyboard = InlineKeyboardMarkup(
            [
                [
                    InlineKeyboardButton(
                        text="Help",
                        url=f"t.me/{me}?start=help",
                    ),
                ],
            ],
        )
        msg = tlang(m, "start.pm_for_help")

    await m.reply_text(
        msg,
        reply_markup=keyboard,
    )

    return
Ejemplo n.º 5
0
async def get_help_msg(m, help_option: str):
    """Helper function for getting help_msg and it's keyboard."""

    help_msg = None
    help_kb = None
    help_cmd_keys = sorted([
        k for j in
        [HELP_COMMANDS[i]["alt_cmds"] for i in list(HELP_COMMANDS.keys())]
        for k in j
    ], )

    if help_option in help_cmd_keys:
        help_option_name = next(HELP_COMMANDS[i] for i in HELP_COMMANDS
                                if help_option in HELP_COMMANDS[i]["alt_cmds"])
        help_option_value = help_option_name["help_msg"]
        help_kb = next(HELP_COMMANDS[i]["buttons"] for i in HELP_COMMANDS
                       if help_option in HELP_COMMANDS[i]["alt_cmds"]) + [
                           [
                               InlineKeyboardButton(
                                   "« " + (tlang(m, "general.back_btn")),
                                   callback_data="commands",
                               ),
                           ],
                       ]
        help_msg = (
            f"**{(tlang(m, (help_option_name['help_msg']).replace('.help', '.main')))}:**\n\n"
            + tlang(m, help_option_value))
        LOGGER.info(
            f"{m.from_user.id} fetched help for {help_option} in {m.chat.id}",
        )
    else:
        help_msg = tlang(m, "general.commands_available")
        help_kb = [
            *(await gen_cmds_kb(m)),
            [
                InlineKeyboardButton(
                    f"« {(tlang(m, 'general.back_btn'))}",
                    callback_data="start_back",
                ),
            ],
        ]

    return help_msg, help_kb
Ejemplo n.º 6
0
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())
        return await m.reply_text(f"Disabled {m.text.split(None, 1)[1]}!")
    if str(m.text.split(None, 1)[1]) not in disable_cmd_keys:
        return await m.reply_text("Can't do it sorry !")
Ejemplo n.º 7
0
async def gen_cmds_kb(m: Message or CallbackQuery):
    """Generate the keyboard for languages."""
    if isinstance(m, CallbackQuery):
        m = m.message

    cmds = sorted(list(HELP_COMMANDS.keys()))
    kb = []

    while cmds:
        if cmds:
            cmd = cmds[0]
            a = [
                InlineKeyboardButton(
                    tlang(m, cmd),
                    callback_data=f"get_mod.{cmd.lower()}",
                ),
            ]
            cmds.pop(0)
        if cmds:
            cmd = cmds[0]
            a.append(
                InlineKeyboardButton(
                    tlang(m, cmd),
                    callback_data=f"get_mod.{cmd.lower()}",
                ), )
            cmds.pop(0)
        if cmds:
            cmd = cmds[0]
            a.append(
                InlineKeyboardButton(
                    tlang(m, cmd),
                    callback_data=f"get_mod.{cmd.lower()}",
                ), )
            cmds.pop(0)
        kb.append(a)
    return kb