forked from TeamUltroid/Ultroid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uploads_files.py
175 lines (157 loc) · 4.9 KB
/
uploads_files.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
# Ultroid - UserBot
# Copyright (C) 2020 TeamUltroid
#
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
# PLease read the GNU Affero General Public License in
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
"""
✘ Commands Available -
• `{i}ul <path/to/file>`
Upload file to telegram chat.
• `{i}dl <filename(optional)>`
Reply to file to download.
• `{i}save <filename.ext>`
Reply to a text msg to save it in a file.
• `{i}open`
Reply to a file to reveal it's text.
"""
import asyncio
import os
import time
from datetime import datetime as dt
from . import *
opn = []
@ultroid_cmd(
pattern="dl ?(.*)",
)
async def download(event):
xx = await eor(event, "`Processing...`")
kk = event.pattern_match.group(1)
s = dt.now()
k = time.time()
if event.reply_to_msg_id:
ok = await event.get_reply_message()
if not ok.media:
return await eod(xx, "`Reply The File/Media u Want to Download..`", time=5)
else:
if not kk:
d = "resources/downloads/"
o = await event.client.download_media(
ok,
d,
progress_callback=lambda d, t: asyncio.get_event_loop().create_task(
progress(
d,
t,
xx,
k,
"Downloading...",
)
),
)
else:
d = f"resources/downloads/{kk}"
o = await event.client.download_media(
ok,
d,
progress_callback=lambda d, t: asyncio.get_event_loop().create_task(
progress(
d,
t,
xx,
k,
"Downloading...",
file_name=d,
)
),
)
e = datetime.now()
t = convert((e - s).seconds)
await eod(xx, f"Download Successful..\nTo\n`{o}`\nin `{t}`")
@ultroid_cmd(
pattern="ul ?(.*)",
)
async def download(event):
xx = await eor(event, "`Processing...`")
kk = event.pattern_match.group(1)
s = dt.now()
tt = time.time()
if not kk:
return await eod(xx, "`Give a specific path to file`")
else:
try:
x = await event.client.send_file(
event.chat_id,
kk,
caption=kk,
progress_callback=lambda d, t: asyncio.get_event_loop().create_task(
progress(
d,
t,
xx,
tt,
"Uploading...",
file_name=kk,
)
),
)
except ValueError as ve:
return await eod(xx, str(ve))
e = datetime.now()
t = convert((e - s).seconds)
try:
await x.edit(f"`{kk}`\nTime Taken: `{t}`")
except BaseException:
pass
await eod(xx, f"Uploaded `{kk}` in `{t}`", time=5)
@ultroid_cmd(
pattern="save",
)
async def _(event):
input_str = event.text[6:]
xx = await eor(event, "`Processing...`")
if event.reply_to_msg_id:
a = await event.get_reply_message()
if not a.message:
return await xx.edit("`Reply to a message`")
else:
b = open(input_str, "w")
b.write(str(a.message))
b.close()
await xx.edit(f"**Packing into** `{input_str}`")
await asyncio.sleep(2)
await xx.edit(f"**Uploading** `{input_str}`")
await asyncio.sleep(2)
await event.client.send_file(event.chat_id, input_str)
await xx.delete()
os.remove(input_str)
@ultroid_cmd(
pattern="open$",
)
async def _(event):
xx = await eor(event, "`Processing...`")
if event.reply_to_msg_id:
a = await event.get_reply_message()
if a.media:
b = await a.download_media()
c = open(b, "r")
d = c.read()
c.close()
n = 4096
for bkl in range(0, len(d), n):
opn.append(d[bkl : bkl + n])
for bc in opn:
await event.client.send_message(
event.chat_id,
f"```{bc}```",
reply_to=event.reply_to_msg_id,
)
await event.delete()
opn.clear()
os.remove(b)
await xx.delete()
else:
return await eod(xx, "`Reply to a readable file`", time=10)
else:
return await eod(xx, "`Reply to a readable file`", time=10)
HELP.update({f"{__name__.split('.')[1]}": f"{__doc__.format(i=HNDLR)}"})