diff --git a/config.py b/config.py index 0f861952..882f9176 100644 --- a/config.py +++ b/config.py @@ -75,6 +75,6 @@ class Config(object): THUMB_PIC = os.getenv("THUMB_PIC", "material/images/tron.png") # --------------------- TL_NAME = os.getenv("TL_NAME") - + HELP_EMOJI = os.getenv("HELP_EMOJI") diff --git a/tronx/__main__.py b/tronx/__main__.py index c1702336..215cc1fd 100644 --- a/tronx/__main__.py +++ b/tronx/__main__.py @@ -12,6 +12,7 @@ async def start_assistant(): """ Start assistant """ if app.bot: + await app.bot.start() app.log.info("Assistant activated, startup in progress . . .\n") else: app.log.info("Assistant start unsuccessful, please check that you have given the bot token.\n") @@ -23,6 +24,7 @@ async def start_assistant(): async def start_userbot(): """ Start userbot """ if app: + await app.start() app.log.info("Userbot activated, startup in progress . . .\n") else: app.log.info("Userbot startup unsuccessful, please check everything again ...") @@ -43,7 +45,7 @@ async def start_bot(): print(f"\n\n{_mods} modules Loaded") await start_assistant() await start_userbot() - idle() + await idle() diff --git a/tronx/clients/client.py b/tronx/clients/client.py index da53c1b0..e0385a92 100644 --- a/tronx/clients/client.py +++ b/tronx/clients/client.py @@ -14,24 +14,15 @@ def __init__(self): workers=self.WORKERS, ) self.start() - - def tron(self): - return print(self.get_me()) - - def dc_id(self): - return (self.get_me()) - - def id(self): - return (self.get_me()) - - def name(self): - return (self.get_me()) - - def username(self): - return "@" + (self.get_me()) if (self.get_me()) else "" - - - class bot(Client, Utils): + self.bot = self.Bot() + self.me = self.get_me() + self.id = self.me.id + self.dc_id = self.me.dc_id + self.name = self.me.first_name + self.username = "@" + self.me.username if self.me.username else "" + self.stop() + + class Bot(Client, Utils): """ Assistant (Nora) """ def __init__(self): super().__init__( @@ -41,19 +32,9 @@ def __init__(self): bot_token=self.TOKEN, ) self.start() - - def nora(self): - return self.bot.get_me() - - def dc_id(self): - return (self.bot.get_me()) - - def id(self): - return (self.bot.get_me()) - - def name(self): - return (self.bot.get_me()) - - def username(self): - return "@" + (self.bot.get_me()) - + self.me = self.get_me() + self.id = self.me.id + self.dc_id = self.me.dc_id + self.name = self.me.first_name + self.username = "@" + self.me.username + self.stop() diff --git a/tronx/helpers/decorators.py b/tronx/helpers/decorators.py index 83398c4c..a91972cc 100644 --- a/tronx/helpers/decorators.py +++ b/tronx/helpers/decorators.py @@ -8,7 +8,7 @@ class Decorators(object): def alert_user(self, func): async def wrapper(_, cb: CallbackQuery): - if cb.from_user and not cb.from_user.id in self.USER_ID: + if cb.from_user and not cb.from_user.id == self.id: await cb.answer( f"Sorry, but you can't use this userbot ! make your own userbot at @tronuserbot", show_alert=True diff --git a/tronx/helpers/functions.py b/tronx/helpers/functions.py index a0140135..38efa451 100644 --- a/tronx/helpers/functions.py +++ b/tronx/helpers/functions.py @@ -136,11 +136,11 @@ async def send_edit( formats = [mono, bold, italic, strike, underline] format_dict = { - "mono" : f"{text}", - "bold" : f"{text}", - "italic" : f"{text}", - "strike" : f"{text}", - "underline" : f"{text}" + mono : f"{text}", + bold : f"{text}", + italic : f"{text}", + strike : f"{text}", + underline : f"{text}" } edited = False @@ -150,7 +150,7 @@ async def send_edit( await self.edit_text( m, format_dict[x], - disable_wab_page_preview=disable_wab_page_preview, + disable_web_page_preview=disable_web_page_preview, parse_mode=parse_mode ) edited = True diff --git a/tronx/helpers/user.py b/tronx/helpers/user.py index 88aa7269..4028a82c 100644 --- a/tronx/helpers/user.py +++ b/tronx/helpers/user.py @@ -17,7 +17,7 @@ def UserUsername(self): # mention of bot owner def UserMention(self): - return self.mention_markdown(self.UserId(), self.UserName()) if self.UserName() and self.UserId() else None + return self.MentionMarkdown(self.UserId(), self.UserName()) if self.UserName() and self.UserId() else None # telegram id of bot owner @@ -32,3 +32,10 @@ def UserId(self): def UserDc(self): data = self.USER_DC if self.USER_DC else self.dc_id return data if data else None + + + # custom user pic + def UserPic(self): + var = self.getdv("USER_PIC") + one = var if bool(var) is True else self.USER_PIC + return one if one else None diff --git a/tronx/helpers/utilities.py b/tronx/helpers/utilities.py index 86a0b2c3..5d780c2a 100644 --- a/tronx/helpers/utilities.py +++ b/tronx/helpers/utilities.py @@ -329,7 +329,7 @@ def DictSizeInBytes(self, directory): elif entry.is_dir(): # if it's a directory, recursively call this function - total += DictSizeInBytes(entry.path) + total += self.DictSizeInBytes(entry.path) except NotADirectoryError: # if `directory` isn't a directory, get the file size then return os.path.getsize(directory) @@ -348,7 +348,7 @@ def SizeFormat(self, b, factor=1024, suffix="B"): def DictSize(self, location): - return SizeFormat(DictSizeInBytes(location)) + return self.SizeFormat(self.DictSizeInBytes(location)) def CleanHtml(self, raw_html): diff --git a/tronx/modules/afk.py b/tronx/modules/afk.py index 144fb575..3e87c056 100644 --- a/tronx/modules/afk.py +++ b/tronx/modules/afk.py @@ -35,7 +35,7 @@ async def go_offline(_, m: Message): app.set_afk(True, m.text.split(None, 1)[1], start) # with reason await app.send_edit( m, - "{} is now Offline.\nBecause: {}".format(app.mymention(), m.text.split(None, 1)[1]), + "{} is now Offline.\nBecause: {}".format(app.UserMention(), m.text.split(None, 1)[1]), delme=2 ) elif app.long(m) == 1 and app.long(m) < 4096: @@ -51,7 +51,7 @@ async def go_offline(_, m: Message): app.set_afk(True, "", start) # without reason await app.send_edit( m, - "{} is now offline.".format(app.mymention()), + "{} is now offline.".format(app.UserMention()), delme=2 ) except Exception as e: @@ -79,17 +79,17 @@ async def offline_mention(_, m: Message): if get["reason"] and get["afktime"]: msg = await app.send_message( m.chat.id, - "Sorry {} is currently offline !\n**Time:** {}\n**Because:** {}".format(app.mymention(), otime, get['reason']), + "Sorry {} is currently offline !\n**Time:** {}\n**Because:** {}".format(app.UserMention(), otime, get['reason']), reply_to_message_id=m.message_id ) - await delete(msg, 3) + await app.delete(msg, 3) elif get["afktime"] and not get["reason"]: - await app.send_message( + msg = await app.send_message( m.chat.id, - "Sorry {} is currently offline !\n**Time:** {}".format(app.mymention(), otime), + "Sorry {} is currently offline !\n**Time:** {}".format(app.UserMention(), otime), reply_to_message_id=m.message_id ) - await delete(msg, 3) + await app.delete(msg, 3) content, message_type = app.GetMessageType(m) if message_type == app.TEXT: if m.text: @@ -135,11 +135,9 @@ async def back_online(_, m: Message): afk_time = app.GetReadableTime(end - get["afktime"]) msg = await app.send_message( m.chat.id, - f"{app.mymention()} is now online !\n**Time:** `{afk_time}`" + f"{app.UserMention()} is now online !\n**Time:** `{afk_time}`" ) app.set_afk(False, "", 0) - else: - return except Exception as e: await app.error(m, e) diff --git a/tronx/modules/alive.py b/tronx/modules/alive.py index 60947ebd..394b08f0 100644 --- a/tronx/modules/alive.py +++ b/tronx/modules/alive.py @@ -39,7 +39,7 @@ async def simple_alive(_, m: Message): alive_msg = f"\n" if BIO: alive_msg += f"⦿ {BIO}\n\n" - alive_msg += f"⟜ **Owner:** {app.mymention()}\n" + alive_msg += f"⟜ **Owner:** {app.UserMention()}\n" alive_msg += f"⟜ **Tron:** `{app.userbot_version}`\n" alive_msg += f"⟜ **Python:** `{app.python_version}`\n" alive_msg += f"⟜ **Pyrogram:** `{app.pyrogram_version}`\n" @@ -106,7 +106,7 @@ async def inline_quote(_, m: Message): try: await app.send_edit(m,". . .") try: - result = await app.get_inline_bot_results(BOT_USERNAME, "#q7o5e") + result = await app.get_inline_bot_results(app.bot.username, "#q7o5e") except BotInvalid: return await app.send_edit(m,"This bot can't be used in inline mode.", delme=2) diff --git a/tronx/modules/carbon.py b/tronx/modules/carbon.py index a5585d77..60eec945 100644 --- a/tronx/modules/carbon.py +++ b/tronx/modules/carbon.py @@ -107,7 +107,7 @@ async def create_carbon(m: Message, text, colour): await app.send_document( m.chat.id, filename, - caption=f"**Carbon Made by:** {app.mymention()}", + caption=f"**Carbon Made by:** {app.UserMention()}", reply_to_message_id=reply_msg_id, ) await m.delete() diff --git a/tronx/modules/download.py b/tronx/modules/download.py index 91892ed8..99492c9c 100644 --- a/tronx/modules/download.py +++ b/tronx/modules/download.py @@ -66,9 +66,9 @@ async def list_directories(_, m: Message): for file in files: if not file.endswith(".session") and not file in ["__pycache__", ".git", ".github", ".profile.d", ".heroku", ".cache"]: if os.path.isfile(f"{location}/{file}"): - collect.append(f"📑 `{file}` ({DictSize(os.path.abspath(location+file))})") + collect.append(f"📑 `{file}` ({app.DictSize(os.path.abspath(location+file))})") if os.path.isdir(f"{location}/{file}"): - collect.append(f"🗂️ `{file}` ({DictSize(os.path.abspath(location+file))})") + collect.append(f"🗂️ `{file}` ({app.DictSize(os.path.abspath(location+file))})") collect.sort() # sort the files file = "\n".join(collect) diff --git a/tronx/modules/fun.py b/tronx/modules/fun.py index cf5bdf1d..3b6411eb 100644 --- a/tronx/modules/fun.py +++ b/tronx/modules/fun.py @@ -42,7 +42,7 @@ async def slap_friends(app, m): try: await app.send_edit(m,"...") - my_info = app.mymention() + my_info = app.UserMention() user = m.reply_to_message.from_user user_info = app.mention_markdown(user.id, user.first_name) TASK = ( diff --git a/tronx/modules/google.py b/tronx/modules/google.py index 9d3f330e..f471da51 100644 --- a/tronx/modules/google.py +++ b/tronx/modules/google.py @@ -73,10 +73,9 @@ async def image_sauce(_, m: Message): file_name="./downloads/" + universe ) else: - await app.send_edit(m, "Only photo & animation media supported.", delme=3) - return + return await app.send_edit(m, "Only photo & animation media supported.", delme=3) searchUrl = 'http://www.google.co.id/searchbyimage/upload' - filePath = 'tronx/downloads/{}'.format(universe) + filePath = './downloads/{}'.format(universe) multipart = {'encoded_image': (filePath, open(filePath, 'rb')), 'image_content': ''} response = requests.post(searchUrl, files=multipart, allow_redirects=False) fetchUrl = response.headers['Location'] diff --git a/tronx/modules/group.py b/tronx/modules/group.py index 9675b1ff..d5109b31 100644 --- a/tronx/modules/group.py +++ b/tronx/modules/group.py @@ -17,9 +17,10 @@ {"group" : ( "group", { - "group [group name]" : "Creates a basic group.", + "bgroup [group name]" : "Creates a basic group.", "sgroup [group name]" : "Creates a super group.", - "unread" : "Mark a chat as unread in your telegram folders." + "unread" : "Mark a chat as unread in your telegram folders.", + "channel [channel name]" : "Create a channel through this command." } ) } @@ -31,21 +32,16 @@ @app.on_message(gen(["bgroup", "bgp"])) async def create_basic_group(_, m: Message): if app.long(m) < 2: - return await app.send_edit(m, f"`Usage: {app.PREFIX}group [group name]`", delme=3) + return await app.send_edit(m, f"`Usage: {app.PREFIX}bgroup [group name]`", delme=3) args = m.text.split(None, 1) grpname = args[1] grptype = "basic" user_id = "@Alita_Robot" try: - if grptype == "basic": - try: - await app.send_edit(m, f"Creating a new basic group: `{grpname}`") - groupjson = await app.create_group(f"{grpname}", user_id) - print(groupjson) - except Exception as e: - await app.error(m, e) - await app.send_edit(m, f"**Created a new basic group:** `{grpname}`") + await app.send_edit(m, f"Creating a new basic group: `{grpname}`") + groupjson = await app.create_group(f"{grpname}", user_id) + await app.send_edit(m, f"**Created a new basic group:** `{grpname}`") except Exception as e: await app.error(m, e) @@ -62,15 +58,9 @@ async def create_supergroup(_, m: Message): grptype = "super" user_id = "@Alita_Robot" try: - if grptype == "super": - try: - await app.send_edit(m, f"Creating a new super Group: `{grpname}`") - await app.create_group( - f"{grpname}", user_id - ) - except Exception as e: - await app.error(m, e) - await app.send_edit(m, f"**Created a new super Group:** `{grpname}`") + await app.send_edit(m, f"Creating a new super Group: `{grpname}`") + await app.create_supergroup(f"{grpname}", user_id) + await app.send_edit(m, f"**Created a new super Group:** `{grpname}`") except Exception as e: await app.error(m, e) diff --git a/tronx/modules/help.py b/tronx/modules/help.py index c8c9b499..b406b9a3 100644 --- a/tronx/modules/help.py +++ b/tronx/modules/help.py @@ -32,7 +32,7 @@ -@app.bot.on_callback_query(filters.regex("delete-dex") & filters.user(app.id())) +@app.bot.on_callback_query(filters.regex("delete-dex") & filters.user(app.id)) @app.alert_user async def delete_helpdex(_, cb: CallbackQuery): if bool(app.message_ids) is False: @@ -64,7 +64,7 @@ async def help_menu(app, m): if args is False: await app.send_edit(m, ". . .", mono=True) result = await app.get_inline_bot_results( - app.bot.username(), + app.bot.username, "#t5r4o9nn6" ) if result: diff --git a/tronx/modules/heroku.py b/tronx/modules/heroku.py index b7e1c1d6..7fee9739 100644 --- a/tronx/modules/heroku.py +++ b/tronx/modules/heroku.py @@ -117,7 +117,7 @@ async def dynostats(_, m: Message): r = requests.get(heroku_api + path, headers=headers) if r.status_code != 200: return await app.send_edit( - msg, + m, "Error: something bad happened`\n\n" f"> {r.reason}\n", mono=True ) @@ -144,7 +144,7 @@ async def dynostats(_, m: Message): AppMinutes = math.floor(AppQuotaUsed % 60) await app.send_edit( - msg, + m, "**Dyno Usage**:\n\n" f"**Total Dyno Hours:** `550 Hours`\n\n" f"**⧓ Dyno usage for App:** __`{app.HEROKU_APP_NAME}`__\n" @@ -318,11 +318,7 @@ async def delvar(_, m: Message): @app.on_message(gen("logs")) async def logs(_, m: Message): await not_heroku(m) - await app.send_edit( - m, - "⏳ • hold on . . .", - mono=True - ) + await app.send_edit(m, "⏳ • hold on . . .", mono=True) try: Heroku = heroku3.from_key(app.HEROKU_API_KEY) zen = Heroku.app(app.HEROKU_APP_NAME) @@ -336,23 +332,19 @@ async def logs(_, m: Message): data = zen.get_log() if data: try: - file = open(f"{app.username()}_logs.txt", "w+") + file = open(f"{app.username}_logs.txt", "w+") file.write(data) file.close() await app.send_document( m.chat.id, - f"{app.username()}_logs.txt", - caption=f"Uploaded By: {app.mymention()}") - os.remove(f"{app.username()}_logs.txt") + f"{app.username}_logs.txt", + caption=f"Uploaded By: {app.UserMention()}") + os.remove(f"{app.username}_logs.txt") await m.delete() except Exception as e: await app.error(m, e) else: - await app.send_edit( - m, - "Failed to get logs . . .", - delme=3 - ) + await app.send_edit(m, "Failed to get logs . . .", delme=3) @@ -361,10 +353,7 @@ async def logs(_, m: Message): @app.on_message(gen(["textlogs", "tlogs"])) async def logs_in_text(_, m: Message): await not_heroku(m) - await app.send_edit( - m, - "⏳ • hold on . . . ", mono=True - ) + await app.send_edit(m, "⏳ • hold on . . . ", mono=True) try: Heroku = heroku3.from_key(app.HEROKU_API_KEY) zen = Heroku.app(app.HEROKU_APP_NAME) diff --git a/tronx/plugins/callback.py b/tronx/plugins/callback.py index bebbaabc..201d73e5 100644 --- a/tronx/plugins/callback.py +++ b/tronx/plugins/callback.py @@ -43,7 +43,7 @@ async def modules(_, cb): @app.alert_user async def give_next_page(_, cb): current_page_number = int(cb.matches[0].group(1)) - buttons = app.helpDex(current_page_number + 1, app.CMD_HELP, "helpme") + buttons = app.HelpDex(current_page_number + 1, app.CMD_HELP, "helpme") print(cb.matches[0]) print(dir(cb.matches[0])) await cb.edit_message_reply_markup(reply_markup=InlineKeyboardMarkup(buttons)) @@ -54,7 +54,7 @@ async def give_next_page(_, cb): @app.alert_user async def give_old_page(_, cb): current_page_number = int(cb.matches[0].group(1)) - buttons = app.Helpdex(current_page_number - 1, app.CMD_HELP, "helpme") + buttons = app.HelpDex(current_page_number - 1, app.CMD_HELP, "helpme") await cb.edit_message_reply_markup(reply_markup=InlineKeyboardMarkup(buttons)) @@ -76,7 +76,7 @@ async def give_plugin_cmds(_, cb): plugs = await app.data(plugin_name) help_string = f"PLUGIN: {plugin_name}\n\n" + "".join(plugs) await cb.edit_message_text( - app.help_string, + help_string, reply_markup=InlineKeyboardMarkup( [ [ @@ -95,7 +95,7 @@ async def give_plugin_cmds(_, cb): @app.alert_user async def _stats(_, cb): await cb.edit_message_text( - text=app.stat_string, + text=app.stat_string(), reply_markup=InlineKeyboardMarkup([home_back]), ) @@ -159,7 +159,7 @@ async def _extra(_, cb): @app.alert_user async def _close(_, cb: CallbackQuery): await cb.edit_message_text( - text=app.closed_menu_string, + text=app.closed_menu_string(), reply_markup=InlineKeyboardMarkup( [ [ diff --git a/tronx/plugins/inlinequery.py b/tronx/plugins/inlinequery.py index 8cefead8..6558b8c4 100644 --- a/tronx/plugins/inlinequery.py +++ b/tronx/plugins/inlinequery.py @@ -30,7 +30,7 @@ # via bot messages @app.bot.on_inline_query(filters.user(app.id)) -def inline_res(_, inline_query): +def inline_result(_, inline_query): query = inline_query.query if query.startswith("#p0e3r4m8i8t5"): inline_query.answer( @@ -64,10 +64,10 @@ def inline_res(_, inline_query): inline_query.answer( results=[ InlineQueryResultPhoto( - photo_url=ialive_pic(), + photo_url=app.ialive_pic(), title="Inline alive", description="This is same as alive command, the difference is that this command have inline button.", - caption=f"**⛊ Inline Status:**\n\n**⟐** {Config.USER_BIO}\n\n**⟜ Owner**: [{USER_NAME}](https://t.me/{USER_USERNAME})\n**⟜ Tron:** `{userbot_version}`\n**⟜ Python:** `{python_version}`\n⟜ **Pyrogram:** `{pyrogram_version}`\n⟜ **uptime:** `{uptime()}\n\n", + caption=f"**⛊ Inline Status:**\n\n**⟐** {app.USER_BIO}\n\n**⟜ Owner**: [{app.name}](https://t.me/{app.username})\n**⟜ Tron:** `{app.userbot_version}`\n**⟜ Python:** `{app.python_version}`\n⟜ **Pyrogram:** `{app.pyrogram_version}`\n⟜ **uptime:** `{app.uptime()}\n\n", parse_mode="combined", reply_markup=InlineKeyboardMarkup([home_back]) ) diff --git a/tronx/plugins/start.py b/tronx/plugins/start.py index 4956e813..2a0eec92 100644 --- a/tronx/plugins/start.py +++ b/tronx/plugins/start.py @@ -16,7 +16,7 @@ async def send_help(_, m: Message): @app.bot.on_message(filters.new_chat_members & filters.group) async def added_to_group_msg(_, m: Message): - if m.new_chat_members[0].id == app.REAL_BOT_ID: + if m.new_chat_members[0].id == app.bot.id: try: await app.bot.send_message( m.chat.id,