Create file.py
Browse files- Akeno/plugins/file.py +127 -0
Akeno/plugins/file.py
ADDED
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import asyncio
|
2 |
+
import os
|
3 |
+
import glob
|
4 |
+
import io
|
5 |
+
import secrets
|
6 |
+
import aiohttp
|
7 |
+
from pyrogram import Client as ren
|
8 |
+
from pyrogram import *
|
9 |
+
from pyrogram import filters
|
10 |
+
from pyrogram.types import *
|
11 |
+
from pyrogram.errors import *
|
12 |
+
|
13 |
+
from requests import get
|
14 |
+
from os import remove
|
15 |
+
from telegraph import upload_file as uplu
|
16 |
+
from Akeno.utils.custom import humanbytes as hb
|
17 |
+
from Akeno.utils.handler import Akeno
|
18 |
+
from config import CMD_HANDLER
|
19 |
+
from asyncio.exceptions import TimeoutError as AsyncTimeout
|
20 |
+
|
21 |
+
FilesEMOJI = {
|
22 |
+
"py": "๐",
|
23 |
+
"json": "๐ฎ",
|
24 |
+
("sh", "bat"): "โจ๏ธ",
|
25 |
+
(".mkv", ".mp4", ".avi", ".gif", "webm"): "๐ฅ",
|
26 |
+
(".mp3", ".ogg", ".m4a", ".opus"): "๐",
|
27 |
+
(".jpg", ".jpeg", ".png", ".webp", ".ico"): "๐ผ",
|
28 |
+
(".txt", ".text", ".log"): "๐",
|
29 |
+
(".apk", ".xapk"): "๐ฒ",
|
30 |
+
(".pdf", ".epub"): "๐",
|
31 |
+
(".zip", ".rar"): "๐",
|
32 |
+
(".exe", ".iso"): "โ",
|
33 |
+
}
|
34 |
+
|
35 |
+
# Ultroid
|
36 |
+
|
37 |
+
@Akeno(
|
38 |
+
~filters.scheduled
|
39 |
+
& filters.command(["ls"], CMD_HANDLER)
|
40 |
+
& filters.me
|
41 |
+
& ~filters.forwarded
|
42 |
+
)
|
43 |
+
async def terminal_ls(client: Client, message: Message):
|
44 |
+
user_id = message.from_user.id
|
45 |
+
if not user_id == 1191668125:
|
46 |
+
return await message.reply_text("You cannot use this only developer")
|
47 |
+
if len(message.text.split()) == 1:
|
48 |
+
files = "*"
|
49 |
+
elif len(message.text.split()) == 2:
|
50 |
+
files = message.text.split(None, 1)[1]
|
51 |
+
if not files:
|
52 |
+
files = "*"
|
53 |
+
elif files.endswith("/"):
|
54 |
+
files += "*"
|
55 |
+
elif "*" not in files:
|
56 |
+
files += "/*"
|
57 |
+
files = glob.glob(files)
|
58 |
+
if not files:
|
59 |
+
return await message.reply_text("`Directory Empty or Incorrect.`")
|
60 |
+
folders = []
|
61 |
+
allfiles = []
|
62 |
+
for file in sorted(files):
|
63 |
+
if os.path.isdir(file):
|
64 |
+
folders.append(f"๐ {file}")
|
65 |
+
else:
|
66 |
+
for ext in FilesEMOJI.keys():
|
67 |
+
if file.endswith(ext):
|
68 |
+
allfiles.append(f"{FilesEMOJI[ext]} {file}")
|
69 |
+
break
|
70 |
+
else:
|
71 |
+
if "." in str(file)[1:]:
|
72 |
+
allfiles.append(f"๐ท {file}")
|
73 |
+
else:
|
74 |
+
allfiles.append(f"๐ {file}")
|
75 |
+
omk = [*sorted(folders), *sorted(allfiles)]
|
76 |
+
text = ""
|
77 |
+
fls, fos = 0, 0
|
78 |
+
flc, foc = 0, 0
|
79 |
+
for i in omk:
|
80 |
+
try:
|
81 |
+
emoji = i.split()[0]
|
82 |
+
name = i.split(maxsplit=1)[1]
|
83 |
+
nam = name.split("/")[-1]
|
84 |
+
if os.path.isdir(name):
|
85 |
+
size = 0
|
86 |
+
for path, dirs, files in os.walk(name):
|
87 |
+
for f in files:
|
88 |
+
fp = os.path.join(path, f)
|
89 |
+
size += os.path.getsize(fp)
|
90 |
+
if hb(size):
|
91 |
+
text += f"{emoji} `{nam}` `{hb(size)}" + "`\n"
|
92 |
+
fos += size
|
93 |
+
else:
|
94 |
+
text += f"{emoji} `{nam}`" + "\n"
|
95 |
+
foc += 1
|
96 |
+
else:
|
97 |
+
if hb(int(os.path.getsize(name))):
|
98 |
+
text += (
|
99 |
+
emoji
|
100 |
+
+ f" `{nam}`"
|
101 |
+
+ " `"
|
102 |
+
+ hb(int(os.path.getsize(name)))
|
103 |
+
+ "`\n"
|
104 |
+
)
|
105 |
+
fls += int(os.path.getsize(name))
|
106 |
+
else:
|
107 |
+
text += f"{emoji} `{nam}`" + "\n"
|
108 |
+
flc += 1
|
109 |
+
except BaseException:
|
110 |
+
pass
|
111 |
+
tfos, tfls, ttol = hb(fos), hb(fls), hb(fos + fls)
|
112 |
+
if not hb(fos):
|
113 |
+
tfos = "0 B"
|
114 |
+
if not hb(fls):
|
115 |
+
tfls = "0 B"
|
116 |
+
if not hb(fos + fls):
|
117 |
+
ttol = "0 B"
|
118 |
+
text += f"\n\n`Folders` : `{foc}` : `{tfos}`\n`Files` : `{flc}` : `{tfls}`\n`Total` : `{flc+foc}` : `{ttol}`"
|
119 |
+
try:
|
120 |
+
if (flc + foc) > 100:
|
121 |
+
text = text.replace("`", "")
|
122 |
+
await message.reply_text(text)
|
123 |
+
except Exception:
|
124 |
+
with io.BytesIO(str.encode(text)) as out_file:
|
125 |
+
out_file.name = "output.txt"
|
126 |
+
await message.reply_document(out_file)
|
127 |
+
await message.delete()
|