Spaces:
Running
Running
File size: 8,041 Bytes
607505f a6d0535 607505f d3100d7 607505f d3100d7 607505f a6d0535 d3100d7 a6d0535 d3100d7 a6d0535 607505f a6d0535 d3100d7 a6d0535 d3100d7 a6d0535 607505f d3100d7 607505f d3100d7 607505f |
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 |
# Ultroid - UserBot
# Copyright (C) 2021-2025 TeamUltroid
#
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
# PLease read the GNU Affero General Public License in
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
from telethon.errors.rpcerrorlist import (
BotInlineDisabledError,
BotInvalidError,
BotMethodInvalidError,
BotResponseTimeoutError,
)
from telethon.tl.custom import Button
from pyUltroid.dB._core import HELP, LIST
from pyUltroid.fns.tools import cmd_regex_replace
from . import HNDLR, LOGS, OWNER_NAME, asst, get_string, inline_pic, udB, ultroid_cmd
def _build_help_menu(include_settings=True, include_manager=False):
"""Build the help menu dynamically, optionally including settings button and manager help"""
menu = [
[
Button.inline(get_string("help_4"), data="uh_Official_"),
Button.inline(get_string("help_5"), data="uh_Addons_"),
],
]
# Manager Help button
if include_manager:
menu.append([Button.inline("• Manager Help •", "mngbtn")])
menu.append([
Button.inline(get_string("help_6"), data="uh_VCBot_"),
Button.inline(get_string("help_7"), data="inlone"),
])
# Settings button only if bot is available
settings_row = [Button.inline(get_string("help_8"), data="ownr")]
if include_settings:
try:
if hasattr(asst, "me") and hasattr(asst.me, "username") and asst.me.username:
settings_row.append(
Button.url(
get_string("help_9"), url=f"https://t.me/{asst.me.username}?start=set"
)
)
except Exception:
pass
menu.append(settings_row)
menu.append([Button.inline(get_string("help_10"), data="close")])
return menu
@ultroid_cmd(pattern="help( (.*)|$)")
async def _help(ult):
plug = ult.pattern_match.group(1).strip()
chat = await ult.get_chat()
if plug:
try:
if plug in HELP["Official"]:
output = f"**Plugin** - `{plug}`\n"
for i in HELP["Official"][plug]:
output += i
output += "\n© @TeamUltroid"
await ult.eor(output)
elif HELP.get("Addons") and plug in HELP["Addons"]:
output = f"**Plugin** - `{plug}`\n"
for i in HELP["Addons"][plug]:
output += i
output += "\n© @TeamUltroid"
await ult.eor(output)
elif HELP.get("VCBot") and plug in HELP["VCBot"]:
output = f"**Plugin** - `{plug}`\n"
for i in HELP["VCBot"][plug]:
output += i
output += "\n© @TeamUltroid"
await ult.eor(output)
else:
try:
x = get_string("help_11").format(plug)
for d in LIST[plug]:
x += HNDLR + d
x += "\n"
x += "\n© @TeamUltroid"
await ult.eor(x)
except BaseException:
file = None
compare_strings = []
for file_name in LIST:
compare_strings.append(file_name)
value = LIST[file_name]
for j in value:
j = cmd_regex_replace(j)
compare_strings.append(j)
if j.strip() == plug:
file = file_name
break
if not file:
# the enter command/plugin name is not found
text = f"`{plug}` is not a valid plugin!"
best_match = None
for _ in compare_strings:
if plug in _ and not _.startswith("_"):
best_match = _
break
if best_match:
text += f"\nDid you mean `{best_match}`?"
return await ult.eor(text)
output = f"**Command** `{plug}` **found in plugin** - `{file}`\n"
if file in HELP["Official"]:
for i in HELP["Official"][file]:
output += i
elif HELP.get("Addons") and file in HELP["Addons"]:
for i in HELP["Addons"][file]:
output += i
elif HELP.get("VCBot") and file in HELP["VCBot"]:
for i in HELP["VCBot"][file]:
output += i
output += "\n© @TeamUltroid"
await ult.eor(output)
except BaseException as er:
LOGS.exception(er)
await ult.eor("Error 🤔 occured.")
else:
# Check if asst is actually a bot before trying inline_query
is_bot = False
try:
# Check if asst has bot token (_bot attribute) or if me.bot is True
is_bot = (hasattr(asst, "_bot") and asst._bot) or (hasattr(asst, "me") and hasattr(asst.me, "bot") and asst.me.bot)
except Exception:
pass
if not is_bot:
# asst is not a bot, fallback to button-based help menu
z = []
for x in LIST.values():
z.extend(x)
cmd = len(z) + 10
include_manager = bool(udB.get_key("MANAGER") and udB.get_key("DUAL_HNDLR") == "/")
help_menu = _build_help_menu(include_settings=False, include_manager=include_manager)
return await ult.reply(
get_string("inline_4").format(
OWNER_NAME,
len(HELP["Official"]),
len(HELP["Addons"] if "Addons" in HELP else []),
cmd,
),
file=inline_pic(),
buttons=help_menu,
)
try:
results = await ult.client.inline_query(asst.me.username, "ultd")
except BotInvalidError:
# Bot is invalid, fallback to button-based help menu
z = []
for x in LIST.values():
z.extend(x)
cmd = len(z) + 10
include_manager = bool(udB.get_key("MANAGER") and udB.get_key("DUAL_HNDLR") == "/")
help_menu = _build_help_menu(include_settings=False, include_manager=include_manager)
return await ult.reply(
get_string("inline_4").format(
OWNER_NAME,
len(HELP["Official"]),
len(HELP["Addons"] if "Addons" in HELP else []),
cmd,
),
file=inline_pic(),
buttons=help_menu,
)
except BotMethodInvalidError:
z = []
for x in LIST.values():
z.extend(x)
cmd = len(z) + 10
include_manager = bool(udB.get_key("MANAGER") and udB.get_key("DUAL_HNDLR") == "/")
help_menu = _build_help_menu(include_settings=False, include_manager=include_manager)
return await ult.reply(
get_string("inline_4").format(
OWNER_NAME,
len(HELP["Official"]),
len(HELP["Addons"] if "Addons" in HELP else []),
cmd,
),
file=inline_pic(),
buttons=help_menu,
)
except BotResponseTimeoutError:
return await ult.eor(
get_string("help_2").format(HNDLR),
)
except BotInlineDisabledError:
return await ult.eor(get_string("help_3"))
await results[0].click(chat.id, reply_to=ult.reply_to_msg_id, hide_via=True)
await ult.delete()
|