BinaryONe
commited on
Commit
·
a9f0bb6
1
Parent(s):
d4a1239
Polls Update
Browse files
FileStream/bot/plugins/FileHandlers/callback.py
CHANGED
|
@@ -106,51 +106,6 @@ async def cb_data(bot: Client, update: CallbackQuery):
|
|
| 106 |
disable_web_page_preview=True,
|
| 107 |
reply_markup=reply_markup,
|
| 108 |
)
|
| 109 |
-
elif usr_cmd[0] == "initilize":
|
| 110 |
-
try:
|
| 111 |
-
user_id = str(usr_cmd[1])
|
| 112 |
-
message_id = int(usr_cmd[2])
|
| 113 |
-
response_id = int(usr_cmd[3])
|
| 114 |
-
message = await FileStream.get_messages(user_id, message_id)
|
| 115 |
-
#response = await FileStream.get_messages(user_id, response_id)
|
| 116 |
-
instruction = {
|
| 117 |
-
"privacy_type": "PUBLIC",
|
| 118 |
-
"user_id": user_id,
|
| 119 |
-
"user_type": "TELEGRAM"
|
| 120 |
-
}
|
| 121 |
-
file_caption = getattr(message, "caption", f"{get_name(message)}" ) or "None/Unknown"
|
| 122 |
-
file_name = get_name(message)
|
| 123 |
-
print("Detail",file_caption,file_name)
|
| 124 |
-
await update.message.edit_text(
|
| 125 |
-
text=file_caption,
|
| 126 |
-
parse_mode=ParseMode.HTML,
|
| 127 |
-
disable_web_page_preview=True,
|
| 128 |
-
reply_markup=InlineKeyboardMarkup([
|
| 129 |
-
[InlineKeyboardButton("Movie", callback_data=f"pubup_{user_id}_{message_id}_Movie")],
|
| 130 |
-
[InlineKeyboardButton("WebSeries", callback_data=f"pubup_{user_id}_{message_id}_WebSeries")],
|
| 131 |
-
[InlineKeyboardButton("Anime", callback_data=f"pubup_{user_id}_{message_id}_Anime")],
|
| 132 |
-
[InlineKeyboardButton("Documentary", callback_data=f"pubup_{user_id}_{message_id}_Documentary")],
|
| 133 |
-
[InlineKeyboardButton("Regular", callback_data=f"pubup_{user_id}_{message_id}_Regular")],
|
| 134 |
-
]),
|
| 135 |
-
)
|
| 136 |
-
"""#await FileStream.delete_messages(chat_id=user_id,message_ids=response_id)
|
| 137 |
-
await FileStream.send_poll(
|
| 138 |
-
type= enums.PollType.REGULAR,
|
| 139 |
-
reply_to_message_id=message_id,
|
| 140 |
-
explanation=f"{file_caption}",
|
| 141 |
-
question=f"{message_id}_{user_id}_{response_id}_File Name :\n{file_caption}",
|
| 142 |
-
options=["Movie", "WebSeries", "Anime", "Documentary", "Regular"],
|
| 143 |
-
allows_multiple_answers=True,
|
| 144 |
-
chat_id=user_id
|
| 145 |
-
)
|
| 146 |
-
"""
|
| 147 |
-
except Exception as e:
|
| 148 |
-
print(f"An error occurred: {str(e)}")
|
| 149 |
-
await FileStream.send_message(
|
| 150 |
-
chat_id=Telegram.ULOG_GROUP,
|
| 151 |
-
text=f"An error occurred: {str(e)}"
|
| 152 |
-
)
|
| 153 |
-
|
| 154 |
elif usr_cmd[0] == "pubup":
|
| 155 |
try:
|
| 156 |
user_id = str(usr_cmd[1])
|
|
@@ -167,94 +122,7 @@ async def cb_data(bot: Client, update: CallbackQuery):
|
|
| 167 |
}
|
| 168 |
file_caption = getattr(message, "caption", f"{get_name(message)}" ) or "None/Unknown"
|
| 169 |
file_name = get_name(message)
|
| 170 |
-
print("Detail",file_caption,"\nFile:",file_name)
|
| 171 |
-
"""
|
| 172 |
-
await FileStream.delete_messages(
|
| 173 |
-
chat_id=user_id,
|
| 174 |
-
message_ids=message_id
|
| 175 |
-
)
|
| 176 |
-
await FileStream.send_poll(
|
| 177 |
-
type= enums.PollType.REGULAR,
|
| 178 |
-
reply_to_message_id=message_id,
|
| 179 |
-
question="Is this a poll question?",
|
| 180 |
-
options=["Movie", "WebSeries", "Anime", "Documentary", "Regular"],
|
| 181 |
-
allows_multiple_answers=True,
|
| 182 |
-
chat_id=user_id
|
| 183 |
-
)
|
| 184 |
-
|
| 185 |
-
functions.messages.EditMessage(
|
| 186 |
-
peer=user_id,
|
| 187 |
-
id=message_id,
|
| 188 |
-
media=InputMediaPoll(
|
| 189 |
-
poll=Poll(
|
| 190 |
-
id=FileStream.rnd_id(),
|
| 191 |
-
question="Is this a poll question?",
|
| 192 |
-
answers=["Movie", "WebSeries", "Anime", "Documentary", "Regular"],
|
| 193 |
-
multiple_choice=True,
|
| 194 |
-
quiz=False,
|
| 195 |
-
)
|
| 196 |
-
),
|
| 197 |
-
)
|
| 198 |
-
|
| 199 |
-
print("Poll function and all initializers executed successfully.")
|
| 200 |
-
print("dir(Poll):", dir(Poll))
|
| 201 |
-
print("Poll.__init__:", Poll.__init__)
|
| 202 |
-
print("Poll.__init__ inputs:", Poll.__init__.__code__.co_varnames)
|
| 203 |
-
print("InputMediaPoll.__init__ inputs:", InputMediaPoll.__init__.__code__.co_varnames)
|
| 204 |
-
update=await FileStream.edit_message_media(
|
| 205 |
-
chat_id=user_id,
|
| 206 |
-
message_id=response_id,
|
| 207 |
-
media=InputMediaPoll(
|
| 208 |
-
caption="Is this a poll question?",
|
| 209 |
-
poll=Poll(
|
| 210 |
-
id=FileStream.rnd_id(),
|
| 211 |
-
question="Is this a poll question?",
|
| 212 |
-
answers=[
|
| 213 |
-
PollAnswer(text="Movie", option=bytes([1])),
|
| 214 |
-
PollAnswer(text="WebSeries", option=bytes([2])),
|
| 215 |
-
PollAnswer(text="Anime", option=bytes([3])),
|
| 216 |
-
PollAnswer(text="Documentary", option=bytes([4]))
|
| 217 |
-
],
|
| 218 |
-
closed=False,
|
| 219 |
-
public_voters=True,
|
| 220 |
-
multiple_choice=True,
|
| 221 |
-
quiz=False,
|
| 222 |
-
close_period=None,
|
| 223 |
-
close_date=None
|
| 224 |
-
),
|
| 225 |
-
)
|
| 226 |
-
)
|
| 227 |
-
print("Update:",update)
|
| 228 |
-
|
| 229 |
-
PollAnswer(
|
| 230 |
-
id=FileStream.rnd_id(),
|
| 231 |
-
question="Is this a poll question?",
|
| 232 |
-
answers=["Movie","WebSeries"),
|
| 233 |
-
PollAnswer(text="Anime"),
|
| 234 |
-
PollAnswer(text="Documentary"),
|
| 235 |
-
PollAnswer(text="Regular")
|
| 236 |
-
],
|
| 237 |
-
multiple_choice=True,
|
| 238 |
-
quiz=False,
|
| 239 |
-
answers=[
|
| 240 |
-
PollAnswer("Movie"),
|
| 241 |
-
PollAnswer(text="WebSeries"),
|
| 242 |
-
PollAnswer(text="Anime"),
|
| 243 |
-
PollAnswer(text="Documentary"),
|
| 244 |
-
PollAnswer(text="Regular")
|
| 245 |
-
],
|
| 246 |
-
await FileStream.send_poll(
|
| 247 |
-
type= enums.PollType.REGULAR,
|
| 248 |
-
reply_to_message_id=message_id,
|
| 249 |
-
question="Is this a poll question?",
|
| 250 |
-
options=["Movie", "WebSeries", "Anime", "Documentary", "Regular"],
|
| 251 |
-
allows_multiple_answers=True,
|
| 252 |
-
chat_id=user_id
|
| 253 |
-
)
|
| 254 |
-
|
| 255 |
-
#type=enums.PollType.QUIZ,
|
| 256 |
-
print(polls)
|
| 257 |
-
"""
|
| 258 |
file_info = get_file_info(message, instruction)
|
| 259 |
# Here we are Adding the File Into the database First
|
| 260 |
inserted_id = await db.add_file(file_info)
|
|
|
|
| 106 |
disable_web_page_preview=True,
|
| 107 |
reply_markup=reply_markup,
|
| 108 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
elif usr_cmd[0] == "pubup":
|
| 110 |
try:
|
| 111 |
user_id = str(usr_cmd[1])
|
|
|
|
| 122 |
}
|
| 123 |
file_caption = getattr(message, "caption", f"{get_name(message)}" ) or "None/Unknown"
|
| 124 |
file_name = get_name(message)
|
| 125 |
+
print("Detail",file_caption,"\nFile:",file_name,"\n Message Detail",message)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
file_info = get_file_info(message, instruction)
|
| 127 |
# Here we are Adding the File Into the database First
|
| 128 |
inserted_id = await db.add_file(file_info)
|
FileStream/bot/plugins/FileHandlers/stream.py
CHANGED
|
@@ -64,17 +64,20 @@ async def private_receive_handler(bot: Client, message: Message):
|
|
| 64 |
}
|
| 65 |
file_info=get_file_info(message, instruction)
|
| 66 |
reply = await message.reply_text(LANG.PROCESSING_TEXT)
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
| 78 |
except FloodWait as e:
|
| 79 |
print(f"Sleeping for {str(e.value)}s")
|
| 80 |
await asyncio.sleep(e.value)
|
|
|
|
| 64 |
}
|
| 65 |
file_info=get_file_info(message, instruction)
|
| 66 |
reply = await message.reply_text(LANG.PROCESSING_TEXT)
|
| 67 |
+
|
| 68 |
+
await reply.edit_text(
|
| 69 |
+
text=f"{file_info['file']['caption'] if file_info['file']['caption'] else file_info['file']['file_name']}",
|
| 70 |
+
parse_mode=ParseMode.HTML,
|
| 71 |
+
disable_web_page_preview=True,
|
| 72 |
+
reply_markup=InlineKeyboardMarkup([
|
| 73 |
+
[InlineKeyboardButton("Movie", callback_data=f"pubup_{user_id}_{message_id}_Movie")],
|
| 74 |
+
[InlineKeyboardButton("WebSeries", callback_data=f"pubup_{user_id}_{message_id}_WebSeries")],
|
| 75 |
+
[InlineKeyboardButton("Anime", callback_data=f"pubup_{user_id}_{message_id}_Anime")],
|
| 76 |
+
[InlineKeyboardButton("Documentary", callback_data=f"pubup_{user_id}_{message_id}_Documentary")],
|
| 77 |
+
[InlineKeyboardButton("Regular", callback_data=f"pubup_{user_id}_{message_id}_Regular")],
|
| 78 |
+
[ InlineKeyboardButton("ᴄʟᴏsᴇ", callback_data="close")]
|
| 79 |
+
]),
|
| 80 |
+
)
|
| 81 |
except FloodWait as e:
|
| 82 |
print(f"Sleeping for {str(e.value)}s")
|
| 83 |
await asyncio.sleep(e.value)
|
FileStream/utils/FileProcessors/file_properties.py
CHANGED
|
@@ -189,6 +189,11 @@ def get_file_info(message, instruction):
|
|
| 189 |
"user_id": instruction['user_id'],
|
| 190 |
"user_type": instruction['user_type'],
|
| 191 |
"message_id": message.id,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
"location": message.from_user.id if (message.chat.type == ChatType.PRIVATE) else message.chat.id,
|
| 193 |
"file": {
|
| 194 |
"file_id": getattr(media, "file_id", ""),
|
|
|
|
| 189 |
"user_id": instruction['user_id'],
|
| 190 |
"user_type": instruction['user_type'],
|
| 191 |
"message_id": message.id,
|
| 192 |
+
"TMDB_id": int(),
|
| 193 |
+
"title": "Unknown",
|
| 194 |
+
"type": instruction['type'] if instruction['type'] else "Unknown",
|
| 195 |
+
"subtype":"Unknown",
|
| 196 |
+
"quality":"Unknown",
|
| 197 |
"location": message.from_user.id if (message.chat.type == ChatType.PRIVATE) else message.chat.id,
|
| 198 |
"file": {
|
| 199 |
"file_id": getattr(media, "file_id", ""),
|
Unused Codes/callback.py
ADDED
|
@@ -0,0 +1,734 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import math
|
| 2 |
+
import asyncio
|
| 3 |
+
import datetime
|
| 4 |
+
|
| 5 |
+
from pyrogram import filters, Client, raw, types,enums
|
| 6 |
+
from pyrogram.errors import FloodWait
|
| 7 |
+
from pyrogram.raw import functions
|
| 8 |
+
from pyrogram.raw.types import Poll,PollAnswer, InputMediaPoll
|
| 9 |
+
#from pyrogram.raw.base import PollAnswer, Poll
|
| 10 |
+
from pyrogram.enums.parse_mode import ParseMode
|
| 11 |
+
from pyrogram.file_id import FileId, FileType, PHOTO_TYPES
|
| 12 |
+
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, CallbackQuery, WebAppInfo
|
| 13 |
+
from pyrogram.raw.types import KeyboardButtonSimpleWebView
|
| 14 |
+
|
| 15 |
+
#-------------------------Local Imports -----------------------------------#
|
| 16 |
+
from FileStream import __version__
|
| 17 |
+
from FileStream.Database import Database
|
| 18 |
+
from FileStream.config import Telegram, Server
|
| 19 |
+
from FileStream.bot import FileStream
|
| 20 |
+
from FileStream.bot import MULTI_CLIENTS
|
| 21 |
+
from FileStream.Exceptions import FileNotFound # Corrected the import statement
|
| 22 |
+
from FileStream.utils.FileProcessors.translation import LANG, BUTTON
|
| 23 |
+
from FileStream.utils.FileProcessors.human_readable import humanbytes
|
| 24 |
+
from FileStream.bot.plugins.FileHandlers.stream import private_receive_handler
|
| 25 |
+
from FileStream.utils.FileProcessors.file_properties import get_file_ids, get_file_info,get_name
|
| 26 |
+
from FileStream.utils.FileProcessors.bot_utils import gen_link, priv_func, gen_priv_file_link
|
| 27 |
+
#-----------------Starting Point --------------------------#
|
| 28 |
+
|
| 29 |
+
db = Database(Telegram.DATABASE_URL, Telegram.SESSION_NAME)
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
#---------------------[ START CMD ]---------------------#
|
| 33 |
+
@FileStream.on_callback_query()
|
| 34 |
+
async def cb_data(bot: Client, update: CallbackQuery):
|
| 35 |
+
usr_cmd = update.data.split("_")
|
| 36 |
+
if usr_cmd[0] == "home":
|
| 37 |
+
await update.message.edit_text(text=LANG.START_TEXT.format(
|
| 38 |
+
update.from_user.mention, FileStream.username),
|
| 39 |
+
disable_web_page_preview=True,
|
| 40 |
+
reply_markup=BUTTON.START_BUTTONS)
|
| 41 |
+
elif usr_cmd[0] == "help":
|
| 42 |
+
await update.message.edit_text(text=LANG.HELP_TEXT.format(
|
| 43 |
+
Telegram.OWNER_ID),
|
| 44 |
+
disable_web_page_preview=True,
|
| 45 |
+
reply_markup=BUTTON.HELP_BUTTONS)
|
| 46 |
+
elif usr_cmd[0] == "about":
|
| 47 |
+
await update.message.edit_text(text=LANG.ABOUT_TEXT.format(
|
| 48 |
+
FileStream.fname, __version__),
|
| 49 |
+
disable_web_page_preview=True,
|
| 50 |
+
reply_markup=BUTTON.ABOUT_BUTTONS)
|
| 51 |
+
|
| 52 |
+
#---------------------[ MY FILES CMD ]---------------------#
|
| 53 |
+
|
| 54 |
+
elif usr_cmd[0] == "N/A":
|
| 55 |
+
await update.answer("N/A", True)
|
| 56 |
+
elif usr_cmd[0] == "close":
|
| 57 |
+
await update.message.delete()
|
| 58 |
+
elif usr_cmd[0] == "back":
|
| 59 |
+
try:
|
| 60 |
+
user_id = str(usr_cmd[1])
|
| 61 |
+
message_id = int(usr_cmd[2])
|
| 62 |
+
print(user_id, message_id)
|
| 63 |
+
message = await FileStream.get_messages(user_id, message_id)
|
| 64 |
+
await private_receive_handler(FileStream, message)
|
| 65 |
+
except FloodWait as e:
|
| 66 |
+
print(f"Sleeping for {str(e.value)}s")
|
| 67 |
+
await asyncio.sleep(e.value)
|
| 68 |
+
await FileStream.send_message(
|
| 69 |
+
chat_id=Telegram.ULOG_GROUP,
|
| 70 |
+
text=
|
| 71 |
+
f"Gᴏᴛ FʟᴏᴏᴅWᴀɪᴛ ᴏғ {str(e.value)}s ғʀᴏᴍ [{message.from_user.first_name}](tg://user?id={message.from_user.id})\n\n**ᴜsᴇʀ ɪᴅ :** `{str(message.from_user.id)}`",
|
| 72 |
+
disable_web_page_preview=True,
|
| 73 |
+
parse_mode=ParseMode.MARKDOWN)
|
| 74 |
+
|
| 75 |
+
elif usr_cmd[0] == "msgdelete":
|
| 76 |
+
await update.message.edit_caption(
|
| 77 |
+
caption="**Cᴏɴғɪʀᴍ ʏᴏᴜ ᴡᴀɴᴛ ᴛᴏ ᴅᴇʟᴇᴛᴇ ᴛʜᴇ Fɪʟᴇ**\n\n",
|
| 78 |
+
reply_markup=InlineKeyboardMarkup([[
|
| 79 |
+
InlineKeyboardButton(
|
| 80 |
+
"ʏᴇs", callback_data=f"msgdelyes_{usr_cmd[1]}_{usr_cmd[2]}"),
|
| 81 |
+
InlineKeyboardButton(
|
| 82 |
+
"ɴᴏ", callback_data=f"myfile_{usr_cmd[1]}_{usr_cmd[2]}")
|
| 83 |
+
]]))
|
| 84 |
+
elif usr_cmd[0] == "msgdelyes":
|
| 85 |
+
await delete_user_file(usr_cmd[1], int(usr_cmd[2]), update)
|
| 86 |
+
return
|
| 87 |
+
elif usr_cmd[0] == "msgdelpvt":
|
| 88 |
+
await update.message.edit_caption(
|
| 89 |
+
caption="**Cᴏɴғɪʀᴍ ʏᴏᴜ ᴡᴀɴᴛ ᴛᴏ ᴅᴇʟᴇᴛᴇ ᴛʜᴇ Fɪʟᴇ**\n\n",
|
| 90 |
+
reply_markup=InlineKeyboardMarkup([[
|
| 91 |
+
InlineKeyboardButton("ʏᴇs",
|
| 92 |
+
callback_data=f"msgdelpvtyes_{usr_cmd[1]}"),
|
| 93 |
+
InlineKeyboardButton("ɴᴏ",
|
| 94 |
+
callback_data=f"mainstream_{usr_cmd[1]}")
|
| 95 |
+
]]))
|
| 96 |
+
elif usr_cmd[0] == "msgdelpvtyes":
|
| 97 |
+
await delete_user_filex(usr_cmd[1], update)
|
| 98 |
+
return
|
| 99 |
+
|
| 100 |
+
elif usr_cmd[0] == "mainstream":
|
| 101 |
+
_id = usr_cmd[1]
|
| 102 |
+
reply_markup, stream_text = await gen_link(_id=_id)
|
| 103 |
+
await update.message.edit_text(
|
| 104 |
+
text=stream_text,
|
| 105 |
+
parse_mode=ParseMode.HTML,
|
| 106 |
+
disable_web_page_preview=True,
|
| 107 |
+
reply_markup=reply_markup,
|
| 108 |
+
)
|
| 109 |
+
try:
|
| 110 |
+
user_id = str(usr_cmd[1])
|
| 111 |
+
message_id = int(usr_cmd[2])
|
| 112 |
+
response_id = int(usr_cmd[3])
|
| 113 |
+
message = await FileStream.get_messages(user_id, message_id)
|
| 114 |
+
#response = await FileStream.get_messages(user_id, response_id)
|
| 115 |
+
instruction = {
|
| 116 |
+
"privacy_type": "PUBLIC",
|
| 117 |
+
"user_id": user_id,
|
| 118 |
+
"user_type": "TELEGRAM"
|
| 119 |
+
}
|
| 120 |
+
file_caption = getattr(message, "caption", f"{get_name(message)}" ) or "None/Unknown"
|
| 121 |
+
file_name = get_name(message)
|
| 122 |
+
print("Detail",file_caption,file_name)
|
| 123 |
+
await update.message.edit_text(
|
| 124 |
+
text=file_caption,
|
| 125 |
+
parse_mode=ParseMode.HTML,
|
| 126 |
+
disable_web_page_preview=True,
|
| 127 |
+
reply_markup=InlineKeyboardMarkup([
|
| 128 |
+
[InlineKeyboardButton("Movie", callback_data=f"pubup_{user_id}_{message_id}_Movie")],
|
| 129 |
+
[InlineKeyboardButton("WebSeries", callback_data=f"pubup_{user_id}_{message_id}_WebSeries")],
|
| 130 |
+
[InlineKeyboardButton("Anime", callback_data=f"pubup_{user_id}_{message_id}_Anime")],
|
| 131 |
+
[InlineKeyboardButton("Documentary", callback_data=f"pubup_{user_id}_{message_id}_Documentary")],
|
| 132 |
+
[InlineKeyboardButton("Regular", callback_data=f"pubup_{user_id}_{message_id}_Regular")],
|
| 133 |
+
]),
|
| 134 |
+
)
|
| 135 |
+
"""#await FileStream.delete_messages(chat_id=user_id,message_ids=response_id)
|
| 136 |
+
await FileStream.send_poll(
|
| 137 |
+
type= enums.PollType.REGULAR,
|
| 138 |
+
reply_to_message_id=message_id,
|
| 139 |
+
explanation=f"{file_caption}",
|
| 140 |
+
question=f"{message_id}_{user_id}_{response_id}_File Name :\n{file_caption}",
|
| 141 |
+
options=["Movie", "WebSeries", "Anime", "Documentary", "Regular"],
|
| 142 |
+
allows_multiple_answers=True,
|
| 143 |
+
chat_id=user_id
|
| 144 |
+
)
|
| 145 |
+
"""
|
| 146 |
+
except Exception as e:
|
| 147 |
+
print(f"An error occurred: {str(e)}")
|
| 148 |
+
await FileStream.send_message(
|
| 149 |
+
chat_id=Telegram.ULOG_GROUP,
|
| 150 |
+
text=f"An error occurred: {str(e)}"
|
| 151 |
+
)
|
| 152 |
+
|
| 153 |
+
elif usr_cmd[0] == "pubup":
|
| 154 |
+
try:
|
| 155 |
+
user_id = str(usr_cmd[1])
|
| 156 |
+
message_id = int(usr_cmd[2])
|
| 157 |
+
msg_type = usr_cmd[3]
|
| 158 |
+
#response_id = int(usr_cmd[3])
|
| 159 |
+
message = await FileStream.get_messages(user_id, message_id)
|
| 160 |
+
#response = await FileStream.get_messages(user_id, response_id)
|
| 161 |
+
#print("Response Update:",update,f"Message ID:{response_id}")
|
| 162 |
+
instruction = {
|
| 163 |
+
"privacy_type": "PUBLIC",
|
| 164 |
+
"user_id": user_id,
|
| 165 |
+
"user_type": "TELEGRAM"
|
| 166 |
+
}
|
| 167 |
+
file_caption = getattr(message, "caption", f"{get_name(message)}" ) or "None/Unknown"
|
| 168 |
+
file_name = get_name(message)
|
| 169 |
+
print("Detail",file_caption,"\nFile:",file_name)
|
| 170 |
+
"""
|
| 171 |
+
await FileStream.delete_messages(
|
| 172 |
+
chat_id=user_id,
|
| 173 |
+
message_ids=message_id
|
| 174 |
+
)
|
| 175 |
+
await FileStream.send_poll(
|
| 176 |
+
type= enums.PollType.REGULAR,
|
| 177 |
+
reply_to_message_id=message_id,
|
| 178 |
+
question="Is this a poll question?",
|
| 179 |
+
options=["Movie", "WebSeries", "Anime", "Documentary", "Regular"],
|
| 180 |
+
allows_multiple_answers=True,
|
| 181 |
+
chat_id=user_id
|
| 182 |
+
)
|
| 183 |
+
|
| 184 |
+
functions.messages.EditMessage(
|
| 185 |
+
peer=user_id,
|
| 186 |
+
id=message_id,
|
| 187 |
+
media=InputMediaPoll(
|
| 188 |
+
poll=Poll(
|
| 189 |
+
id=FileStream.rnd_id(),
|
| 190 |
+
question="Is this a poll question?",
|
| 191 |
+
answers=["Movie", "WebSeries", "Anime", "Documentary", "Regular"],
|
| 192 |
+
multiple_choice=True,
|
| 193 |
+
quiz=False,
|
| 194 |
+
)
|
| 195 |
+
),
|
| 196 |
+
)
|
| 197 |
+
|
| 198 |
+
print("Poll function and all initializers executed successfully.")
|
| 199 |
+
print("dir(Poll):", dir(Poll))
|
| 200 |
+
print("Poll.__init__:", Poll.__init__)
|
| 201 |
+
print("Poll.__init__ inputs:", Poll.__init__.__code__.co_varnames)
|
| 202 |
+
print("InputMediaPoll.__init__ inputs:", InputMediaPoll.__init__.__code__.co_varnames)
|
| 203 |
+
update=await FileStream.edit_message_media(
|
| 204 |
+
chat_id=user_id,
|
| 205 |
+
message_id=response_id,
|
| 206 |
+
media=InputMediaPoll(
|
| 207 |
+
caption="Is this a poll question?",
|
| 208 |
+
poll=Poll(
|
| 209 |
+
id=FileStream.rnd_id(),
|
| 210 |
+
question="Is this a poll question?",
|
| 211 |
+
answers=[
|
| 212 |
+
PollAnswer(text="Movie", option=bytes([1])),
|
| 213 |
+
PollAnswer(text="WebSeries", option=bytes([2])),
|
| 214 |
+
PollAnswer(text="Anime", option=bytes([3])),
|
| 215 |
+
PollAnswer(text="Documentary", option=bytes([4]))
|
| 216 |
+
],
|
| 217 |
+
closed=False,
|
| 218 |
+
public_voters=True,
|
| 219 |
+
multiple_choice=True,
|
| 220 |
+
quiz=False,
|
| 221 |
+
close_period=None,
|
| 222 |
+
close_date=None
|
| 223 |
+
),
|
| 224 |
+
)
|
| 225 |
+
)
|
| 226 |
+
print("Update:",update)
|
| 227 |
+
|
| 228 |
+
PollAnswer(
|
| 229 |
+
id=FileStream.rnd_id(),
|
| 230 |
+
question="Is this a poll question?",
|
| 231 |
+
answers=["Movie","WebSeries"),
|
| 232 |
+
PollAnswer(text="Anime"),
|
| 233 |
+
PollAnswer(text="Documentary"),
|
| 234 |
+
PollAnswer(text="Regular")
|
| 235 |
+
],
|
| 236 |
+
multiple_choice=True,
|
| 237 |
+
quiz=False,
|
| 238 |
+
answers=[
|
| 239 |
+
PollAnswer("Movie"),
|
| 240 |
+
PollAnswer(text="WebSeries"),
|
| 241 |
+
PollAnswer(text="Anime"),
|
| 242 |
+
PollAnswer(text="Documentary"),
|
| 243 |
+
PollAnswer(text="Regular")
|
| 244 |
+
],
|
| 245 |
+
await FileStream.send_poll(
|
| 246 |
+
type= enums.PollType.REGULAR,
|
| 247 |
+
reply_to_message_id=message_id,
|
| 248 |
+
question="Is this a poll question?",
|
| 249 |
+
options=["Movie", "WebSeries", "Anime", "Documentary", "Regular"],
|
| 250 |
+
allows_multiple_answers=True,
|
| 251 |
+
chat_id=user_id
|
| 252 |
+
)
|
| 253 |
+
|
| 254 |
+
#type=enums.PollType.QUIZ,
|
| 255 |
+
print(polls)
|
| 256 |
+
"""
|
| 257 |
+
file_info = get_file_info(message, instruction)
|
| 258 |
+
# Here we are Adding the File Into the database First
|
| 259 |
+
inserted_id = await db.add_file(file_info)
|
| 260 |
+
await get_file_ids(False, inserted_id, message)
|
| 261 |
+
#All the Time Get_file_ids should be called before update privacy or else tagged_users will be {}
|
| 262 |
+
await db.update_privacy(file_info)
|
| 263 |
+
reply_markup, stream_text = await gen_link(_id=inserted_id)
|
| 264 |
+
await update.message.edit_text(
|
| 265 |
+
text=stream_text,
|
| 266 |
+
parse_mode=ParseMode.HTML,
|
| 267 |
+
disable_web_page_preview=True,
|
| 268 |
+
reply_markup=reply_markup,
|
| 269 |
+
)
|
| 270 |
+
except FloodWait as e:
|
| 271 |
+
print(f"Sleeping for {str(e.value)}s")
|
| 272 |
+
await asyncio.sleep(e.value)
|
| 273 |
+
await FileStream.send_message(
|
| 274 |
+
chat_id=Telegram.ULOG_GROUP,
|
| 275 |
+
text=
|
| 276 |
+
f"Gᴏᴛ FʟᴏᴏᴅWᴀɪᴛ ᴏғ {str(e.value)}s ғʀᴏᴍ [{message.from_user.first_name}](tg://user?id={message.from_user.id})\n\n**ᴜsᴇʀ ɪᴅ :** `{str(message.from_user.id)}`",
|
| 277 |
+
disable_web_page_preview=True,
|
| 278 |
+
parse_mode=ParseMode.MARKDOWN)
|
| 279 |
+
except Exception as e:
|
| 280 |
+
print(f"An error occurred: {str(e)}")
|
| 281 |
+
await FileStream.send_message(
|
| 282 |
+
chat_id=Telegram.ULOG_GROUP,
|
| 283 |
+
text=f"An error occurred: {str(e)}"
|
| 284 |
+
)
|
| 285 |
+
|
| 286 |
+
elif usr_cmd[0] == "privup":
|
| 287 |
+
try:
|
| 288 |
+
user_id = str(usr_cmd[1])
|
| 289 |
+
message_id = int(usr_cmd[2])
|
| 290 |
+
message = await FileStream.get_messages(user_id, message_id)
|
| 291 |
+
instruction = {
|
| 292 |
+
|
| 293 |
+
"privacy_type": "PRIVATE",
|
| 294 |
+
"user_id": user_id,
|
| 295 |
+
"user_type": "TELEGRAM"
|
| 296 |
+
}
|
| 297 |
+
file_info = get_file_info(message, instruction)
|
| 298 |
+
# Here we are Adding the File Into the database First
|
| 299 |
+
db_id = await db.add_file(file_info)
|
| 300 |
+
await get_file_ids(False, db_id, message)
|
| 301 |
+
|
| 302 |
+
if True:
|
| 303 |
+
file_info = await db.get_file(db_id)
|
| 304 |
+
reply_markup, stream_text = await priv_func(file_info['file']['file_name'], file_info['file']['file_size'])
|
| 305 |
+
|
| 306 |
+
await update.message.edit_text(
|
| 307 |
+
text=stream_text,
|
| 308 |
+
parse_mode=ParseMode.HTML,
|
| 309 |
+
disable_web_page_preview=True,
|
| 310 |
+
reply_markup=reply_markup,
|
| 311 |
+
)
|
| 312 |
+
except FloodWait as e:
|
| 313 |
+
print(f"Sleeping for {str(e.value)}s")
|
| 314 |
+
await asyncio.sleep(e.value)
|
| 315 |
+
await FileStream.send_message(
|
| 316 |
+
chat_id=Telegram.ULOG_GROUP,
|
| 317 |
+
text=
|
| 318 |
+
f"Gᴏᴛ FʟᴏᴏᴅWᴀɪᴛ ᴏғ {str(e.value)}s ғʀᴏᴍ [{message.from_user.first_name}](tg://user?id={message.from_user.id})\n\n**ᴜsᴇʀ ɪᴅ :** `{str(message.from_user.id)}`",
|
| 319 |
+
disable_web_page_preview=True,
|
| 320 |
+
parse_mode=ParseMode.MARKDOWN)
|
| 321 |
+
|
| 322 |
+
elif usr_cmd[0] == "userfiles":
|
| 323 |
+
file_list, total_files = await gen_file_list_button(int(usr_cmd[1]), update.from_user.id)
|
| 324 |
+
await update.message.edit_caption(
|
| 325 |
+
caption="Total files: {}".format(total_files),
|
| 326 |
+
reply_markup=InlineKeyboardMarkup(file_list))
|
| 327 |
+
|
| 328 |
+
elif usr_cmd[0] == "userprivfiles":
|
| 329 |
+
file_list, total_files = await gen_privfile_list_button(
|
| 330 |
+
int(usr_cmd[1]), update.from_user.id)
|
| 331 |
+
await update.message.edit_caption(
|
| 332 |
+
caption="Total files: {}".format(total_files),
|
| 333 |
+
reply_markup=InlineKeyboardMarkup(file_list))
|
| 334 |
+
|
| 335 |
+
elif usr_cmd[0] == "userallfiles":
|
| 336 |
+
file_list, total_files = await gen_allfile_list_button(
|
| 337 |
+
int(usr_cmd[1]), update.from_user.id)
|
| 338 |
+
await update.message.edit_caption(
|
| 339 |
+
caption="Total files: {}".format(total_files),
|
| 340 |
+
reply_markup=InlineKeyboardMarkup(file_list))
|
| 341 |
+
|
| 342 |
+
elif usr_cmd[0] == "myfile":
|
| 343 |
+
await gen_file_menu(usr_cmd[1], usr_cmd[2], update)
|
| 344 |
+
return
|
| 345 |
+
elif usr_cmd[0] == "allfile":
|
| 346 |
+
await gen_allfile_menu(usr_cmd[1], usr_cmd[2], update)
|
| 347 |
+
return
|
| 348 |
+
elif usr_cmd[0] == "myprivfile":
|
| 349 |
+
await gen_privfile_menu(usr_cmd[1], usr_cmd[2], update)
|
| 350 |
+
return
|
| 351 |
+
elif usr_cmd[0] == "sendfile":
|
| 352 |
+
myfile = await db.get_file(usr_cmd[1])
|
| 353 |
+
file_name = myfile['file']['file_name']
|
| 354 |
+
await update.answer(f"Sending File {file_name}")
|
| 355 |
+
await update.message.reply_cached_media(myfile['file']['file_id'],caption=f'**{file_name}**')
|
| 356 |
+
else:
|
| 357 |
+
await update.message.delete()
|
| 358 |
+
|
| 359 |
+
#---------------------[ MY FILES FUNC ]---------------------#
|
| 360 |
+
|
| 361 |
+
|
| 362 |
+
async def gen_file_list_button(file_list_no: int, user_id: int):
|
| 363 |
+
|
| 364 |
+
file_range = [file_list_no * 10 - 10 + 1, file_list_no * 10]
|
| 365 |
+
user_files, total_files = await db.find_files(user_id, file_range)
|
| 366 |
+
|
| 367 |
+
file_list = []
|
| 368 |
+
async for x in user_files:
|
| 369 |
+
file_list.append([
|
| 370 |
+
InlineKeyboardButton(f"📦 {x['file']['caption']}",
|
| 371 |
+
callback_data=f"myfile_{x['_id']}_{file_list_no}")
|
| 372 |
+
])
|
| 373 |
+
if total_files > 10:
|
| 374 |
+
file_list.append([
|
| 375 |
+
InlineKeyboardButton(
|
| 376 |
+
"◄",
|
| 377 |
+
callback_data="{}".format("userfiles_" +
|
| 378 |
+
str(file_list_no -
|
| 379 |
+
1) if file_list_no > 1 else 'N/A')),
|
| 380 |
+
InlineKeyboardButton(f"{file_list_no}/{math.ceil(total_files/10)}",
|
| 381 |
+
callback_data="N/A"),
|
| 382 |
+
InlineKeyboardButton(
|
| 383 |
+
"►",
|
| 384 |
+
callback_data="{}".format("userfiles_" +
|
| 385 |
+
str(file_list_no +
|
| 386 |
+
1) if total_files > file_list_no *
|
| 387 |
+
10 else 'N/A'))
|
| 388 |
+
])
|
| 389 |
+
if not file_list:
|
| 390 |
+
file_list.append([InlineKeyboardButton("ᴇᴍᴘᴛʏ", callback_data="N/A")])
|
| 391 |
+
file_list.append([InlineKeyboardButton("ᴄʟᴏsᴇ", callback_data="close")])
|
| 392 |
+
return file_list, total_files
|
| 393 |
+
|
| 394 |
+
|
| 395 |
+
async def gen_file_menu(_id, file_list_no, update: CallbackQuery):
|
| 396 |
+
try:
|
| 397 |
+
myfile_info = await db.get_file(_id)
|
| 398 |
+
except FileNotFound:
|
| 399 |
+
await update.answer("File Not Found")
|
| 400 |
+
return
|
| 401 |
+
|
| 402 |
+
file_id = FileId.decode(myfile_info['file']['file_id'])
|
| 403 |
+
|
| 404 |
+
if file_id.file_type in PHOTO_TYPES:
|
| 405 |
+
file_type = "Image"
|
| 406 |
+
elif file_id.file_type == FileType.VOICE:
|
| 407 |
+
file_type = "Voice"
|
| 408 |
+
elif file_id.file_type in (FileType.VIDEO, FileType.ANIMATION,
|
| 409 |
+
FileType.VIDEO_NOTE):
|
| 410 |
+
file_type = "Video"
|
| 411 |
+
elif file_id.file_type == FileType.DOCUMENT:
|
| 412 |
+
file_type = "Document"
|
| 413 |
+
elif file_id.file_type == FileType.STICKER:
|
| 414 |
+
file_type = "Sticker"
|
| 415 |
+
elif file_id.file_type == FileType.AUDIO:
|
| 416 |
+
file_type = "Audio"
|
| 417 |
+
else:
|
| 418 |
+
file_type = "Unknown"
|
| 419 |
+
|
| 420 |
+
page_link = f"{Server.URL}app/watch/{myfile_info['_id']}"
|
| 421 |
+
stream_link = f"{Server.URL}api/dl/{myfile_info['_id']}"
|
| 422 |
+
if "video" in file_type.lower():
|
| 423 |
+
MYFILES_BUTTONS = InlineKeyboardMarkup([
|
| 424 |
+
[
|
| 425 |
+
InlineKeyboardButton("sᴛʀᴇᴀᴍ", url=page_link),
|
| 426 |
+
InlineKeyboardButton("ᴅᴏᴡɴʟᴏᴀᴅ", url=stream_link)
|
| 427 |
+
],
|
| 428 |
+
[
|
| 429 |
+
InlineKeyboardButton(
|
| 430 |
+
"ɢᴇᴛ ғɪʟᴇ", callback_data=f"sendfile_{myfile_info['_id']}"),
|
| 431 |
+
InlineKeyboardButton(
|
| 432 |
+
"ʀᴇᴠᴏᴋᴇ ғɪʟᴇ",
|
| 433 |
+
callback_data=f"msgdelete_{myfile_info['_id']}_{file_list_no}")
|
| 434 |
+
],
|
| 435 |
+
[
|
| 436 |
+
InlineKeyboardButton(
|
| 437 |
+
"ʙᴀᴄᴋ", callback_data="userfiles_{}".format(file_list_no))
|
| 438 |
+
]
|
| 439 |
+
])
|
| 440 |
+
else:
|
| 441 |
+
MYFILES_BUTTONS = InlineKeyboardMarkup([
|
| 442 |
+
[InlineKeyboardButton("ᴅᴏᴡɴʟᴏᴀᴅ", url=stream_link)],
|
| 443 |
+
[
|
| 444 |
+
InlineKeyboardButton(
|
| 445 |
+
"ɢᴇᴛ ғɪʟᴇ", callback_data=f"sendfile_{myfile_info['_id']}"),
|
| 446 |
+
InlineKeyboardButton(
|
| 447 |
+
"ʀᴇᴠᴏᴋᴇ ғɪʟᴇ",
|
| 448 |
+
callback_data=f"msgdelete_{myfile_info['_id']}_{file_list_no}")
|
| 449 |
+
],
|
| 450 |
+
[
|
| 451 |
+
InlineKeyboardButton(
|
| 452 |
+
"ʙᴀᴄᴋ", callback_data="userfiles_{}".format(file_list_no))
|
| 453 |
+
]
|
| 454 |
+
])
|
| 455 |
+
|
| 456 |
+
TiMe = myfile_info['time']
|
| 457 |
+
if type(TiMe) == float:
|
| 458 |
+
date = datetime.datetime.fromtimestamp(TiMe)
|
| 459 |
+
await update.edit_message_caption(
|
| 460 |
+
caption="**File Name :** `{}`\n**File Size :** `{}`\n**File Type :** `{}`\n**Created On :** `{}`"
|
| 461 |
+
.format(myfile_info['file']['file_name'],
|
| 462 |
+
humanbytes(int(myfile_info['file']['file_size'])), file_type,
|
| 463 |
+
TiMe if isinstance(TiMe, str) else date.date()), reply_markup=MYFILES_BUTTONS)
|
| 464 |
+
|
| 465 |
+
|
| 466 |
+
#################------ private file list
|
| 467 |
+
async def gen_privfile_list_button(file_list_no: int, user_id: int):
|
| 468 |
+
|
| 469 |
+
file_range = [file_list_no * 10 - 10 + 1, file_list_no * 10]
|
| 470 |
+
user_files, total_files = await db.find_privfiles(user_id, file_range)
|
| 471 |
+
|
| 472 |
+
file_list = []
|
| 473 |
+
async for x in user_files:
|
| 474 |
+
file_list.append([
|
| 475 |
+
InlineKeyboardButton(
|
| 476 |
+
f"📦 {x['file']['caption']}",
|
| 477 |
+
callback_data=f"myprivfile_{x['_id']}_{file_list_no}")
|
| 478 |
+
])
|
| 479 |
+
if total_files > 10:
|
| 480 |
+
file_list.append([
|
| 481 |
+
InlineKeyboardButton(
|
| 482 |
+
"◄",
|
| 483 |
+
callback_data="{}".format("userprivfiles_" +
|
| 484 |
+
str(file_list_no -
|
| 485 |
+
1) if file_list_no > 1 else 'N/A')),
|
| 486 |
+
InlineKeyboardButton(f"{file_list_no}/{math.ceil(total_files/10)}",
|
| 487 |
+
callback_data="N/A"),
|
| 488 |
+
InlineKeyboardButton(
|
| 489 |
+
"►",
|
| 490 |
+
callback_data="{}".format("userprivfiles_" +
|
| 491 |
+
str(file_list_no +
|
| 492 |
+
1) if total_files > file_list_no *
|
| 493 |
+
10 else 'N/A'))
|
| 494 |
+
])
|
| 495 |
+
if not file_list:
|
| 496 |
+
file_list.append([InlineKeyboardButton("ᴇᴍᴘᴛʏ", callback_data="N/A")])
|
| 497 |
+
file_list.append([InlineKeyboardButton("ᴄʟᴏsᴇ", callback_data="close")])
|
| 498 |
+
return file_list, total_files
|
| 499 |
+
|
| 500 |
+
|
| 501 |
+
async def gen_privfile_menu(_id, file_list_no, update: CallbackQuery):
|
| 502 |
+
try:
|
| 503 |
+
myfile_info = await db.get_privfile(_id)
|
| 504 |
+
except FileNotFound:
|
| 505 |
+
await update.answer("File Not Found")
|
| 506 |
+
return
|
| 507 |
+
|
| 508 |
+
file_id = FileId.decode(myfile_info['file']['file_id'])
|
| 509 |
+
|
| 510 |
+
if file_id.file_type in PHOTO_TYPES:
|
| 511 |
+
file_type = "Image"
|
| 512 |
+
elif file_id.file_type == FileType.VOICE:
|
| 513 |
+
file_type = "Voice"
|
| 514 |
+
elif file_id.file_type in (FileType.VIDEO, FileType.ANIMATION,
|
| 515 |
+
FileType.VIDEO_NOTE):
|
| 516 |
+
file_type = "Video"
|
| 517 |
+
elif file_id.file_type == FileType.DOCUMENT:
|
| 518 |
+
file_type = "Document"
|
| 519 |
+
elif file_id.file_type == FileType.STICKER:
|
| 520 |
+
file_type = "Sticker"
|
| 521 |
+
elif file_id.file_type == FileType.AUDIO:
|
| 522 |
+
file_type = "Audio"
|
| 523 |
+
else:
|
| 524 |
+
file_type = "Unknown"
|
| 525 |
+
|
| 526 |
+
page_link = f"{Server.URL}app/watch/{myfile_info['_id']}"
|
| 527 |
+
stream_link = f"{Server.URL}api/dl/{myfile_info['_id']}"
|
| 528 |
+
if "video" in file_type.lower():
|
| 529 |
+
MYFILES_BUTTONS = InlineKeyboardMarkup([
|
| 530 |
+
[
|
| 531 |
+
InlineKeyboardButton("sᴛʀᴇᴀᴍ", url=page_link),
|
| 532 |
+
InlineKeyboardButton("ᴅᴏᴡɴʟᴏᴀᴅ", url=stream_link)
|
| 533 |
+
],
|
| 534 |
+
[
|
| 535 |
+
InlineKeyboardButton(
|
| 536 |
+
"ɢᴇᴛ ғɪʟᴇ", callback_data=f"sendfile_{myfile_info['_id']}"),
|
| 537 |
+
InlineKeyboardButton(
|
| 538 |
+
"ʀᴇᴠᴏᴋᴇ ғɪʟᴇ",
|
| 539 |
+
callback_data=f"msgdelete_{myfile_info['_id']}_{file_list_no}")
|
| 540 |
+
],
|
| 541 |
+
[
|
| 542 |
+
InlineKeyboardButton(
|
| 543 |
+
"ʙᴀᴄᴋ", callback_data="userfiles_{}".format(file_list_no))
|
| 544 |
+
]
|
| 545 |
+
])
|
| 546 |
+
else:
|
| 547 |
+
MYFILES_BUTTONS = InlineKeyboardMarkup([
|
| 548 |
+
[InlineKeyboardButton("ᴅᴏᴡɴʟᴏᴀᴅ", url=stream_link)],
|
| 549 |
+
[
|
| 550 |
+
InlineKeyboardButton(
|
| 551 |
+
"ɢᴇᴛ ғɪʟᴇ", callback_data=f"sendfile_{myfile_info['_id']}"),
|
| 552 |
+
InlineKeyboardButton(
|
| 553 |
+
"ʀᴇᴠᴏᴋᴇ ғɪʟᴇ",
|
| 554 |
+
callback_data=f"msgdelete_{myfile_info['_id']}_{file_list_no}")
|
| 555 |
+
],
|
| 556 |
+
[
|
| 557 |
+
InlineKeyboardButton(
|
| 558 |
+
"ʙᴀᴄᴋ", callback_data="userfiles_{}".format(file_list_no))
|
| 559 |
+
]
|
| 560 |
+
])
|
| 561 |
+
|
| 562 |
+
TiMe = myfile_info['time']
|
| 563 |
+
if type(TiMe) == float:
|
| 564 |
+
date = datetime.datetime.fromtimestamp(TiMe)
|
| 565 |
+
await update.edit_message_caption(
|
| 566 |
+
caption=
|
| 567 |
+
"**File Name :** `{}`\n**File Size :** `{}`\n**File Type :** `{}`\n**Created On :** `{}`"
|
| 568 |
+
.format(myfile_info['file_name'],
|
| 569 |
+
humanbytes(int(myfile_info['file']['file_size'])), file_type,
|
| 570 |
+
TiMe if isinstance(TiMe, str) else date.date()),
|
| 571 |
+
reply_markup=MYFILES_BUTTONS)
|
| 572 |
+
|
| 573 |
+
|
| 574 |
+
##################---- all file function-----##################
|
| 575 |
+
async def gen_allfile_list_button(file_list_no: int, user_id: int):
|
| 576 |
+
|
| 577 |
+
file_range = [file_list_no * 10 - 10 + 1, file_list_no * 10]
|
| 578 |
+
user_files, total_files = await db.find_all_files(file_range)
|
| 579 |
+
|
| 580 |
+
file_list = []
|
| 581 |
+
async for x in user_files:
|
| 582 |
+
file_list.append([
|
| 583 |
+
InlineKeyboardButton(
|
| 584 |
+
f"📦 {x['file']['caption']}",
|
| 585 |
+
callback_data=f"allfile_{x['_id']}_{file_list_no}")
|
| 586 |
+
])
|
| 587 |
+
if total_files > 10:
|
| 588 |
+
file_list.append([
|
| 589 |
+
InlineKeyboardButton(
|
| 590 |
+
"◄",
|
| 591 |
+
callback_data="{}".format("userallfiles_" +
|
| 592 |
+
str(file_list_no -
|
| 593 |
+
1) if file_list_no > 1 else 'N/A')),
|
| 594 |
+
InlineKeyboardButton(f"{file_list_no}/{math.ceil(total_files/10)}",
|
| 595 |
+
callback_data="N/A"),
|
| 596 |
+
InlineKeyboardButton(
|
| 597 |
+
"►",
|
| 598 |
+
callback_data="{}".format("userallfiles_" +
|
| 599 |
+
str(file_list_no +
|
| 600 |
+
1) if total_files > file_list_no *
|
| 601 |
+
10 else 'N/A'))
|
| 602 |
+
])
|
| 603 |
+
if not file_list:
|
| 604 |
+
file_list.append([InlineKeyboardButton("ᴇᴍᴘᴛʏ", callback_data="N/A")])
|
| 605 |
+
file_list.append([InlineKeyboardButton("ᴄʟᴏsᴇ", callback_data="close")])
|
| 606 |
+
return file_list, total_files
|
| 607 |
+
|
| 608 |
+
|
| 609 |
+
async def gen_allfile_menu(_id, file_list_no, update: CallbackQuery):
|
| 610 |
+
try:
|
| 611 |
+
myfile_info = await db.get_file(_id)
|
| 612 |
+
except FileNotFound:
|
| 613 |
+
await update.answer("File Not Found")
|
| 614 |
+
return
|
| 615 |
+
|
| 616 |
+
file_id = FileId.decode(myfile_info['file']['file_id'])
|
| 617 |
+
|
| 618 |
+
if file_id.file_type in PHOTO_TYPES:
|
| 619 |
+
file_type = "Image"
|
| 620 |
+
elif file_id.file_type == FileType.VOICE:
|
| 621 |
+
file_type = "Voice"
|
| 622 |
+
elif file_id.file_type in (FileType.VIDEO, FileType.ANIMATION,
|
| 623 |
+
FileType.VIDEO_NOTE):
|
| 624 |
+
file_type = "Video"
|
| 625 |
+
elif file_id.file_type == FileType.DOCUMENT:
|
| 626 |
+
file_type = "Document"
|
| 627 |
+
elif file_id.file_type == FileType.STICKER:
|
| 628 |
+
file_type = "Sticker"
|
| 629 |
+
elif file_id.file_type == FileType.AUDIO:
|
| 630 |
+
file_type = "Audio"
|
| 631 |
+
else:
|
| 632 |
+
file_type = "Unknown"
|
| 633 |
+
|
| 634 |
+
page_link = f"{Server.URL}app/watch/{myfile_info['_id']}"
|
| 635 |
+
stream_link = f"{Server.URL}api/dl/{myfile_info['_id']}"
|
| 636 |
+
if "video" in file_type.lower():
|
| 637 |
+
MYFILES_BUTTONS = InlineKeyboardMarkup([
|
| 638 |
+
[
|
| 639 |
+
InlineKeyboardButton("sᴛʀᴇᴀᴍ", url=page_link),
|
| 640 |
+
InlineKeyboardButton("ᴅᴏᴡɴʟᴏᴀᴅ", url=stream_link)
|
| 641 |
+
],
|
| 642 |
+
[
|
| 643 |
+
InlineKeyboardButton(
|
| 644 |
+
"ɢᴇᴛ ғɪʟᴇ", callback_data=f"sendfile_{myfile_info['_id']}"),
|
| 645 |
+
InlineKeyboardButton(
|
| 646 |
+
"ʀᴇᴠᴏᴋᴇ ғɪʟᴇ",
|
| 647 |
+
callback_data=f"msgdelete_{myfile_info['_id']}_{file_list_no}")
|
| 648 |
+
],
|
| 649 |
+
[
|
| 650 |
+
InlineKeyboardButton(
|
| 651 |
+
"ʙᴀᴄᴋ", callback_data="userfiles_{}".format(file_list_no))
|
| 652 |
+
]
|
| 653 |
+
])
|
| 654 |
+
else:
|
| 655 |
+
MYFILES_BUTTONS = InlineKeyboardMarkup([
|
| 656 |
+
[InlineKeyboardButton("ᴅᴏᴡɴʟᴏᴀᴅ", url=stream_link)],
|
| 657 |
+
[
|
| 658 |
+
InlineKeyboardButton(
|
| 659 |
+
"ɢᴇᴛ ғɪʟᴇ", callback_data=f"sendfile_{myfile_info['_id']}"),
|
| 660 |
+
InlineKeyboardButton(
|
| 661 |
+
"ʀᴇᴠᴏᴋᴇ ғɪʟᴇ",
|
| 662 |
+
callback_data=f"msgdelete_{myfile_info['_id']}_{file_list_no}")
|
| 663 |
+
],
|
| 664 |
+
[
|
| 665 |
+
InlineKeyboardButton(
|
| 666 |
+
"ʙᴀᴄᴋ", callback_data="userfiles_{}".format(file_list_no))
|
| 667 |
+
]
|
| 668 |
+
])
|
| 669 |
+
|
| 670 |
+
TiMe = myfile_info['time']
|
| 671 |
+
if type(TiMe) == float:
|
| 672 |
+
date = datetime.datetime.fromtimestamp(TiMe)
|
| 673 |
+
await update.edit_message_caption(
|
| 674 |
+
caption=
|
| 675 |
+
"**File Name :** `{}`\n**File Size :** `{}`\n**File Type :** `{}`\n**Created On :** `{}`"
|
| 676 |
+
.format(myfile_info['file']['file_name'],
|
| 677 |
+
humanbytes(int(myfile_info['file']['file_size'])), file_type,
|
| 678 |
+
TiMe if isinstance(TiMe, str) else date.date()),
|
| 679 |
+
reply_markup=MYFILES_BUTTONS)
|
| 680 |
+
|
| 681 |
+
|
| 682 |
+
async def delete_user_file(_id, file_list_no: int, update: CallbackQuery):
|
| 683 |
+
|
| 684 |
+
try:
|
| 685 |
+
myfile_info = await db.get_file(_id)
|
| 686 |
+
if not myfile_info:
|
| 687 |
+
|
| 688 |
+
myfile_info = await db.get_privfile(db_id)
|
| 689 |
+
await db.delete_one_privfile(myfile_info['_id'])
|
| 690 |
+
#await db.count_links(update.from_user.id, "-")
|
| 691 |
+
await update.message.edit_caption(
|
| 692 |
+
caption="**Fɪʟᴇ Dᴇʟᴇᴛᴇᴅ Sᴜᴄᴄᴇssғᴜʟʟʏ !**" +
|
| 693 |
+
update.message.caption.replace("Cᴏɴғɪʀᴍ ʏᴏᴜ ᴡᴀɴᴛ ᴛᴏ ᴅᴇʟᴇᴛᴇ ᴛʜᴇ Fɪʟᴇ",
|
| 694 |
+
""),
|
| 695 |
+
reply_markup=InlineKeyboardMarkup(
|
| 696 |
+
[[InlineKeyboardButton("ʙᴀᴄᴋ", callback_data=f"userfiles_1")]]))
|
| 697 |
+
else:
|
| 698 |
+
await db.delete_one_file(myfile_info['_id'])
|
| 699 |
+
await db.count_links(update.from_user.id, "-")
|
| 700 |
+
await update.message.edit_caption(
|
| 701 |
+
caption="**Fɪʟᴇ Dᴇʟᴇᴛᴇᴅ Sᴜᴄᴄᴇssғᴜʟʟʏ !**" +
|
| 702 |
+
update.message.caption.replace("Cᴏɴғɪʀᴍ ʏᴏᴜ ᴡᴀɴᴛ ᴛᴏ ᴅᴇʟᴇᴛᴇ ᴛʜᴇ Fɪʟᴇ",
|
| 703 |
+
""),
|
| 704 |
+
reply_markup=InlineKeyboardMarkup(
|
| 705 |
+
[[InlineKeyboardButton("ʙᴀᴄᴋ", callback_data=f"userfiles_1")]]))
|
| 706 |
+
|
| 707 |
+
except FileNotFound:
|
| 708 |
+
await update.answer("File Already Deleted")
|
| 709 |
+
return
|
| 710 |
+
|
| 711 |
+
|
| 712 |
+
async def delete_user_filex(_id, update: CallbackQuery):
|
| 713 |
+
|
| 714 |
+
try:
|
| 715 |
+
myfile_info = await db.get_file(_id)
|
| 716 |
+
if not myfile_info:
|
| 717 |
+
|
| 718 |
+
myfile_info = await db.get_privfile(_id)
|
| 719 |
+
await db.delete_one_privfile(myfile_info['_id'])
|
| 720 |
+
await update.message.edit_caption(
|
| 721 |
+
caption="**Fɪʟᴇ Dᴇʟᴇᴛᴇᴅ Sᴜᴄᴄᴇssғᴜʟʟʏ !**\n\n",
|
| 722 |
+
reply_markup=InlineKeyboardMarkup(
|
| 723 |
+
[[InlineKeyboardButton("ᴄʟᴏsᴇ", callback_data=f"close")]]))
|
| 724 |
+
else:
|
| 725 |
+
await db.delete_one_file(myfile_info['_id'])
|
| 726 |
+
await db.count_links(update.from_user.id, "-")
|
| 727 |
+
await update.message.edit_caption(
|
| 728 |
+
caption="**Fɪʟᴇ Dᴇʟᴇᴛᴇᴅ Sᴜᴄᴄᴇssғᴜʟʟʏ !**\n\n",
|
| 729 |
+
reply_markup=InlineKeyboardMarkup(
|
| 730 |
+
[[InlineKeyboardButton("ᴄʟᴏsᴇ", callback_data=f"close")]]))
|
| 731 |
+
|
| 732 |
+
except FileNotFound:
|
| 733 |
+
await update.answer("File Already Deleted")
|
| 734 |
+
return
|