-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
185 lines (122 loc) · 6 KB
/
main.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
from genericpath import exists, isfile
import json
import os
from pathlib import Path
from pyrogram import Client, filters
from pyrogram.types import Message
from src.cfgs.bot_conf import NAME, HASH, ID, BOT_TK, ZIPS, ALLOWED
from freeapi import Freeapi
from src.modules.aiodl import aio
from src.modules.makezip import compress
from flask import Flask
from threading import Thread
bot: Client = Client(
name=NAME,
api_hash=HASH,
api_id=ID,
bot_token=BOT_TK
)
@bot.on_message(filters.command("start", prefixes="/"))
async def start(client: Client, message: Message):
print("Uso el bot "+client.name)
if message.from_user.id in ALLOWED:
await message.reply("Hola {} bienvenido al bot para subir a pediatria :v".format(message.from_user.first_name))
else:
await message.reply("No tiene autorizacion")
@bot.on_message(filters.command("setnube", prefixes="/"))
async def start(client: Client, message: Message):
print("Uso el bot "+client.name)
if message.from_user.id in ALLOWED:
messagesplite = message.text.split(" ")[-1]
file = open(str(message.from_user.id)+".json","w")
file.write(messagesplite)
file.close()
await message.reply("tu configuracion actual es : " +str(open(str(message.from_user.id)+".json","r").read()))
else:
await message.reply("No tiene autorizacion")
@bot.on_message(filters.regex(".*https://.*") | filters.regex(".*http://.*"))
async def download(client: Client, message: Message):
if message.from_user.id in ALLOWED:
print("Uso el bot "+client.name)
links = message.text.split("\n")
for e in links:
Free_API=""
if(exists(str(message.from_user.id)+".json")):
Free_API = Freeapi(id=str(message.from_user.id))
else:
await message.reply("Configura tu nube con /setnube {'nube':'sunube','username':'nombredeusuario','pass':'contrasena'}")
if(e==None):
continue
msg = await message.reply("Link directo Detectado")
filename = ''
size = 0
try :
filename = await aio(e, msg)
size = Path(filename).stat().st_size
except:
filename = e.split('/')
filename = filename[len(filename)-1]
size = Path(filename).stat().st_size
await msg.edit("Descargado ```{}```\nTamaño: ```{:.2f} MB```".format(filename, size / 1000000))
try:
if size > ZIPS * 1024 * 1024:
comp_msg = await message.reply("El archivo pesa mas de lo esperado, se comprimira")
file_list = compress(filename, part_size=ZIPS)
fin_msg = await comp_msg.edit("Archivo Comprimido en partes de {} MB\n\nAhora subiendo".format(ZIPS))
for files in file_list:
await message.reply("Subiendo "+ files)
link = Free_API.upload_file(files)
with open(filename+".txt", "a") as txt:
txt.write(str(json.dumps({"name":files,"url":link,"username":str(Free_API.returnusername()),"pass":str(Free_API.returnpass())})+"\n"))
os.remove(files)
try:
os.remove(filename)
except:
print("ya no existe")
await message.reply_document(filename+".txt", caption="Archivo de [{}](https://t.me/{})".format(message.from_user.first_name, message.from_user.username))
await fin_msg.delete()
await message.reply("Subido ```{}```".format(filename))
else:
filecompresed = compress(filename,size)
txt = open(filename+".txt","w")
Free_API=""
if(exists(str(message.from_user.id)+".json")):
Free_API = Freeapi(id=str(message.from_user.id))
else:
await message.reply("Configura tu nube con /setnube {'nube':'sunube','username':'nombredeusuario','pass':'contrasena'}")
file_link = Free_API.upload_file(filecompresed[0])
txt.write(json.dumps({"url": file_link, "name":filecompresed[0],"username":str(Free_API.returnusername()),"pass":str(Free_API.returnpass())}))
txt.close()
await message.reply_document(filename+".txt")
await message.reply(str(filecompresed))
await message.reply(file_link)
os.remove(filename+".txt")
try:
os.remove(filename)
except:
print("ya no existe")
os.remove(filecompresed[0])
os.remove(filecompresed[0]+".jpg")
except Exception as e:
await message.reply(e)
# os.remove(filename)
pass
else:
await message.reply("No tiene autorizacion")
if __name__ == "__main__":
# print("Iniciando Bot")
# bot.start()
# print("Bot Iniciado")
# bot.loop.run_forever()
app = Flask(__name__)
@app.route('/')
def index():
return "Alive"
def run():
app.run(host='0.0.0.0', port=10000)
def keep_alive():
t = Thread(target=run)
t.start()
keep_alive()
print("Bot iniciado")
bot.run()