__version__ = (1, 0, 0, 1) # This file is a part of Hikka Userbot # Code is NOT licensed under CC-BY-NC-ND 4.0 unless otherwise specified. # 🌐 https://github.com/hikariatama/Hikka # You CAN edit this file without direct permission from the author. # You can redistribute this file with any modifications. # meta developer: @yg_modules # scope: hikka_only # scope: hikka_min 1.6.4 # thx to @codrago for the inspiration # this module may lead to unstable operation of the userbot # β–ˆβ–„β–ˆβ€ƒβ–ˆβ–‘β–ˆβ€ƒβ–ˆβ–€β–„β–€β–ˆβ€ƒβ–ˆβ–€β–„β–€β–ˆβ€ƒβ–ˆβ–„β–ˆβ€ƒ β€ƒβ–ˆβ–€β–„β–€β–ˆβ€ƒβ–ˆβ–€β–ˆβ€ƒβ–ˆβ–€β–„β€ƒβ–ˆβ–€ # β–‘β–ˆβ–‘β€ƒβ–ˆβ–„β–ˆβ€ƒβ–ˆβ–‘β–€β–‘β–ˆβ€ƒβ–ˆβ–‘β–€β–‘β–ˆβ€ƒβ–‘β–ˆβ–‘β€ƒ β€ƒβ–ˆβ–‘β–€β–‘β–ˆβ€ƒβ–ˆβ–„β–ˆβ€ƒβ–ˆβ–„β–€β€ƒβ–„β–ˆ import os import aiofiles import aiohttp from telethon.extensions.html import parse import inspect from .. import loader, utils @loader.tds class SwitchToTelethon(loader.Module): """Auto switch from Hikka-TL to Telethon""" strings = {"name": "SwitchToTelethon"} async def client_ready(self, client, db): self.client = client # step1 if self.get("switch1"): await self._switch_to_telethon(ignore=False) await self._change_files() else: pass # step2 if self.get("switch2"): chat_id = self.get("switch2") await self.client.send_message( chat_id, f"πŸ–€ Switch to Telethon is completed successfully! (this module has been automatically unloaded)\n\n" f"✨ To restore everything to its original state, use the command {self.get_prefix()}terminal git checkout -- ., and restart" ) self.set("switch2", None) await self.invoke('unloadmod', 'SwitchToTelethon', self.inline.bot_id) @loader.command() async def switch(self, message): """Automatically switch to Telethon""" chat_id = utils.get_chat_id(message) await utils.answer(message, "πŸ™‚ Starting the first stage of switching to Telethon...") await self._switch_to_telethon(ignore=True) self.set("switch1", chat_id) await utils.answer(message, "⚑️ First stage completed. Restarting...") await self._restart() async def _restart(self): await self.invoke('restart', '-f', self.inline.bot_id) async def _switch_to_telethon(self, ignore): for root, _, files in os.walk("."): for file in files: # conflict bypass if 'SwitchToTelethon' in file: continue if file.endswith('.py') or file.endswith('.yml'): await self._process_file(os.path.join(root, file), ignore) async def _process_file(self, file_path, ignore): try: async with aiofiles.open(file_path, 'r', encoding='utf-8') as f: original = await f.readlines() updated = False switched = [] for line in original: # conflict bypass x2 if ignore and "CUSTOM_EMOJIS" in line: switched.append(line) continue # conflict bypass x3 if file_path.endswith('main.py') and ignore and line.strip() == "import hikkatl": switched.append(line) continue # change references from "hikkatl" to "telethon" for switch if file_path.endswith('.py'): if "hikkatl" in line: line = line.replace("hikkatl", "telethon") updated = True # conflict bypass x4 if "(2, 0, 8)" in line: line = line.replace("(2, 0, 8)", "(1, 35, 0)") updated = True # change references from "Hikka-TL-New" to "telethon" for switch if "Hikka-TL-New" in line: line = line.replace("Hikka-TL-New", "telethon") updated = True # for HikkaInfo elif file_path.endswith('.yml'): if 'πŸ’œ Hikka-TL:' in line: line = line.replace( "πŸ’œ Hikka-TL:", "❀️‍πŸ”₯ Telethon:" ) updated = True switched.append(line) if updated: async with aiofiles.open(file_path, 'w', encoding='utf-8') as f: await f.writelines(switched) print(f"Switched to Telethon: {file_path}") except Exception as e: print(f"Error: {file_path}: {e}") async def _change_files(self): chat_id = self.get("switch1") if not chat_id: print("No chat ID found for logging.") return try: async with aiohttp.ClientSession() as session: # update html.py async with session.get("https://raw.githubusercontent.com/yummy1gay/hikariatama-libs/main/html.py") as r_html: if r_html.status == 200: html_code = await r_html.text() async with aiofiles.open(inspect.getfile(parse), 'w', encoding='utf-8') as f_html: await f_html.write(html_code) html_message = f"πŸ‘ Updated Telethon parser file (for sending spoilers, custom emojis, etc.): {inspect.getfile(parse)}" else: html_message = f"⚠️ Failed to update HTML parse file: {r_html.status} (please, use {self.get_prefix()}terminal git checkout -- ., and restart)" # update translate.py async with session.get("https://raw.githubusercontent.com/yummy1gay/hikariatama-libs/main/translate.py") as r_translate: if r_translate.status == 200: translate_code = await r_translate.text() async with aiofiles.open("./hikka/modules/translate.py", 'w', encoding='utf-8') as f_translate: await f_translate.write(translate_code) translate_message = f"πŸ‘ Updated translation module: ./hikka/modules/translate.py (for compatibility)" else: translate_message = f"⚠️ Failed to update translation module: {r_translate.status} (please, use {self.get_prefix()}terminal git checkout -- ., and restart)" await self.client.send_message( chat_id, f"{html_message}\n{translate_message}\n\n⏳ Restarting..." ) self.set("switch1", None) self.set("switch2", chat_id) await self._restart() except Exception as e: print(f"Error updating files: {e}") if chat_id: await self.client.send_message( chat_id, f"⚠️ Error updating files: {e} (please, use {self.get_prefix()}terminal git checkout -- ., and restart)" ) # ΠΎΠΊΠ΅ΠΉ