imseldrith commited on
Commit
071487b
·
1 Parent(s): 75c57b1

Upload 6 files

Browse files
unzipper/modules/__init__.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
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
+ # ===================================================================== #
unzipper/modules/admin.py ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 asyncio import sleep
14
+ from shutil import disk_usage as sdisk_usage
15
+
16
+ from config import Config
17
+ from pyrogram import filters
18
+ from unzipper import unzip_client
19
+ from pyrogram.types import Message
20
+
21
+ from pyrogram.errors import FloodWait
22
+ from unzipper.helpers_nexa.utils import humanbytes
23
+
24
+ from unzipper.database.users import (add_banned_user, count_banned_users,
25
+ count_users, del_banned_user, del_user,
26
+ get_users_list)
27
+ from psutil import cpu_percent, disk_usage, net_io_counters, virtual_memory
28
+
29
+
30
+ @unzip_client.on_message(filters.private & filters.command("stats"))
31
+ @unzip_client.handle_erros
32
+ async def send_stats(_, message: Message, texts):
33
+ stats_msg = await message.reply(texts["processing"])
34
+ # Is message from owner?
35
+ frmow = False
36
+ if message.from_user and message.from_user.id == Config.BOT_OWNER:
37
+ frmow = True
38
+ # Disk usage
39
+ total, used, free = sdisk_usage(".")
40
+ total = humanbytes(total)
41
+ used = humanbytes(used)
42
+ free = humanbytes(free)
43
+ # Hardware usage
44
+ cpu_usage = cpu_percent()
45
+ ram_usage = virtual_memory().percent
46
+ cdisk_usage = disk_usage('/').percent
47
+ # Bandwith usage
48
+ net_usage = net_io_counters()
49
+ # Users count
50
+ total_users = await count_users()
51
+ total_banned_users = await count_banned_users()
52
+ usrtxt = f"""
53
+ **👥 Users:**
54
+ ↳**Users in Database:** `{total_users}`
55
+ ↳**Total Banned Users:** `{total_banned_users}`
56
+
57
+ """
58
+ # Show status
59
+ await stats_msg.edit(f"""
60
+ **💫 Current Bot Stats 💫**
61
+ {usrtxt if frmow else ""}
62
+ **🌐 Bandwith Usage,**
63
+ ↳ **Sent:** `{humanbytes(net_usage.bytes_sent)}`
64
+ ↳ **Received:** `{humanbytes(net_usage.bytes_recv)}`
65
+
66
+
67
+ **💾 Disk Usage,**
68
+ ↳**Total Disk Space:** `{total}`
69
+ ↳**Used:** `{used}({cdisk_usage}%)`
70
+ ↳**Free:** `{free}`
71
+
72
+
73
+ **🎛 Hardware Usage,**
74
+ ↳**CPU Usage:** `{cpu_usage}%`
75
+ ↳**RAM Usage:** `{ram_usage}%`""")
76
+
77
+
78
+ async def _do_broadcast(message, user):
79
+ try:
80
+ await message.copy(chat_id=int(user))
81
+ return 200
82
+ except FloodWait as e:
83
+ await sleep(e.x)
84
+ return _do_broadcast(message, user)
85
+ except Exception:
86
+ await del_user(int(user))
87
+
88
+
89
+ @unzip_client.on_message(filters.private & filters.command("broadcast") & filters.user(Config.BOT_OWNER))
90
+ @unzip_client.handle_erros
91
+ async def broadcast_dis(_, message: Message, texts):
92
+ bc_msg = await message.reply(texts["processing"])
93
+ r_msg = message.reply_to_message
94
+ if not r_msg:
95
+ return await bc_msg.edit(texts["no_replied_msg"])
96
+ # Starting the broadcast
97
+ await bc_msg.edit(texts["broadcast_started"])
98
+ success_no = 0
99
+ failed_no = 0
100
+ total_users = await count_users()
101
+ async for user in await get_users_list():
102
+ b_cast = await _do_broadcast(r_msg, user)
103
+ if b_cast == 200:
104
+ success_no += 1
105
+ else:
106
+ failed_no += 1
107
+ await bc_msg.edit((texts["boradcast_results"]).format(total_users, success_no, failed_no))
108
+
109
+
110
+ @unzip_client.on_message(filters.private & filters.command("ban") & filters.user(Config.BOT_OWNER))
111
+ @unzip_client.handle_erros
112
+ async def ban_user(_, message: Message, texts):
113
+ ban_msg = await message.reply(texts["processing"])
114
+ try:
115
+ user_id = message.text.split(None, 1)[1]
116
+ except:
117
+ return await ban_msg.edit(texts["no_userid"])
118
+ # Return if user_id string is not numeric
119
+ if not user_id.isnumeric():
120
+ return await ban_msg.edit(texts["no_userid"])
121
+ await add_banned_user(int(user_id))
122
+ await ban_msg.edit(texts["ok_ban"].format(user_id))
123
+
124
+
125
+ @unzip_client.on_message(filters.private & filters.command("unban") & filters.user(Config.BOT_OWNER))
126
+ @unzip_client.handle_erros
127
+ async def unban_user(_, message: Message, texts):
128
+ unban_msg = await message.reply(texts["processing"])
129
+ try:
130
+ user_id = message.text.split(None, 1)[1]
131
+ except:
132
+ return await unban_msg.edit(texts["no_userid"])
133
+ # Return if user_id string is not numeric
134
+ if not user_id.isnumeric():
135
+ return await unban_msg.edit(texts["no_userid"])
136
+ await del_banned_user(int(user_id))
137
+ await unban_msg.edit(texts["ok_unban"].format(user_id))
unzipper/modules/callbacks.py ADDED
@@ -0,0 +1,249 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ import logging
14
+
15
+ from time import time
16
+ from shutil import rmtree
17
+ from os import makedirs, path
18
+
19
+ from config import Config
20
+ from aiohttp import ClientSession
21
+ from unzipper import unzip_client, Buttons
22
+ from unzipper.client.caching import USER_LANG
23
+
24
+ from pyrogram.types import CallbackQuery
25
+ from unzipper.database.cloud import GofileDB
26
+ from pyrogram.errors import ReplyMarkupTooLong
27
+ from unzipper.database.language import set_language
28
+ from unzipper.database.upload_mode import set_upload_mode
29
+
30
+ from unzipper.helpers_nexa.utils import (TimeFormatter, get_files, humanbytes,
31
+ progress_for_pyrogram)
32
+ from unzipper.database.split_arc import add_split_arc_user, del_split_arc_user
33
+ from unzipper.lib.downloader import Downloader
34
+ from unzipper.lib.backup_tool import CloudBackup
35
+ from unzipper.lib.extractor import Extractor, ExtractionFailed
36
+
37
+
38
+ # Callbacks
39
+ @unzip_client.on_callback_query()
40
+ @unzip_client.handle_query
41
+ async def unzipper_cb(_, query: CallbackQuery, texts):
42
+ qdat = query.data
43
+
44
+ if qdat == "megoinhome":
45
+ await query.edit_message_text(texts["start"].format(query.from_user.mention), reply_markup=Buttons.START)
46
+
47
+ elif qdat == "helpcallback":
48
+ await query.edit_message_text(texts["help_head"], reply_markup=Buttons.HELP)
49
+
50
+ elif qdat == "extracthelp":
51
+ await query.edit_message_text(texts["help_extract"], reply_markup=Buttons.HELP_BACK)
52
+
53
+ elif qdat == "upmodhelp":
54
+ await query.edit_message_text(texts["help_upmode"], reply_markup=Buttons.HELP_BACK)
55
+
56
+ elif qdat == "backuphelp":
57
+ await query.edit_message_text(texts["help_backup"], reply_markup=Buttons.HELP_BACK)
58
+
59
+ elif qdat == "thumbhelp":
60
+ await query.edit_message_text(texts["help_thumb"], reply_markup=Buttons.HELP_BACK)
61
+
62
+ elif qdat == "langhelp":
63
+ await query.edit_message_text(texts["help_lang"], reply_markup=Buttons.HELP_BACK)
64
+
65
+ elif qdat == "aboutcallback":
66
+ await query.edit_message_text(texts["about"].format(unzip_client.version), reply_markup=Buttons.BACK, disable_web_page_preview=True)
67
+
68
+ elif qdat.startswith("extract_file"):
69
+ splitted_data = qdat.split("|")
70
+ user_id = query.from_user.id
71
+ r_message = query.message.reply_to_message
72
+ arc_name = ""
73
+ download_path = f"{Config.DOWNLOAD_LOCATION}/{user_id}"
74
+ ext_files_dir = f"{download_path}/extracted"
75
+
76
+ try:
77
+ if splitted_data[1] == "url":
78
+ url = r_message.text
79
+ async with ClientSession() as ses:
80
+ # Get the file size
81
+ cleng = (await ses.head(url)).headers.get("Content-Length")
82
+ fsize = humanbytes(int(cleng)) if cleng else "undefined"
83
+ # Makes download dir
84
+ makedirs(download_path)
85
+ # Send logs
86
+ await unzip_client.send_message(Config.LOGS_CHANNEL, texts["log"].format(user_id, "N/A", "N/A", url, fsize))
87
+ s_time = time()
88
+ arc_name = f"{download_path}/archive_from_{user_id}_{path.basename(url)}"
89
+ await Downloader().download(url, arc_name, query.message)
90
+ e_time = time()
91
+
92
+ elif splitted_data[1] == "tg_file":
93
+ # Makes download dir
94
+ makedirs(download_path)
95
+ # Send Logs
96
+ rdoc = r_message.document
97
+ rchat = r_message.forward_from_chat
98
+ await r_message.copy(Config.LOGS_CHANNEL, texts["log"].format(
99
+ user_id,
100
+ rchat.title if rchat else "N/A",
101
+ rchat.id if rchat else "N/A",
102
+ rdoc.file_name,
103
+ humanbytes(rdoc.file_size))
104
+ )
105
+ s_time = time()
106
+ arc_name = f"{download_path}/archive_from_{user_id}_{rdoc.file_name}"
107
+ await r_message.download(
108
+ file_name=arc_name,
109
+ progress=progress_for_pyrogram, progress_args=(
110
+ "**Trying to Download!** \n", query.message, s_time)
111
+ )
112
+ e_time = time()
113
+
114
+ else:
115
+ return await unzip_client.answer_query(query, "Can't Find Details! Please contact support group!", answer_only=True)
116
+
117
+ await unzip_client.answer_query(query, texts["ok_download"].format(arc_name, TimeFormatter(round(e_time-s_time) * 1000)))
118
+
119
+ # Checks if the archive is a splitted one
120
+ arc_ext = path.splitext(arc_name)[1]
121
+ if arc_ext.replace(".", "").isnumeric():
122
+ password = ""
123
+ if splitted_data[2] == "with_pass":
124
+ password = (await unzip_client.ask(query.message.chat.id, texts["ask_password"])).text
125
+ await unzip_client.answer_query(query, texts["alert_splitted_arc"])
126
+ await add_split_arc_user(user_id, arc_name, password)
127
+ return
128
+
129
+ # Extract
130
+ exter = Extractor()
131
+ if splitted_data[2] == "with_pass":
132
+ password = (await unzip_client.ask(query.message.chat.id, texts["ask_password"])).text
133
+ ext_s_time = time()
134
+ await exter.extract(arc_name, ext_files_dir, password)
135
+ ext_e_time = time()
136
+ else:
137
+ ext_s_time = time()
138
+ await exter.extract(arc_name, ext_files_dir)
139
+ ext_e_time = time()
140
+
141
+ await unzip_client.answer_query(query, texts["ok_extract"].format(TimeFormatter(round(ext_e_time-ext_s_time) * 1000)))
142
+
143
+ # Upload extracted files
144
+ files = await get_files(ext_files_dir)
145
+ i_e_buttons = await Buttons.make_files_keyboard(files, user_id, query.message.chat.id)
146
+ try:
147
+ await unzip_client.answer_query(query, texts["select_files"], reply_markup=i_e_buttons)
148
+ except ReplyMarkupTooLong:
149
+ i_e_buttons = await Buttons.make_files_keyboard(files, user_id, query.message.chat.id, False)
150
+ await unzip_client.answer_query(query, texts["select_files"], reply_markup=i_e_buttons)
151
+
152
+ except ExtractionFailed:
153
+ await unzip_client.answer_query(query, texts["failed_extract"])
154
+ except BaseException as e:
155
+ try:
156
+ await unzip_client.answer_query(query, texts["failed_main"].format(e))
157
+ rmtree(download_path)
158
+ except Exception as er:
159
+ logging.warn(er)
160
+
161
+ elif qdat.startswith("ext_f"):
162
+ spl_data = qdat.split("|")
163
+ file_path = f"{Config.DOWNLOAD_LOCATION}/{spl_data[1]}/extracted"
164
+ files = await get_files(file_path)
165
+ # Next level logic lmao
166
+ if not files:
167
+ if path.isdir(f"{Config.DOWNLOAD_LOCATION}/{spl_data[1]}"):
168
+ rmtree(f"{Config.DOWNLOAD_LOCATION}/{spl_data[1]}")
169
+ return await unzip_client.answer_query(query, texts["alert_empty_files"])
170
+
171
+ await unzip_client.answer_query(query, texts["alert_sending_file"], True)
172
+ await unzip_client.send_file(spl_data[2], files[int(spl_data[3])], query, texts["this_lang"])
173
+
174
+ # Refreshing Inline keyboard
175
+ await unzip_client.answer_query(query, texts["refreshing"])
176
+ files = await get_files(file_path)
177
+ # There are no files let's die
178
+ if not files:
179
+ try:
180
+ rmtree(f"{Config.DOWNLOAD_LOCATION}/{spl_data[1]}")
181
+ except:
182
+ pass
183
+ return await unzip_client.answer_query(query, texts["ok_upload_basic"])
184
+ i_e_buttons = await Buttons.make_files_keyboard(files, query.from_user.id, query.message.chat.id)
185
+ try:
186
+ await unzip_client.answer_query(query, texts["select_files"], reply_markup=i_e_buttons)
187
+ except ReplyMarkupTooLong:
188
+ i_e_buttons = await Buttons.make_files_keyboard(files, user_id, query.message.chat.id, False)
189
+ await unzip_client.answer_query(query, texts["select_files"], reply_markup=i_e_buttons)
190
+
191
+ elif qdat.startswith("ext_a"):
192
+ spl_data = qdat.split("|")
193
+ file_path = f"{Config.DOWNLOAD_LOCATION}/{spl_data[1]}/extracted"
194
+ paths = await get_files(file_path)
195
+ if not paths:
196
+ if path.isdir(f"{Config.DOWNLOAD_LOCATION}/{spl_data[1]}"):
197
+ rmtree(f"{Config.DOWNLOAD_LOCATION}/{spl_data[1]}")
198
+ return await unzip_client.answer_query(query, texts["alert_empty_files"])
199
+
200
+ await unzip_client.answer_query(query, texts["alert_sending_files"], True)
201
+ for file in paths:
202
+ await unzip_client.send_file(spl_data[2], file, query, texts["this_lang"], True)
203
+
204
+ await unzip_client.answer_query(query, texts["ok_upload_basic"])
205
+ rmtree(f"{Config.DOWNLOAD_LOCATION}/{spl_data[1]}")
206
+
207
+ elif qdat.startswith("set_mode"):
208
+ mode = qdat.split("|")[1]
209
+ await set_upload_mode(query.from_user.id, mode)
210
+ await unzip_client.answer_query(query, texts["changed_upmode"].format(mode))
211
+
212
+ elif qdat.startswith("set_lang"):
213
+ qlang = qdat.split("|")[1]
214
+ chid = query.message.chat.id
215
+ USER_LANG[chid] = qlang
216
+ await set_language(chid, qlang)
217
+ await unzip_client.answer_query(query, texts["changed_lang"].format(qlang))
218
+
219
+ elif qdat.startswith("gf_setting"):
220
+ gf = GofileDB(query.from_user.id)
221
+ mode = qdat.split("-")[1]
222
+ if mode == "set":
223
+ tkn = await unzip_client.ask(query.message.chat.id, texts["ask_gofile_token"])
224
+ await gf.save_token(tkn.text)
225
+ await tkn.delete()
226
+ elif mode == "del":
227
+ await gf.del_token()
228
+ elif mode == "get":
229
+ return await unzip_client.answer_query(query, texts["gofile_token"].format(await gf.get_token()))
230
+ await unzip_client.answer_query(query, "**Done ✅!**")
231
+
232
+ elif qdat.startswith("cloudbackup"):
233
+ clb = CloudBackup(query.from_user.id)
234
+ to = qdat.split("|")[1]
235
+ if to == "gofile":
236
+ await unzip_client.answer_query(query, texts["alert_uploading_to_gofile"])
237
+ glnk = await clb.gofile_backup()
238
+ await unzip_client.answer_query(query, texts["ok_backup"].format(glnk), reply_markup=Buttons.make_button("Gofile link", url=glnk))
239
+
240
+ elif qdat == "cancel_dis":
241
+ await del_split_arc_user(query.from_user.id)
242
+ try:
243
+ rmtree(f"{Config.DOWNLOAD_LOCATION}/{query.from_user.id}")
244
+ except:
245
+ pass
246
+ await unzip_client.answer_query(query, texts["canceled"].format("Process cancelled"))
247
+
248
+ elif qdat == "nobully":
249
+ await unzip_client.answer_query(query, texts["ok_wont_delete"])
unzipper/modules/extract.py ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 re import match
14
+ from time import time
15
+ from os import path, remove
16
+
17
+ from config import Config
18
+ from pyrogram import filters
19
+ from aiohttp import ClientSession
20
+ from pyrogram.types import Message
21
+ from unzipper import unzip_client, Buttons
22
+ from pyrogram.errors import ReplyMarkupTooLong
23
+
24
+ from unzipper.lib.extractor import Extractor
25
+ from unzipper.lib.downloader import Downloader, dl_regex
26
+ from unzipper.helpers_nexa.utils import (TimeFormatter, get_files,
27
+ progress_for_pyrogram, humanbytes)
28
+ from unzipper.database.split_arc import del_split_arc_user, get_split_arc_user
29
+
30
+
31
+ @unzip_client.on_message(filters.incoming & filters.private & filters.regex(dl_regex) | filters.document)
32
+ @unzip_client.handle_erros
33
+ async def extract_dis_archive(_, message: Message, texts):
34
+ unzip_msg = await message.reply(texts["processing"], reply_to_message_id=message.id)
35
+ user_id = message.from_user.id
36
+ download_path = f"{Config.DOWNLOAD_LOCATION}/{user_id}"
37
+ is_url = message.text and (match(dl_regex, message.text))
38
+ is_doc = message.document
39
+
40
+ # Splitted files
41
+ is_spl, lfn, ps = await get_split_arc_user(user_id)
42
+ if is_spl:
43
+ file_name = is_doc.file_name if is_doc else path.basename(message.text)
44
+ await unzip_msg.edit(texts["alert_downloading_part"])
45
+ # Check file extension
46
+ if not path.splitext(file_name)[1].replace(".", "").isnumeric():
47
+ return await unzip_msg.edit(texts["no_splitted_arc"])
48
+ arc_name = f"{download_path}/archive_from_{user_id}_{file_name}"
49
+ if path.isfile(arc_name):
50
+ return await unzip_msg.edit(texts["alert_part_exists"])
51
+ # Download the file
52
+ s_time = time()
53
+ if is_url:
54
+ async with ClientSession() as ses:
55
+ cleng = (await ses.head(message.text)).headers.get("Content-Length")
56
+ fsize = humanbytes(cleng) if cleng else "undefined"
57
+ # Send logs
58
+ await unzip_client.send_message(Config.LOGS_CHANNEL, texts["log"].format(
59
+ user_id,
60
+ "N/A",
61
+ "N/A",
62
+ file_name,
63
+ fsize)
64
+ )
65
+ await Downloader().download(message.text, arc_name, unzip_msg)
66
+ else:
67
+ # Send logs
68
+ rchat = message.forward_from_chat
69
+ await unzip_client.send_message(Config.LOGS_CHANNEL, texts["log"].format(
70
+ user_id,
71
+ rchat.title if rchat else "N/A",
72
+ rchat.id if rchat else "N/A",
73
+ file_name,
74
+ humanbytes(is_doc.file_size))
75
+ )
76
+ await message.download(
77
+ file_name=arc_name,
78
+ progress=progress_for_pyrogram, progress_args=(
79
+ "**Trying to Download!** \n", unzip_msg, s_time)
80
+ )
81
+ e_time = time()
82
+ await unzip_msg.edit(texts["ok_download"].format(file_name, TimeFormatter(round(e_time-s_time) * 1000)))
83
+ return
84
+
85
+ if path.isdir(download_path):
86
+ return await unzip_msg.edit(texts["alert_process_running_already"])
87
+ if is_url:
88
+ await unzip_msg.edit(texts["ask_what_you_want"], reply_markup=Buttons.EXTRACT_URL)
89
+ elif is_doc:
90
+ await unzip_msg.edit(texts["ask_what_you_want"], reply_markup=Buttons.EXTRACT_FILE)
91
+ else:
92
+ await unzip_msg.edit(texts["no_archive"])
93
+
94
+
95
+ @unzip_client.on_message(filters.private & filters.command("done"))
96
+ @unzip_client.handle_erros
97
+ async def extracted_dis_spl_archive(_, message: Message, texts):
98
+ spl_umsg = await message.reply(texts["processing"], reply_to_message_id=message.id)
99
+ user_id = message.from_user.id
100
+ # Retrive data from database
101
+ is_spl, lfn, ps = await get_split_arc_user(user_id)
102
+ # Path checks
103
+ if not is_spl:
104
+ return await spl_umsg.edit("`Bruh, why are you sending this command 🤔?`")
105
+ ext_path = f"{Config.DOWNLOAD_LOCATION}/{user_id}/extracted"
106
+ arc_path = path.dirname(lfn)
107
+ if not path.isdir(arc_path):
108
+ await spl_umsg.edit(texts["alert_empty_files"])
109
+ return await del_split_arc_user(user_id)
110
+ # Remove user record from the database
111
+ await del_split_arc_user(user_id)
112
+ # Extract the archive
113
+ ext = Extractor()
114
+ s_time = time()
115
+ await ext.extract(lfn, ext_path, ps, True)
116
+ extdarc = f"{ext_path}/{path.splitext(path.basename(lfn))[0]}"
117
+ await ext.extract(extdarc, ext_path, ps)
118
+ e_time = time()
119
+ await spl_umsg.edit(texts["ok_extract"].format(TimeFormatter(round(e_time-s_time) * 1000)))
120
+ # Try to remove merged archive
121
+ try:
122
+ remove(extdarc)
123
+ except:
124
+ pass
125
+ paths = await get_files(ext_path)
126
+ i_e_btns = await Buttons.make_files_keyboard(paths, user_id, message.chat.id)
127
+ try:
128
+ await spl_umsg.edit(texts["select_files"], reply_markup=i_e_btns)
129
+ except ReplyMarkupTooLong:
130
+ i_e_btns = await Buttons.make_files_keyboard(paths, user_id, message.chat.id, False)
131
+ await spl_umsg.edit(texts["select_files"], reply_markup=i_e_btns)
unzipper/modules/settings.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 pyrogram import filters
14
+ from pyrogram.types import Message
15
+ from unzipper import unzip_client, Buttons
16
+ from unzipper.database.language import get_language
17
+ from unzipper.database.upload_mode import get_upload_mode
18
+
19
+
20
+ @unzip_client.on_message(filters.private & filters.command(["gofile", "gfsets"]))
21
+ @unzip_client.handle_erros
22
+ async def gofile_settings(_, message: Message, texts):
23
+ prs_msg = await message.reply(texts["processing"], reply_to_message_id=message.id)
24
+ await prs_msg.edit("**Gofile.io settings ⚙️**", reply_markup=Buttons.SETTINGS_GOFILE)
25
+
26
+
27
+ @unzip_client.on_message(filters.private & filters.command(["mode", "setmode"]))
28
+ @unzip_client.handle_erros
29
+ async def set_up_mode_for_user(_, message: Message, texts):
30
+ prs_msg = await message.reply(texts["processing"], reply_to_message_id=message.id)
31
+ upload_mode = await get_upload_mode(message.from_user.id)
32
+ await prs_msg.edit(texts["select_upmode"].format(upload_mode), reply_markup=Buttons.UPLOAD_MODE)
33
+
34
+
35
+ @unzip_client.on_message(filters.private & filters.command(["lang", "set_lang"]))
36
+ @unzip_client.handle_erros
37
+ async def language_settings(_, message: Message, texts):
38
+ prs_msg = await message.reply(texts["processing"])
39
+ clng = await get_language(message.from_user.id)
40
+ await prs_msg.edit(texts["select_lang"].format(clng), reply_markup=Buttons.LANGUAGES)
unzipper/modules/user_utils.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 remove
14
+ from pyrogram import filters
15
+ from pyrogram.types import Message
16
+ from unzipper import unzip_client, Buttons
17
+ from unzipper.database.thumbnail import save_thumbnail, get_thumbnail, del_thumbnail
18
+
19
+
20
+ @unzip_client.on_message(filters.private & filters.command("start"))
21
+ @unzip_client.handle_erros
22
+ async def start_bot(_, message: Message, texts):
23
+ await message.reply_text(texts["start"].format(message.from_user.mention), reply_markup=Buttons.START, disable_web_page_preview=True)
24
+
25
+
26
+ @unzip_client.on_message(filters.private & filters.command(["save", "set_thumb"]))
27
+ @unzip_client.handle_erros
28
+ async def save_dis_thumb(_, message: Message, texts):
29
+ prs_msg = await message.reply(texts["processing"], reply_to_message_id=message.id)
30
+ rply = message.reply_to_message
31
+ if not rply or not rply.photo:
32
+ return await prs_msg.edit(texts["no_replied_msg"])
33
+ await save_thumbnail(message.from_user.id, rply)
34
+ await prs_msg.edit(texts["ok_saving_thumb"])
35
+
36
+
37
+ @unzip_client.on_message(filters.private & filters.command(["thget", "get_thumb"]))
38
+ @unzip_client.handle_erros
39
+ async def give_my_thumb(_, message: Message, texts):
40
+ prs_msg = await message.reply(texts["processing"], reply_to_message_id=message.id)
41
+ gthumb = await get_thumbnail(message.from_user.id, True)
42
+ if not gthumb:
43
+ return await prs_msg.edit(texts["no_thumb"])
44
+ await prs_msg.delete()
45
+ await message.reply_photo(gthumb)
46
+ remove(gthumb)
47
+
48
+
49
+ @unzip_client.on_message(filters.private & filters.command(["thdel", "del_thumb"]))
50
+ @unzip_client.handle_erros
51
+ async def delete_my_thumb(_, message: Message, texts):
52
+ prs_msg = await message.reply(texts["processing"], reply_to_message_id=message.id)
53
+ texist = await get_thumbnail(message.from_user.id)
54
+ if not texist:
55
+ return await prs_msg.edit(texts["no_thumb"])
56
+ await del_thumbnail(message.from_user.id)
57
+ remove(texist)
58
+ await prs_msg.edit(texts["ok_deleting_thumb"])
59
+
60
+
61
+ @unzip_client.on_message(filters.private & filters.command("backup"))
62
+ @unzip_client.handle_erros
63
+ async def do_backup_files(_, message: Message, texts):
64
+ prs_msg = await message.reply(texts["processing"], reply_to_message_id=message.id)
65
+ await prs_msg.edit(texts["select_provider"], reply_markup=Buttons.BACKUP)
66
+
67
+
68
+ @unzip_client.on_message(filters.private & filters.command("clean"))
69
+ @unzip_client.handle_erros
70
+ async def clean_ma_files(_, message: Message, texts):
71
+ prs_msg = await message.reply(texts["processing"], reply_to_message_id=message.id)
72
+ await prs_msg.edit(texts["ask_clean"], reply_markup=Buttons.CLEAN)