Spaces:
Build error
Build error
Commit
·
0bc42a9
1
Parent(s):
989d7ce
Upload 7 files
Browse files- unzipper/database/__init__.py +17 -0
- unzipper/database/cloud.py +41 -0
- unzipper/database/language.py +40 -0
- unzipper/database/split_arc.py +39 -0
- unzipper/database/thumbnail.py +75 -0
- unzipper/database/upload_mode.py +31 -0
- unzipper/database/users.py +67 -0
unzipper/database/__init__.py
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# ===================================================================== #
|
2 |
+
# Copyright (c) 2022 Itz-fork #
|
3 |
+
# #
|
4 |
+
# This program is distributed in the hope that it will be useful, #
|
5 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
6 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. #
|
7 |
+
# See the GNU General Public License for more details. #
|
8 |
+
# #
|
9 |
+
# You should have received a copy of the GNU General Public License #
|
10 |
+
# along with this program. If not, see <http://www.gnu.org/licenses/> #
|
11 |
+
# ===================================================================== #
|
12 |
+
|
13 |
+
from config import Config
|
14 |
+
from motor.motor_asyncio import AsyncIOMotorClient
|
15 |
+
|
16 |
+
mongodb = AsyncIOMotorClient(Config.MONGODB_URL)
|
17 |
+
unzipper_db = mongodb["Unzipper_Bot"]
|
unzipper/database/cloud.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# ===================================================================== #
|
2 |
+
# Copyright (c) 2022 Itz-fork #
|
3 |
+
# #
|
4 |
+
# This program is distributed in the hope that it will be useful, #
|
5 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
6 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. #
|
7 |
+
# See the GNU General Public License for more details. #
|
8 |
+
# #
|
9 |
+
# You should have received a copy of the GNU General Public License #
|
10 |
+
# along with this program. If not, see <http://www.gnu.org/licenses/> #
|
11 |
+
# ===================================================================== #
|
12 |
+
|
13 |
+
from . import unzipper_db
|
14 |
+
|
15 |
+
|
16 |
+
# Gofile.io
|
17 |
+
class GofileDB:
|
18 |
+
def __init__(self, id: int) -> None:
|
19 |
+
self.id = id
|
20 |
+
self.db = unzipper_db["gofile_db"]
|
21 |
+
|
22 |
+
async def save_token(self, gtoken: str):
|
23 |
+
is_exist = await self.db.find_one({"_id": self.id})
|
24 |
+
if is_exist:
|
25 |
+
await self.db.update_one({"_id": self.id}, {"$set": {"token": gtoken}})
|
26 |
+
else:
|
27 |
+
await self.db.insert_one({"_id": self.id, "token": gtoken})
|
28 |
+
|
29 |
+
async def get_token(self):
|
30 |
+
gtkn = await self.db.find_one({"_id": self.id})
|
31 |
+
if gtkn:
|
32 |
+
return gtkn["token"]
|
33 |
+
else:
|
34 |
+
return None
|
35 |
+
|
36 |
+
async def del_token(self):
|
37 |
+
is_exist = await self.db.find_one({"_id": self.id})
|
38 |
+
if is_exist:
|
39 |
+
await self.db.delete_one({"_id": self.id})
|
40 |
+
else:
|
41 |
+
return
|
unzipper/database/language.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# ===================================================================== #
|
2 |
+
# Copyright (c) 2022 Itz-fork #
|
3 |
+
# #
|
4 |
+
# This program is distributed in the hope that it will be useful, #
|
5 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
6 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. #
|
7 |
+
# See the GNU General Public License for more details. #
|
8 |
+
# #
|
9 |
+
# You should have received a copy of the GNU General Public License #
|
10 |
+
# along with this program. If not, see <http://www.gnu.org/licenses/> #
|
11 |
+
# ===================================================================== #
|
12 |
+
|
13 |
+
from . import unzipper_db
|
14 |
+
from unzipper.client.caching import USER_LANG
|
15 |
+
|
16 |
+
|
17 |
+
lang_db = unzipper_db["languages_db"]
|
18 |
+
|
19 |
+
|
20 |
+
async def set_language(user_id: int, lang: str):
|
21 |
+
exists = await lang_db.find_one({"_id": user_id})
|
22 |
+
if exists:
|
23 |
+
await lang_db.update_one({"_id": user_id}, {"$set": {"lang": lang}})
|
24 |
+
else:
|
25 |
+
await lang_db.insert_one({"_id": user_id, "lang": lang})
|
26 |
+
|
27 |
+
|
28 |
+
async def get_language(user_id: int):
|
29 |
+
try:
|
30 |
+
return USER_LANG[user_id]
|
31 |
+
except:
|
32 |
+
exists = await lang_db.find_one({"_id": user_id})
|
33 |
+
if exists:
|
34 |
+
return exists["lang"]
|
35 |
+
else:
|
36 |
+
return "en"
|
37 |
+
|
38 |
+
|
39 |
+
async def get_user_languages():
|
40 |
+
return lang_db.find({})
|
unzipper/database/split_arc.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# ===================================================================== #
|
2 |
+
# Copyright (c) 2022 Itz-fork #
|
3 |
+
# #
|
4 |
+
# This program is distributed in the hope that it will be useful, #
|
5 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
6 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. #
|
7 |
+
# See the GNU General Public License for more details. #
|
8 |
+
# #
|
9 |
+
# You should have received a copy of the GNU General Public License #
|
10 |
+
# along with this program. If not, see <http://www.gnu.org/licenses/> #
|
11 |
+
# ===================================================================== #
|
12 |
+
|
13 |
+
from . import unzipper_db
|
14 |
+
|
15 |
+
spl_db = unzipper_db["splitted_archive_users"]
|
16 |
+
|
17 |
+
|
18 |
+
async def add_split_arc_user(uid: int, fn: str, passw: str):
|
19 |
+
is_exist = await spl_db.find_one({"_id": uid})
|
20 |
+
if not is_exist:
|
21 |
+
await spl_db.insert_one({"_id": uid, "file_name": fn, "password": passw})
|
22 |
+
else:
|
23 |
+
raise ValueError("Data already exists!")
|
24 |
+
|
25 |
+
|
26 |
+
async def get_split_arc_user(uid: int):
|
27 |
+
gsau = await spl_db.find_one({"_id": uid})
|
28 |
+
if gsau:
|
29 |
+
return True, gsau["file_name"], gsau["password"]
|
30 |
+
else:
|
31 |
+
return False, None, None
|
32 |
+
|
33 |
+
|
34 |
+
async def del_split_arc_user(uid: int):
|
35 |
+
is_exist = await spl_db.find_one({"_id": uid})
|
36 |
+
if is_exist:
|
37 |
+
await spl_db.delete_one({"_id": uid})
|
38 |
+
else:
|
39 |
+
return
|
unzipper/database/thumbnail.py
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# ===================================================================== #
|
2 |
+
# Copyright (c) 2022 Itz-fork #
|
3 |
+
# #
|
4 |
+
# This program is distributed in the hope that it will be useful, #
|
5 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
6 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. #
|
7 |
+
# See the GNU General Public License for more details. #
|
8 |
+
# #
|
9 |
+
# You should have received a copy of the GNU General Public License #
|
10 |
+
# along with this program. If not, see <http://www.gnu.org/licenses/> #
|
11 |
+
# ===================================================================== #
|
12 |
+
|
13 |
+
from os import path
|
14 |
+
from PIL import Image
|
15 |
+
from . import unzipper_db
|
16 |
+
from requests import post
|
17 |
+
from pyrogram.types import Message
|
18 |
+
from unzipper.lib.downloader import Downloader
|
19 |
+
from unzipper.helpers_nexa.utils import run_cmds_on_cr
|
20 |
+
|
21 |
+
|
22 |
+
thumb_db = unzipper_db["thumbnails_db"]
|
23 |
+
|
24 |
+
|
25 |
+
def upload_thumbnail(img: str):
|
26 |
+
with open(img, "rb") as file:
|
27 |
+
rs = post(
|
28 |
+
"https://telegra.ph/upload",
|
29 |
+
files={"file": file}
|
30 |
+
).json()[0]
|
31 |
+
return f"https://telegra.ph{rs['src']}"
|
32 |
+
|
33 |
+
|
34 |
+
def prepare_thumb(ipath):
|
35 |
+
tpath = f"{path.splitext(ipath)[0]}.thumb.jpg"
|
36 |
+
with Image.open(ipath) as im:
|
37 |
+
rim = im.convert("RGB")
|
38 |
+
rim.thumbnail((320, 320))
|
39 |
+
rim.save(tpath, "JPEG")
|
40 |
+
return tpath
|
41 |
+
|
42 |
+
|
43 |
+
async def save_thumbnail(uid: int, message: Message):
|
44 |
+
# Download the image
|
45 |
+
ip = await message.download()
|
46 |
+
thumb = await run_cmds_on_cr(prepare_thumb, ip)
|
47 |
+
up_thumb = await run_cmds_on_cr(upload_thumbnail, thumb)
|
48 |
+
is_exist = await thumb_db.find_one({"_id": uid})
|
49 |
+
if is_exist:
|
50 |
+
await thumb_db.update_one({"_id": uid}, {"$set": {"url": up_thumb}})
|
51 |
+
else:
|
52 |
+
await thumb_db.insert_one({"_id": uid, "url": up_thumb})
|
53 |
+
|
54 |
+
|
55 |
+
async def get_thumbnail(user_id: int, download: bool = False):
|
56 |
+
gtm = await thumb_db.find_one({"_id": user_id})
|
57 |
+
if gtm:
|
58 |
+
if download:
|
59 |
+
dimg = f"Dump/thumbnail_{path.basename(gtm['url'])}"
|
60 |
+
await Downloader().download(gtm["url"], dimg, cont_type="image/")
|
61 |
+
return dimg
|
62 |
+
return gtm["url"]
|
63 |
+
else:
|
64 |
+
return None
|
65 |
+
|
66 |
+
|
67 |
+
async def del_thumbnail(user_id: int):
|
68 |
+
is_exist = await thumb_db.find_one({"_id": user_id})
|
69 |
+
if is_exist:
|
70 |
+
await thumb_db.delete_one({"_id": user_id})
|
71 |
+
else:
|
72 |
+
return
|
73 |
+
|
74 |
+
|
75 |
+
|
unzipper/database/upload_mode.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# ===================================================================== #
|
2 |
+
# Copyright (c) 2022 Itz-fork #
|
3 |
+
# #
|
4 |
+
# This program is distributed in the hope that it will be useful, #
|
5 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
6 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. #
|
7 |
+
# See the GNU General Public License for more details. #
|
8 |
+
# #
|
9 |
+
# You should have received a copy of the GNU General Public License #
|
10 |
+
# along with this program. If not, see <http://www.gnu.org/licenses/> #
|
11 |
+
# ===================================================================== #
|
12 |
+
|
13 |
+
from . import unzipper_db
|
14 |
+
|
15 |
+
mode_db = unzipper_db["upload_mode_db"]
|
16 |
+
|
17 |
+
|
18 |
+
async def set_upload_mode(user_id, mode):
|
19 |
+
is_exist = await mode_db.find_one({"_id": user_id})
|
20 |
+
if is_exist:
|
21 |
+
await mode_db.update_one({"_id": user_id}, {"$set": {"mode": mode}})
|
22 |
+
else:
|
23 |
+
await mode_db.insert_one({"_id": user_id, "mode": mode})
|
24 |
+
|
25 |
+
|
26 |
+
async def get_upload_mode(user_id):
|
27 |
+
umode = await mode_db.find_one({"_id": user_id})
|
28 |
+
if umode:
|
29 |
+
return umode["mode"]
|
30 |
+
else:
|
31 |
+
return "doc"
|
unzipper/database/users.py
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# ===================================================================== #
|
2 |
+
# Copyright (c) 2022 Itz-fork #
|
3 |
+
# #
|
4 |
+
# This program is distributed in the hope that it will be useful, #
|
5 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
6 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. #
|
7 |
+
# See the GNU General Public License for more details. #
|
8 |
+
# #
|
9 |
+
# You should have received a copy of the GNU General Public License #
|
10 |
+
# along with this program. If not, see <http://www.gnu.org/licenses/> #
|
11 |
+
# ===================================================================== #
|
12 |
+
|
13 |
+
from . import unzipper_db
|
14 |
+
|
15 |
+
|
16 |
+
# Main users database
|
17 |
+
user_db = unzipper_db["users_db"]
|
18 |
+
|
19 |
+
|
20 |
+
async def add_user(user_id: int):
|
21 |
+
is_exist = await user_db.find_one({"user_id": user_id})
|
22 |
+
if not is_exist:
|
23 |
+
await user_db.insert_one({"user_id": user_id})
|
24 |
+
|
25 |
+
|
26 |
+
async def del_user(user_id: int):
|
27 |
+
is_exist = await user_db.find_one({"user_id": user_id})
|
28 |
+
if is_exist:
|
29 |
+
await user_db.delete_one({"user_id": user_id})
|
30 |
+
|
31 |
+
|
32 |
+
async def is_user_in_db(user_id: int):
|
33 |
+
is_exist = await user_db.find_one({"user_id": user_id})
|
34 |
+
return True if is_exist else False
|
35 |
+
|
36 |
+
|
37 |
+
async def count_users():
|
38 |
+
return await user_db.count_documents({})
|
39 |
+
|
40 |
+
|
41 |
+
async def get_users_list():
|
42 |
+
return (user["user_id"] async for user in user_db.find({}))
|
43 |
+
|
44 |
+
|
45 |
+
# Banned users database (I don't know why tf i added this, but who cares)
|
46 |
+
b_user_db = unzipper_db["banned_users_db"]
|
47 |
+
|
48 |
+
|
49 |
+
async def add_banned_user(user_id: int):
|
50 |
+
is_exist = await b_user_db.find_one({"banned_user_id": user_id})
|
51 |
+
if not is_exist:
|
52 |
+
await b_user_db.insert_one({"banned_user_id": user_id})
|
53 |
+
|
54 |
+
|
55 |
+
async def del_banned_user(user_id: int):
|
56 |
+
is_exist = await b_user_db.find_one({"banned_user_id": user_id})
|
57 |
+
if is_exist:
|
58 |
+
await b_user_db.delete_one({"banned_user_id": user_id})
|
59 |
+
|
60 |
+
|
61 |
+
async def is_user_in_bdb(user_id: int):
|
62 |
+
is_exist = await b_user_db.find_one({"banned_user_id": user_id})
|
63 |
+
return True if is_exist else False
|
64 |
+
|
65 |
+
|
66 |
+
async def count_banned_users():
|
67 |
+
return await b_user_db.count_documents({})
|