-
Notifications
You must be signed in to change notification settings - Fork 0
/
inlinefm.py
352 lines (327 loc) · 11.1 KB
/
inlinefm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
# By MineisZarox https://t.me/IrisZarox (Demon)
import asyncio
import io
import os
import time
from pathlib import Path
from telethon import Button, types
from telethon.events import CallbackQuery
from telethon.utils import get_attributes
from zthon import zedub
from zthon.Config import Config
from zthon.core.decorators import check_owner
from zthon.helpers import humanbytes, progress
from zthon.helpers.utils import _zedutils
CC = []
PATH = [] # using list method for some reason
thumb_image_path = os.path.join(Config.TMP_DOWNLOAD_DIRECTORY, "thumb_image.jpg")
# freaking selector
def add_s(msg, num: int):
fmsg = ""
msgs = msg.splitlines()
leng = len(msgs)
if num == 0:
valv = leng - 1
msgs[valv] = msgs[valv] + " ⭕️"
for ff in msgs:
fmsg += f"{ff}\n"
elif num == leng:
valv = 1
msgs[valv] = msgs[valv] + " ⭕️"
for ff in msgs:
fmsg += f"{ff}\n"
else:
valv = num
msgs[valv] = msgs[valv] + " ⭕️"
for ff in msgs:
fmsg += f"{ff}\n"
buttons = [
[
Button.inline("D", data=f"fmrem_{msgs[valv]}|{valv}"),
Button.inline("X", data=f"fmcut_{msgs[valv]}|{valv}"),
Button.inline("C", data=f"fmcopy_{msgs[valv]}|{valv}"),
Button.inline("V", data=f"fmpaste_{valv}"),
],
[
Button.inline("⬅️", data="fmback"),
Button.inline("⬆️", data=f"fmup_{valv}"),
Button.inline("⬇️", data=f"fmdown_{valv}"),
Button.inline("➡️", data=f"fmforth_{msgs[valv]}"),
],
]
return fmsg, buttons
def get_manager(path, num: int):
if os.path.isdir(path):
msg = "- المجلدات والملفات في `{}` :\n".format(path)
lists = sorted(os.listdir(path))
files = ""
folders = ""
for contents in sorted(lists):
zpath = os.path.join(path, contents)
if not os.path.isdir(zpath):
size = os.stat(zpath).st_size
if str(contents).endswith((".mp3", ".flac", ".wav", ".m4a")):
files += f"🎧`{contents}`\n"
if str(contents).endswith((".opus")):
files += f"🎤`{contents}`\n"
elif str(contents).endswith(
(".mkv", ".mp4", ".webm", ".avi", ".mov", ".flv")
):
files += f"🎬`{contents}`\n"
elif str(contents).endswith((".zip", ".tar", ".tar.gz", ".rar")):
files += f"📚`{contents}`\n"
elif str(contents).endswith((".py")):
files += f"🐍`{contents}`\n"
elif str(contents).endswith(
(".jpg", ".jpeg", ".png", ".gif", ".bmp", ".ico")
):
files += f"🏞`{contents}`\n"
else:
files += f"📔`{contents}`\n"
else:
folders += f"📂`{contents}`\n"
msg = msg + folders + files if files or folders else f"{msg}__مسار فارغ__"
PATH.clear()
PATH.append(path)
msgs = add_s(msg, int(num))
else:
size = os.stat(path).st_size
msg = "- معلومـات الملـف :\n"
if str(path).endswith((".mp3", ".flac", ".wav", ".m4a")):
mode = "🎧"
if str(path).endswith((".opus")):
mode = "🎤"
elif str(path).endswith((".mkv", ".mp4", ".webm", ".avi", ".mov", ".flv")):
mode = "🎬"
elif str(path).endswith((".zip", ".tar", ".tar.gz", ".rar")):
mode = "📚"
elif str(path).endswith((".jpg", ".jpeg", ".png", ".gif", ".bmp", ".ico")):
mode = "🏞"
elif str(path).endswith((".py")):
mode = "🐍"
else:
mode = "📔"
time.ctime(os.path.getctime(path))
time2 = time.ctime(os.path.getmtime(path))
time3 = time.ctime(os.path.getatime(path))
msg += f"**- المـوقع :** `{path}`\n"
msg += f"**- الايقـونه :** `{mode}`\n"
msg += f"**- الحجـم :** `{humanbytes(size)}`\n"
msg += f"**- آخـر تحـديث للملـف :** `{time2}`\n"
msg += f"**- آخـر وقـت تم الوصـول الى الملـف :** `{time3}`"
buttons = [
[
Button.inline("إعادة تسميه", data=f"fmrem_File|{num}"),
Button.inline("إرسـال", data="fmsend"),
Button.inline("X", data=f"fmcut_File|{num}"),
Button.inline("C", data=f"fmcopy_File{num}"),
],
[
Button.inline("⬅️", data="fmback"),
Button.inline("⬆️", data="fmup_File"),
Button.inline("⬇️", data="fmdown_File"),
Button.inline("➡️", data="fmforth_File"),
],
]
PATH.clear()
PATH.append(path)
msgs = (msg, buttons)
return msgs
# BACK
@zedub.tgbot.on(CallbackQuery(pattern="fmback"))
@check_owner
async def back(event):
path = PATH[0]
paths = path.split("/")
if paths[-1] == "":
paths.pop()
paths.pop()
else:
paths.pop()
npath = ""
for ii in paths:
npath += f"{ii}/"
num = 1
msg, buttons = get_manager(npath, num)
await asyncio.sleep(1)
await event.edit(msg, buttons=buttons)
# UP
@zedub.tgbot.on(CallbackQuery(pattern="fmup_(.*)"))
@check_owner
async def up(event):
num = event.pattern_match.group(1).decode("UTF-8")
if num == "File":
await event.answer("هـذا ملـف ياغبـي ؟!", alert=True)
else:
num1 = int(num) - 1
path = PATH[0]
msg, buttons = get_manager(path, num1)
await asyncio.sleep(1)
await event.edit(msg, buttons=buttons)
# DOWN
@zedub.tgbot.on(CallbackQuery(pattern="fmdown_(.*)"))
@check_owner
async def down(event):
num = event.pattern_match.group(1).decode("UTF-8")
if num == "File":
await event.answer("هـذا ملـف ياغبـي ؟!", alert=True)
else:
path = PATH[0]
num1 = int(num) + 1
msg, buttons = get_manager(path, num1)
await asyncio.sleep(1)
await event.edit(msg, buttons=buttons)
# FORTH
@zedub.tgbot.on(CallbackQuery(pattern="fmforth_(.*)"))
@check_owner
async def forth(event):
npath = event.pattern_match.group(1).decode("UTF-8")
if npath == "File":
await event.answer("هـذا ملـف ياغبـي ؟!", alert=True)
else:
path = PATH[0]
npath = npath[2:-4]
rpath = f"{path}/{npath}"
num = 1
msg, buttons = get_manager(rpath, num)
await asyncio.sleep(1)
await event.edit(msg, buttons=buttons)
# REMOVE
@zedub.tgbot.on(CallbackQuery(pattern="fmrem_(.*)"))
@check_owner
async def remove(event):
fn, num = (event.pattern_match.group(1).decode("UTF-8")).split("|", 1)
path = PATH[0]
if fn == "File":
paths = path.split("/")
if paths[-1] == "":
paths.pop()
paths.pop()
else:
paths.pop()
npath = ""
for ii in paths:
npath += f"{ii}/"
rpath = path
else:
n_path = fn[2:-4]
rpath = f"{path}/{n_path}"
npath = path
msg, buttons = get_manager(npath, num)
await asyncio.sleep(1)
await event.edit(msg, buttons=buttons)
await _zedutils.runcmd(f"rm -rf '{rpath}'")
await event.answer(f"- المسـار {rpath} تم حذفـه .. بنجـاح ✓")
# SEND
@zedub.tgbot.on(CallbackQuery(pattern="fmsend"))
@check_owner
async def send(event):
path = PATH[0]
startTime = time.time()
attributes, mime_type = get_attributes(str(path))
ul = io.open(Path(path), "rb")
uploaded = await event.client.fast_upload_file(
file=ul,
progress_callback=lambda d, t: asyncio.get_event_loop().create_task(
progress(
d,
t,
event,
startTime,
"جـارِ الـرفع",
file_name=os.path.basename(Path(path)),
)
),
)
ul.close()
media = types.InputMediaUploadedDocument(
file=uploaded,
mime_type=mime_type,
attributes=attributes,
force_file=False,
thumb=await event.client.upload_file(thumb_image_path)
if thumb_image_path
else None,
)
await event.edit("hi", file=media)
# CUT
@zedub.tgbot.on(CallbackQuery(pattern="fmcut_(.*)"))
@check_owner
async def cut(event):
f, n = (event.pattern_match.group(1).decode("UTF-8")).split("|", 1)
if CC:
return await event.answer(f"قم بـ لصق {CC[1]} اولا")
else:
if f == "File":
npath = PATH[0]
paths = npath.split("/")
if paths[-1] == "":
paths.pop()
paths.pop()
else:
paths.pop()
path = ""
for ii in paths:
path += f"{ii}/"
CC.append("cut")
CC.append(npath)
await event.answer(f"- جـارِ نقـل المسـار {npath} ...")
else:
path = PATH[0]
npath = f[2:-4]
rpath = f"{path}/{npath}"
CC.append("cut")
CC.append(rpath)
await event.answer(f"- جـارِ نقـل المسـار {rpath} ...")
msg, buttons = get_manager(path, n)
await asyncio.sleep(1)
await event.edit(msg, buttons=buttons)
# COPY
@zedub.tgbot.on(CallbackQuery(pattern="fmcopy_(.*)"))
@check_owner
async def copy(event):
f, n = (event.pattern_match.group(1).decode("UTF-8")).split("|", 1)
if CC:
return await event.answer(f"قم بـ لصق {CC[1]} اولا")
else:
if f == "File":
npath = PATH[0]
paths = npath.split("/")
if paths[-1] == "":
paths.pop()
paths.pop()
else:
paths.pop()
path = ""
for ii in paths:
path += f"{ii}/"
CC.append("copy")
CC.append(npath)
await event.answer(f"- جـارِ نسـخ المسـار {path} ...")
else:
path = PATH[0]
npath = f[2:-4]
rpath = f"{path}/{npath}"
CC.append("copy")
CC.append(rpath)
await event.answer(f"- جـارِ نسـخ المسـار {rpath} ...")
msg, buttons = get_manager(path, n)
await asyncio.sleep(1)
await event.edit(msg, buttons=buttons)
# PASTE
@zedub.tgbot.on(CallbackQuery(pattern="fmpaste_(.*)"))
@check_owner
async def paste(event):
n = event.pattern_match.group(1).decode("UTF-8")
path = PATH[0]
if CC:
if CC[0] == "cut":
cmd = f"mv '{CC[1]}' '{path}'"
else:
cmd = f"cp '{CC[1]}' '{path}'"
await _zedutils.runcmd(cmd)
msg, buttons = get_manager(path, n)
await event.edit(msg, buttons=buttons)
CC.clear
else:
await event.answer("انت لم تقم بنسخ اي شي لعمل له لصق ؟!")