azils3/bash
0
1# Ultroid - UserBot2# Copyright (C) 2021-2025 TeamUltroid3#4# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >5# PLease read the GNU Affero General Public License in6# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.7 8import re9import time10from datetime import datetime11from os import remove12 13from git import Repo14from telethon import Button15from telethon.tl.types import InputWebDocument, Message16from telethon.utils import resolve_bot_file_id17 18from pyUltroid._misc._assistant import callback, in_pattern19from pyUltroid.dB._core import HELP, LIST20from pyUltroid.fns.helper import gen_chlog, time_formatter, updater21from pyUltroid.fns.misc import split_list22 23from . import (24 HNDLR,25 LOGS,26 OWNER_NAME,27 InlinePlugin,28 asst,29 get_string,30 inline_pic,31 split_list,32 start_time,33 udB,34)35from ._help import _main_help_menu36 37# ================================================#38 39helps = get_string("inline_1")40 41add_ons = udB.get_key("ADDONS")42 43zhelps = get_string("inline_3") if add_ons is False else get_string("inline_2")44PLUGINS = HELP.get("Official", [])45ADDONS = HELP.get("Addons", [])46upage = 047# ============================================#48 49# --------------------BUTTONS--------------------#50 51SUP_BUTTONS = [52 [53 Button.url("• Repo •", url="https://github.com/TeamUltroid/Ultroid"),54 Button.url("• Support •", url="t.me/UltroidSupportChat"),55 ],56]57 58# --------------------BUTTONS--------------------#59 60 61@in_pattern(owner=True, func=lambda x: not x.text)62async def inline_alive(o):63 TLINK = inline_pic() or "https://graph.org/file/74d6259983e0642923fdb.jpg"64 MSG = "• **Ultroid Userbot •**"65 WEB0 = InputWebDocument(66 "https://graph.org/file/acd4f5d61369f74c5e7a7.jpg", 0, "image/jpg", []67 )68 RES = [69 await o.builder.article(70 type="photo",71 text=MSG,72 include_media=True,73 buttons=SUP_BUTTONS,74 title="Ultroid Userbot",75 description="Userbot | Telethon",76 url=TLINK,77 thumb=WEB0,78 content=InputWebDocument(TLINK, 0, "image/jpg", []),79 )80 ]81 await o.answer(82 RES,83 private=True,84 cache_time=300,85 switch_pm="👥 ULTROID PORTAL",86 switch_pm_param="start",87 )88 89 90@in_pattern("ultd", owner=True)91async def inline_handler(event):92 z = []93 for x in LIST.values():94 z.extend(x)95 text = get_string("inline_4").format(96 OWNER_NAME,97 len(HELP.get("Official", [])),98 len(HELP.get("Addons", [])),99 len(z),100 )101 if inline_pic():102 result = await event.builder.photo(103 file=inline_pic(),104 link_preview=False,105 text=text,106 buttons=_main_help_menu,107 )108 else:109 result = await event.builder.article(110 title="Ultroid Help Menu", text=text, buttons=_main_help_menu111 )112 await event.answer([result], private=True, cache_time=300, gallery=True)113 114 115@in_pattern("pasta", owner=True)116async def _(event):117 ok = event.text.split("-")[1]118 if not ok.startswith("http"):119 link = f"https://spaceb.in/{ok}"120 raw = f"https://spaceb.in/api/v1/documents/{ok}/raw"121 else:122 link = ok123 raw = f"{ok}/raw"124 result = await event.builder.article(125 title="Paste",126 text="Pasted to Spacebin 🌌",127 buttons=[128 [129 Button.url("SpaceBin", url=link),130 Button.url("Raw", url=raw),131 ],132 ],133 )134 await event.answer([result])135 136 137@callback("ownr", owner=True)138async def setting(event):139 z = []140 for x in LIST.values():141 z.extend(x)142 await event.edit(143 get_string("inline_4").format(144 OWNER_NAME,145 len(HELP.get("Official", [])),146 len(HELP.get("Addons", [])),147 len(z),148 ),149 file=inline_pic(),150 link_preview=False,151 buttons=[152 [153 Button.inline("•Pɪɴɢ•", data="pkng"),154 Button.inline("•Uᴘᴛɪᴍᴇ•", data="upp"),155 ],156 [157 Button.inline("•Stats•", data="alive"),158 Button.inline("•Uᴘᴅᴀᴛᴇ•", data="doupdate"),159 ],160 [Button.inline("« Bᴀᴄᴋ", data="open")],161 ],162 )163 164 165_strings = {"Official": helps, "Addons": zhelps, "VCBot": get_string("inline_6")}166 167 168@callback(re.compile("uh_(.*)"), owner=True)169async def help_func(ult):170 key, count = ult.data_match.group(1).decode("utf-8").split("_")171 if key == "VCBot" and HELP.get("VCBot") is None:172 return await ult.answer(get_string("help_12"), alert=True)173 elif key == "Addons" and HELP.get("Addons") is None:174 return await ult.answer(get_string("help_13").format(HNDLR), alert=True)175 if "|" in count:176 _, count = count.split("|")177 count = int(count) if count else 0178 text = _strings.get(key, "").format(OWNER_NAME, len(HELP.get(key)))179 await ult.edit(text, buttons=page_num(count, key), link_preview=False)180 181 182@callback(re.compile("uplugin_(.*)"), owner=True)183async def uptd_plugin(event):184 key, file = event.data_match.group(1).decode("utf-8").split("_")185 index = None186 if "|" in file:187 file, index = file.split("|")188 key_ = HELP.get(key, [])189 hel_p = f"Plugin Name - `{file}`\n"190 help_ = ""191 try:192 for i in key_[file]:193 help_ += i194 except BaseException:195 if file in LIST:196 help_ = get_string("help_11").format(file)197 for d in LIST[file]:198 help_ += HNDLR + d199 help_ += "\n"200 if not help_:201 help_ = f"{file} has no Detailed Help!"202 help_ += "\n© @TeamUltroid"203 buttons = []204 if inline_pic():205 data = f"sndplug_{key}_{file}"206 if index is not None:207 data += f"|{index}"208 buttons.append(209 [210 Button.inline(211 "« Sᴇɴᴅ Pʟᴜɢɪɴ »",212 data=data,213 )214 ]215 )216 data = f"uh_{key}_"217 if index is not None:218 data += f"|{index}"219 buttons.append(220 [221 Button.inline("« Bᴀᴄᴋ", data=data),222 ]223 )224 try:225 await event.edit(help_, buttons=buttons)226 except Exception as er:227 LOGS.exception(er)228 help = f"Do `{HNDLR}help {key}` to get list of commands."229 await event.edit(help, buttons=buttons)230 231 232@callback(data="doupdate", owner=True)233async def _(event):234 if not await updater():235 return await event.answer(get_string("inline_9"), cache_time=0, alert=True)236 if not inline_pic():237 return await event.answer(f"Do '{HNDLR}update' to update..")238 repo = Repo.init()239 changelog, tl_chnglog = await gen_chlog(240 repo, f"HEAD..upstream/{repo.active_branch}"241 )242 changelog_str = changelog + "\n\n" + get_string("inline_8")243 if len(changelog_str) > 1024:244 await event.edit(get_string("upd_4"))245 with open("ultroid_updates.txt", "w+") as file:246 file.write(tl_chnglog)247 await event.edit(248 get_string("upd_5"),249 file="ultroid_updates.txt",250 buttons=[251 [Button.inline("• Uᴘᴅᴀᴛᴇ Nᴏᴡ •", data="updatenow")],252 [Button.inline("« Bᴀᴄᴋ", data="ownr")],253 ],254 )255 remove("ultroid_updates.txt")256 else:257 await event.edit(258 changelog_str,259 buttons=[260 [Button.inline("Update Now", data="updatenow")],261 [Button.inline("« Bᴀᴄᴋ", data="ownr")],262 ],263 parse_mode="html",264 )265 266 267@callback(data="pkng", owner=True)268async def _(event):269 start = datetime.now()270 end = datetime.now()271 ms = (end - start).microseconds272 pin = f"🌋Pɪɴɢ = {ms} microseconds"273 await event.answer(pin, cache_time=0, alert=True)274 275 276@callback(data="upp", owner=True)277async def _(event):278 uptime = time_formatter((time.time() - start_time) * 1000)279 pin = f"🙋Uᴘᴛɪᴍᴇ = {uptime}"280 await event.answer(pin, cache_time=0, alert=True)281 282 283@callback(data="inlone", owner=True)284async def _(e):285 _InButtons = [286 Button.switch_inline(_, query=InlinePlugin[_], same_peer=True)287 for _ in list(InlinePlugin.keys())288 ]289 InButtons = split_list(_InButtons, 2)290 291 button = InButtons.copy()292 button.append(293 [294 Button.inline("« Bᴀᴄᴋ", data="open"),295 ],296 )297 await e.edit(buttons=button, link_preview=False)298 299 300@callback(data="open", owner=True)301async def opner(event):302 z = []303 for x in LIST.values():304 z.extend(x)305 await event.edit(306 get_string("inline_4").format(307 OWNER_NAME,308 len(HELP.get("Official", [])),309 len(HELP.get("Addons", [])),310 len(z),311 ),312 buttons=_main_help_menu,313 link_preview=False,314 )315 316 317@callback(data="close", owner=True)318async def on_plug_in_callback_query_handler(event):319 await event.edit(320 get_string("inline_5"),321 buttons=Button.inline("Oᴘᴇɴ Aɢᴀɪɴ", data="open"),322 )323 324 325def page_num(index, key):326 rows = udB.get_key("HELP_ROWS") or 5327 cols = udB.get_key("HELP_COLUMNS") or 2328 loaded = HELP.get(key, [])329 emoji = udB.get_key("EMOJI_IN_HELP") or "✘"330 List = [331 Button.inline(f"{emoji} {x} {emoji}", data=f"uplugin_{key}_{x}|{index}")332 for x in sorted(loaded)333 ]334 all_ = split_list(List, cols)335 fl_ = split_list(all_, rows)336 try:337 new_ = fl_[index]338 except IndexError:339 new_ = fl_[0] if fl_ else []340 index = 0341 if index == 0 and len(fl_) == 1:342 new_.append([Button.inline("« Bᴀᴄᴋ »", data="open")])343 else:344 new_.append(345 [346 Button.inline(347 "« Pʀᴇᴠɪᴏᴜs",348 data=f"uh_{key}_{index-1}",349 ),350 Button.inline("« Bᴀᴄᴋ »", data="open"),351 Button.inline(352 "Nᴇxᴛ »",353 data=f"uh_{key}_{index+1}",354 ),355 ]356 )357 return new_358 359 360# --------------------------------------------------------------------------------- #361 362 363STUFF = {}364 365 366@in_pattern("stf(.*)", owner=True)367async def ibuild(e):368 n = e.pattern_match.group(1).strip()369 builder = e.builder370 if not (n and n.isdigit()):371 return372 ok = STUFF.get(int(n))373 txt = ok.get("msg")374 pic = ok.get("media")375 btn = ok.get("button")376 if not (pic or txt):377 txt = "Hey!"378 if pic:379 try:380 include_media = True381 mime_type, _pic = None, None382 cont, results = None, None383 try:384 ext = str(pic).split(".")[-1].lower()385 except BaseException:386 ext = None387 if ext in ["img", "jpg", "png"]:388 _type = "photo"389 mime_type = "image/jpg"390 elif ext in ["mp4", "mkv", "gif"]:391 mime_type = "video/mp4"392 _type = "gif"393 else:394 try:395 if "telethon.tl.types" in str(type(pic)):396 _pic = pic397 else:398 _pic = resolve_bot_file_id(pic)399 except BaseException:400 pass401 if _pic:402 results = [403 await builder.document(404 _pic,405 title="Ultroid Op",406 text=txt,407 description="@TeamUltroid",408 buttons=btn,409 link_preview=False,410 )411 ]412 else:413 _type = "article"414 include_media = False415 if not results:416 if include_media:417 cont = InputWebDocument(pic, 0, mime_type, [])418 results = [419 await builder.article(420 title="Ultroid Op",421 type=_type,422 text=txt,423 description="@TeamUltroid",424 include_media=include_media,425 buttons=btn,426 thumb=cont,427 content=cont,428 link_preview=False,429 )430 ]431 return await e.answer(results)432 except Exception as er:433 LOGS.exception(er)434 result = [435 await builder.article("Ultroid Op", text=txt, link_preview=False, buttons=btn)436 ]437 await e.answer(result)438 439 440async def something(e, msg, media, button, reply=True, chat=None):441 if e.client._bot:442 return await e.reply(msg, file=media, buttons=button)443 num = len(STUFF) + 1444 STUFF.update({num: {"msg": msg, "media": media, "button": button}})445 try:446 res = await e.client.inline_query(asst.me.username, f"stf{num}")447 return await res[0].click(448 chat or e.chat_id,449 reply_to=bool(isinstance(e, Message) and reply),450 hide_via=True,451 silent=True,452 )453 454 except Exception as er:455 LOGS.exception(er)456 