diff --git a/modules/filters.py b/modules/filters.py index 4ccaa6d..ffeba81 100644 --- a/modules/filters.py +++ b/modules/filters.py @@ -201,7 +201,7 @@ async def filters_handler(_, message: Message): try: text = "" for index, a in enumerate(get_filters_chat(message.chat.id).items(), start=1): - key, item = a + key, _ = a key = key.replace("<", "").replace(">", "") text += f"{index}. {key}\n" text = f"Your filters in current chat:\n\n" f"{text}" diff --git a/modules/open.py b/modules/open.py index c5760ac..4a2fe70 100644 --- a/modules/open.py +++ b/modules/open.py @@ -20,7 +20,7 @@ import time import aiofiles -from pyrogram import Client, enums, filters +from pyrogram import Client, filters from pyrogram.errors import MessageTooLong from pyrogram.types import Message @@ -35,58 +35,37 @@ async def read_file(file_path): def check_extension(file_path): - if file_path.lower().endswith(".txt"): - code_start = "```txt" - elif file_path.lower().endswith(".py"): - code_start = "```py" - elif file_path.lower().endswith(".js"): - code_start = "```js" - elif file_path.lower().endswith(".json"): - code_start = "```json" - elif file_path.lower().endswith(".smali"): - code_start = "```smali" - elif file_path.lower().endswith(".sh"): - code_start = "```bash" - elif file_path.lower().endswith(".c"): - code_start = "```C" - elif file_path.lower().endswith(".java"): - code_start = "```java" - elif file_path.lower().endswith(".php"): - code_start = "```php" - elif file_path.lower().endswith(".doc"): - code_start = "```doc" - elif file_path.lower().endswith(".docx"): - code_start = "```docx" - elif file_path.lower().endswith(".rtf"): - code_start = "```rtf" - elif file_path.lower().endswith(".s"): - code_start = "```asm" - elif file_path.lower().endswith(".dart"): - code_start = "```dart" - elif file_path.lower().endswith(".cfg"): - code_start = "```cfg" - elif file_path.lower().endswith(".swift"): - code_start = "```swift" - elif file_path.lower().endswith(".cs"): - code_start = "```C#" - elif file_path.lower().endswith(".vb"): - code_start = "```vb" - elif file_path.lower().endswith(".css"): - code_start = "```css" - elif file_path.lower().endswith(".htm") or file_path.lower().endswith(".html"): - code_start = "```html" - elif file_path.lower().endswith(".rss"): - code_start = "```rss" - elif file_path.lower().endswith(".swift"): - code_start = "```swift" - elif file_path.lower().endswith(".xhtml"): - code_start = "```xhtml" - elif file_path.lower().endswith(".cpp"): - code_start = "```cpp" - else: - code_start = "```" - - return code_start + extensions = { + ".txt": "
",
+        ".py": "
",
+        ".js": "
",
+        ".json": "
",
+        ".smali": "
",
+        ".sh": "
",
+        ".c": "
",
+        ".java": "
",
+        ".php": "
",
+        ".doc": "
",
+        ".docx": "
",
+        ".rtf": "
",
+        ".s": "
",
+        ".dart": "
",
+        ".cfg": "
",
+        ".swift": "
",
+        ".cs": "
",
+        ".vb": "
",
+        ".css": "
",
+        ".htm": "
",
+        ".html": "
",
+        ".rss": "
",
+        ".xhtml": "
",
+        ".cpp": "
",
+    }
+
+    ext = os.path.splitext(file_path)[1].lower()
+
+    return extensions.get(ext, "
")
+
 
 
 @Client.on_message(filters.command("open", prefix) & filters.me)
@@ -95,7 +74,7 @@ async def openfile(client: Client, message: Message):
         return await message.edit_text("Kindly Reply to a File")
 
     try:
-        ms = await edit_or_reply(message, "`Downloading...")
+        ms = await edit_or_reply(message, "Downloading...")
         ct = time.time()
         file_path = await message.reply_to_message.download(
             progress=progress, progress_args=(ms, ct, "Downloading...")
@@ -108,18 +87,16 @@ async def openfile(client: Client, message: Message):
             "%Y-%m-%d %H:%M:%S"
         )
         code_start = check_extension(file_path=file_path)
-        code_end = "```"
         content = await read_file(file_path=file_path)
         await ms.edit_text(
-            f"**File Name:** `{file_name[0]}`\n**Size:** `{file_size} bytes`\n**Last Modified:** `{last_modified}`\n**Content:** {code_start}\n{content}{code_end}",
-            parse_mode=enums.ParseMode.MARKDOWN,
+            f"File Name: {file_name[0]}\nSize: {file_size} bytes\nLast Modified: {last_modified}\nContent: {code_start}{content}
", ) except MessageTooLong: await ms.edit_text( "File Content is too long... Pasting to rentry..." ) - content_new = f"{code_start}\n{content}{code_end}" + content_new = f"```{code_start[11:-2]}\n{content}```" paste = subprocess.run( ["rentry", "new", content_new], capture_output=True, text=True, check=True ) @@ -130,8 +107,7 @@ async def openfile(client: Client, message: Message): if parts[0].strip() == "Url:": url = "".join(parts[1:]).split()[0] await ms.edit_text( - f"**File Name:** `{file_name[0]}`\n**Size:** `{file_size} bytes`\n**Last Modified:** `{last_modified}`\n**Content:** {url}\n**Note:** `Edit Code has been sent to your saved messages`", - parse_mode=enums.ParseMode.MARKDOWN, + f"File Name: {file_name[0]}\nSize: {file_size} bytes\nLast Modified: {last_modified}\nContent: {url}\nNote: Edit Code has been sent to your saved messages", disable_web_page_preview=True, ) break