BinaryONe commited on
Commit
ae409d1
·
1 Parent(s): a8dd6ac

Changes in Database

Browse files
FileStream/Tools/progress.py CHANGED
@@ -42,9 +42,6 @@ from FileStream.utils.FileProcessors.human_readable import humanbytes
42
  from FileStream.utils.FileProcessors.file_properties import get_file_ids,get_file_info
43
 
44
 
45
-
46
-
47
-
48
  async def progress(current, total, progress_args):
49
  progress_text = LANG.BASIC_PRIV_FILE.format(
50
  progress_args[1], humanbytes(progress_args[2]))
 
42
  from FileStream.utils.FileProcessors.file_properties import get_file_ids,get_file_info
43
 
44
 
 
 
 
45
  async def progress(current, total, progress_args):
46
  progress_text = LANG.BASIC_PRIV_FILE.format(
47
  progress_args[1], humanbytes(progress_args[2]))
FileStream/__main__.py CHANGED
@@ -48,6 +48,7 @@ async def start_services():
48
  FileStream.id = bot_info.id
49
  FileStream.username = bot_info.username
50
  FileStream.fname = bot_info.first_name
 
51
  print("------------------------------ DONE ------------------------------\n")
52
 
53
  print("---------------------- Initializing Clients ----------------------")
 
48
  FileStream.id = bot_info.id
49
  FileStream.username = bot_info.username
50
  FileStream.fname = bot_info.first_name
51
+ await FileStream.get_users(Telegram.DATA_SOURCES + [Telegram.FLOG_CHANNEL])
52
  print("------------------------------ DONE ------------------------------\n")
53
 
54
  print("---------------------- Initializing Clients ----------------------")
FileStream/bot/plugins/FileHandlers/callback.py CHANGED
@@ -109,12 +109,12 @@ async def cb_data(bot: Client, update: CallbackQuery):
109
 
110
  elif usr_cmd[0] == "mainstream":
111
  _id = usr_cmd[1]
112
- reply_markup, stream_text = await gen_link(_id=_id)
113
  await update.message.edit_text(
114
- text=stream_text,
115
  parse_mode=ParseMode.HTML,
116
  disable_web_page_preview=True,
117
- reply_markup=reply_markup,
118
  )
119
 
120
  elif usr_cmd[0] == "pubup":
@@ -164,10 +164,10 @@ async def cb_data(bot: Client, update: CallbackQuery):
164
  await db.update_privacy(file_info)
165
  reply_markup, stream_text = await gen_link(_id=inserted_id)
166
  await update.message.edit_text(
167
- text=stream_text,
168
  parse_mode=ParseMode.HTML,
169
  disable_web_page_preview=True,
170
- reply_markup=reply_markup,
171
  )
172
  except FloodWait as e:
173
  print(f"Sleeping for {str(e.value)}s")
@@ -227,12 +227,12 @@ async def cb_data(bot: Client, update: CallbackQuery):
227
  #All the Time Get_file_ids should be called before update privacy or else tagged_users will be {}
228
  print(file_info)
229
  await db.update_privacy(file_info)
230
- reply_markup, stream_text = await gen_link(_id=inserted_id)
231
  await update.message.edit_text(
232
- text=stream_text,
233
  parse_mode=ParseMode.HTML,
234
  disable_web_page_preview=True,
235
- reply_markup=reply_markup,
236
  )
237
  except FloodWait as e:
238
  print(f"Sleeping for {str(e.value)}s")
 
109
 
110
  elif usr_cmd[0] == "mainstream":
111
  _id = usr_cmd[1]
112
+ response = await gen_link(_id=_id)
113
  await update.message.edit_text(
114
+ text=response["stream_text"],
115
  parse_mode=ParseMode.HTML,
116
  disable_web_page_preview=True,
117
+ reply_markup=response["reply_markup"],
118
  )
119
 
120
  elif usr_cmd[0] == "pubup":
 
164
  await db.update_privacy(file_info)
165
  reply_markup, stream_text = await gen_link(_id=inserted_id)
166
  await update.message.edit_text(
167
+ text=response["stream_text"],
168
  parse_mode=ParseMode.HTML,
169
  disable_web_page_preview=True,
170
+ reply_markup=response["reply_markup"],
171
  )
172
  except FloodWait as e:
173
  print(f"Sleeping for {str(e.value)}s")
 
227
  #All the Time Get_file_ids should be called before update privacy or else tagged_users will be {}
228
  print(file_info)
229
  await db.update_privacy(file_info)
230
+ response = await gen_link(_id=inserted_id)
231
  await update.message.edit_text(
232
+ text=response["stream_text"],
233
  parse_mode=ParseMode.HTML,
234
  disable_web_page_preview=True,
235
+ reply_markup=response["reply_markup"],
236
  )
237
  except FloodWait as e:
238
  print(f"Sleeping for {str(e.value)}s")
FileStream/bot/plugins/FileHandlers/stream.py CHANGED
@@ -75,12 +75,19 @@ async def private_receive_handler(bot: Client, message: Message):
75
  reply = await message.reply_text(LANG.PROCESSING_TEXT)
76
  file_info=get_file_info(message, instruction)
77
  #This Will give a option to Public Private and temporary Upload
78
- reply_markup, stream_text = await upload_type_func(get_file_info(message, instruction),reply)
79
- await reply.edit_text(text=stream_text,
 
80
  parse_mode=ParseMode.HTML,
81
  disable_web_page_preview=True,
82
- reply_markup=reply_markup,
83
- )
 
 
 
 
 
 
84
  except FloodWait as e:
85
  print(f"Sleeping for {str(e.value)}s")
86
 
@@ -102,15 +109,14 @@ async def channel_receive_handler(bot: Client, message: Message):
102
  try:
103
  inserted_id = await db.add_file(file_info=get_file_info(message), db_type="TEMPORARY")
104
  await get_file_ids(False, inserted_id, MULTI_CLIENTS, message)
105
- reply_markup, stream_link = await gen_link(_id=inserted_id)
106
  await bot.edit_message_reply_markup(
107
  chat_id=message.chat.id,
108
  message_id=message.id,
109
  reply_markup=InlineKeyboardMarkup([[
110
  InlineKeyboardButton(
111
  "Dᴏᴡɴʟᴏᴀᴅ ʟɪɴᴋ 📥",
112
- url=
113
- f"https://t.me/{FileStream.username}?start=stream_{str(inserted_id)}"
114
  )
115
  ]]))
116
 
@@ -210,12 +216,12 @@ async def reply_handler(
210
  reply_to_msg_id=None,
211
  chat_id=Telegram.PFLOG_CHANNEL)
212
 
213
- reply_markup, stream_text = await gen_link(_id=file_info['_id'])
214
  await replied_message.edit_text(
215
- text=f"{message_txt}\n{stream_text}",
216
  parse_mode=ParseMode.HTML,
217
  disable_web_page_preview=True,
218
- reply_markup=reply_markup,
219
  )
220
  instruction = {
221
  "privacy_type":"PRIVATE",
 
75
  reply = await message.reply_text(LANG.PROCESSING_TEXT)
76
  file_info=get_file_info(message, instruction)
77
  #This Will give a option to Public Private and temporary Upload
78
+ response = await upload_type_func(get_file_info(message, instruction),reply)
79
+ if response["type"]=="ExistingFile":
80
+ reply.reply_photo(text=response["stream_text"],
81
  parse_mode=ParseMode.HTML,
82
  disable_web_page_preview=True,
83
+ reply_markup= response["reply_markup"],
84
+ )
85
+ else:
86
+ await reply.edit_text(text=response["stream_text"],
87
+ parse_mode=ParseMode.HTML,
88
+ disable_web_page_preview=True,
89
+ reply_markup= response["reply_markup"],
90
+ )
91
  except FloodWait as e:
92
  print(f"Sleeping for {str(e.value)}s")
93
 
 
109
  try:
110
  inserted_id = await db.add_file(file_info=get_file_info(message), db_type="TEMPORARY")
111
  await get_file_ids(False, inserted_id, MULTI_CLIENTS, message)
112
+ response = await gen_link(_id=inserted_id)
113
  await bot.edit_message_reply_markup(
114
  chat_id=message.chat.id,
115
  message_id=message.id,
116
  reply_markup=InlineKeyboardMarkup([[
117
  InlineKeyboardButton(
118
  "Dᴏᴡɴʟᴏᴀᴅ ʟɪɴᴋ 📥",
119
+ url=f"https://t.me/{FileStream.username}?start=stream_{str(inserted_id)}"
 
120
  )
121
  ]]))
122
 
 
216
  reply_to_msg_id=None,
217
  chat_id=Telegram.PFLOG_CHANNEL)
218
 
219
+ response = await gen_link(_id=file_info['_id'])
220
  await replied_message.edit_text(
221
+ text=f"{message_txt}\n{response['stream_text']}",
222
  parse_mode=ParseMode.HTML,
223
  disable_web_page_preview=True,
224
+ reply_markup=response['reply_markup'],
225
  )
226
  instruction = {
227
  "privacy_type":"PRIVATE",
FileStream/utils/FileProcessors/bot_utils.py CHANGED
@@ -33,8 +33,7 @@ async def is_user_joined(bot, message: Message):
33
  if Telegram.FORCE_SUB_ID and Telegram.FORCE_SUB_ID.startswith("-100"):
34
  channel_chat_id = int(
35
  Telegram.FORCE_SUB_ID) # When id startswith with -100
36
- elif Telegram.FORCE_SUB_ID and (
37
- not Telegram.FORCE_SUB_ID.startswith("-100")):
38
  channel_chat_id = Telegram.FORCE_SUB_ID # When id not startswith -100
39
  else:
40
  return 200
@@ -53,18 +52,12 @@ async def is_user_joined(bot, message: Message):
53
  photo=Telegram.VERIFY_PIC,
54
  caption="<i>Jᴏɪɴ ᴍʏ ᴜᴘᴅᴀᴛᴇ ᴄʜᴀɴɴᴇʟ ᴛᴏ ᴜsᴇ ᴍᴇ 🔐</i>",
55
  parse_mode=ParseMode.HTML,
56
- reply_markup=InlineKeyboardMarkup([[
57
- InlineKeyboardButton("❆ Jᴏɪɴ Oᴜʀ Cʜᴀɴɴᴇʟ ❆",
58
- url=invite_link.invite_link)
59
- ]]))
60
  else:
61
  #---------------------------------------------------------------#
62
  ver = await message.reply_text(
63
  text="<i>Jᴏɪɴ ᴍʏ ᴜᴘᴅᴀᴛᴇ ᴄʜᴀɴɴᴇʟ ᴛᴏ ᴜsᴇ ᴍᴇ 🔐</i>",
64
- reply_markup=InlineKeyboardMarkup([[
65
- InlineKeyboardButton("❆ Jᴏɪɴ Oᴜʀ Cʜᴀɴɴᴇʟ ❆",
66
- url=invite_link.invite_link)
67
- ]]),
68
  parse_mode=ParseMode.HTML)
69
 
70
  await asyncio.sleep(30)
@@ -76,8 +69,7 @@ async def is_user_joined(bot, message: Message):
76
  return False
77
  except Exception:
78
  await message.reply_text(
79
- text=
80
- f"<i>Sᴏᴍᴇᴛʜɪɴɢ ᴡʀᴏɴɢ ᴄᴏɴᴛᴀᴄᴛ ᴍʏ ᴅᴇᴠᴇʟᴏᴘᴇʀ</i> <b><a href='https://t.me/{Telegram.UPDATES_CHANNEL}'>[ ᴄʟɪᴄᴋ ʜᴇʀᴇ ]</a></b>",
81
  parse_mode=ParseMode.HTML,
82
  disable_web_page_preview=True)
83
  return False
@@ -101,9 +93,9 @@ async def upload_type_func(file_info,replied_message):
101
  existing_file = await db.get_file_by_fileuniqueid_only(file_info['file']['file_unique_id'],file_info['privacy_type'])
102
  if existing_file :
103
 
104
- reply_markup, stream_text = await gen_link(existing_file['_id'])
105
  #await update.message.edit_text(text=stream_text,parse_mode=ParseMode.HTML,disable_web_page_preview=True,reply_markup=reply_markup,)
106
- return reply_markup, stream_text
107
 
108
  else:
109
 
@@ -118,7 +110,7 @@ async def upload_type_func(file_info,replied_message):
118
  ],
119
  [InlineKeyboardButton("ᴄʟᴏsᴇ", callback_data="close")]
120
  ])
121
- return reply_markup, stream_text
122
 
123
 
124
  async def priv_func(file_name, file_size):
@@ -198,7 +190,7 @@ async def gen_link(_id):
198
  InlineKeyboardButton("ɢᴇᴛ ғɪʟᴇ", url=file_link),
199
  InlineKeyboardButton("ʀᴇᴠᴏᴋᴇ ғɪʟᴇ",callback_data=f"msgdelpvt_{_id}")
200
  ], [InlineKeyboardButton("ᴄʟᴏsᴇ", callback_data="close")]])
201
- return reply_markup, stream_text
202
 
203
 
204
  #---------------------[ GEN STREAM LINKS FOR CHANNEL ]---------------------#
 
33
  if Telegram.FORCE_SUB_ID and Telegram.FORCE_SUB_ID.startswith("-100"):
34
  channel_chat_id = int(
35
  Telegram.FORCE_SUB_ID) # When id startswith with -100
36
+ elif Telegram.FORCE_SUB_ID and (not Telegram.FORCE_SUB_ID.startswith("-100")):
 
37
  channel_chat_id = Telegram.FORCE_SUB_ID # When id not startswith -100
38
  else:
39
  return 200
 
52
  photo=Telegram.VERIFY_PIC,
53
  caption="<i>Jᴏɪɴ ᴍʏ ᴜᴘᴅᴀᴛᴇ ᴄʜᴀɴɴᴇʟ ᴛᴏ ᴜsᴇ ᴍᴇ 🔐</i>",
54
  parse_mode=ParseMode.HTML,
55
+ reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("❆ Jᴏɪɴ Oᴜʀ Cʜᴀɴɴᴇʟ ❆",url=invite_link.invite_link)]]))
 
 
 
56
  else:
57
  #---------------------------------------------------------------#
58
  ver = await message.reply_text(
59
  text="<i>Jᴏɪɴ ᴍʏ ᴜᴘᴅᴀᴛᴇ ᴄʜᴀɴɴᴇʟ ᴛᴏ ᴜsᴇ ᴍᴇ 🔐</i>",
60
+ reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("❆ Jᴏɪɴ Oᴜʀ Cʜᴀɴɴᴇʟ ❆",url=invite_link.invite_link)]]),
 
 
 
61
  parse_mode=ParseMode.HTML)
62
 
63
  await asyncio.sleep(30)
 
69
  return False
70
  except Exception:
71
  await message.reply_text(
72
+ text=f"<i>Sᴏᴍᴇᴛʜɪɴɢ ᴡʀᴏɴɢ ᴄᴏɴᴛᴀᴄᴛ ᴍʏ ᴅᴇᴠᴇʟᴏᴘᴇʀ</i> <b><a href='https://t.me/{Telegram.UPDATES_CHANNEL}'>[ ᴄʟɪᴄᴋ ʜᴇʀᴇ ]</a></b>",
 
73
  parse_mode=ParseMode.HTML,
74
  disable_web_page_preview=True)
75
  return False
 
93
  existing_file = await db.get_file_by_fileuniqueid_only(file_info['file']['file_unique_id'],file_info['privacy_type'])
94
  if existing_file :
95
 
96
+ response = await gen_link(existing_file['_id'])
97
  #await update.message.edit_text(text=stream_text,parse_mode=ParseMode.HTML,disable_web_page_preview=True,reply_markup=reply_markup,)
98
+ return {"reply_markup" : response["reply_markup"], "stream_text": response["stream_text"],"poster":response["poster"],"type":"ExistingFile"}
99
 
100
  else:
101
 
 
110
  ],
111
  [InlineKeyboardButton("ᴄʟᴏsᴇ", callback_data="close")]
112
  ])
113
+ return {"reply_markup" : reply_markup, "stream_text": stream_text, "type":"OPTIONS"}
114
 
115
 
116
  async def priv_func(file_name, file_size):
 
190
  InlineKeyboardButton("ɢᴇᴛ ғɪʟᴇ", url=file_link),
191
  InlineKeyboardButton("ʀᴇᴠᴏᴋᴇ ғɪʟᴇ",callback_data=f"msgdelpvt_{_id}")
192
  ], [InlineKeyboardButton("ᴄʟᴏsᴇ", callback_data="close")]])
193
+ return {"reply_markup": reply_markup, "stream_text": stream_text, "poster":poster}
194
 
195
 
196
  #---------------------[ GEN STREAM LINKS FOR CHANNEL ]---------------------#
FileStream/utils/FileProcessors/custom_ul.py CHANGED
@@ -59,8 +59,7 @@ class TeleUploader:
59
  logging.debug(f"Cached file properties for file with ID {db_id}")
60
  return self.cached_file_ids[db_id]
61
 
62
- async def generate_media_session(self, client: Client,
63
- file_id: FileId) -> Session:
64
  """
65
  Generates the media session for the DC that contains the media file.
66
  This is required for getting the bytes from Telegram servers.
@@ -190,9 +189,7 @@ class TeleUploader:
190
  media = raw.types.InputMediaUploadedDocument(
191
  file=final,
192
  mime_type=file_details['file']["mime_type"],
193
- attributes=[
194
- raw.types.DocumentAttributeFilename(file_name=file_details['file']["file_name"])
195
- ])
196
 
197
  try:
198
  msgs = await client.invoke(
@@ -203,10 +200,8 @@ class TeleUploader:
203
  random_id=file['file']["file_id"]))
204
 
205
  #print(msgs)
206
- message = await FileStream.send_message(
207
- Telegram.ULOG_GROUP, "Message sent with **Pyrogram**!")
208
- message_id = getattr(
209
- getattr(getattr(msgs, "updates", "")[1], "message", ""), "id", "")
210
 
211
  print("Printing msg-id", message_id)
212
  chat_id = Telegram.FLOG_CHANNEL
@@ -227,12 +222,12 @@ class TeleUploader:
227
  #await db.add_webfile(file_info)
228
  inserted_id = await db.add_file(file_info=file_info,db_type="TEMPORARY")
229
  await get_file_ids(False, inserted_id, MessageFile)
230
- reply_markup, stream_text = await gen_link(_id=inserted_id)
231
  await message.edit_text(
232
- text=stream_text,
233
  parse_mode=ParseMode.HTML,
234
  disable_web_page_preview=True,
235
- reply_markup=reply_markup,
236
  )
237
 
238
  #log_msg = await send_file(FileStream, db_id, file_info['file_id'], message)
@@ -241,9 +236,7 @@ class TeleUploader:
241
  await client.send_message(chat_id=Telegram.ULOG_GROUP,
242
  text=f"**#EʀʀᴏʀTʀᴀᴄᴋᴇʙᴀᴄᴋ:** `{e}`",
243
  disable_web_page_preview=True)
244
- print(
245
- f"Cᴀɴ'ᴛ Eᴅɪᴛ Bʀᴏᴀᴅᴄᴀsᴛ Mᴇssᴀɢᴇ!\nEʀʀᴏʀ: **Gɪᴠᴇ ᴍᴇ ᴇᴅɪᴛ ᴘᴇʀᴍɪssɪᴏɴ ɪɴ ᴜᴘᴅᴀᴛᴇs ᴀɴᴅ ʙɪɴ Cʜᴀɴɴᴇʟ!{traceback.format_exc()}**"
246
- )
247
  await session.stop()
248
 
249
  return response
 
59
  logging.debug(f"Cached file properties for file with ID {db_id}")
60
  return self.cached_file_ids[db_id]
61
 
62
+ async def generate_media_session(self, client: Client,file_id: FileId) -> Session:
 
63
  """
64
  Generates the media session for the DC that contains the media file.
65
  This is required for getting the bytes from Telegram servers.
 
189
  media = raw.types.InputMediaUploadedDocument(
190
  file=final,
191
  mime_type=file_details['file']["mime_type"],
192
+ attributes=[raw.types.DocumentAttributeFilename(file_name=file_details['file']["file_name"])])
 
 
193
 
194
  try:
195
  msgs = await client.invoke(
 
200
  random_id=file['file']["file_id"]))
201
 
202
  #print(msgs)
203
+ message = await FileStream.send_message(Telegram.ULOG_GROUP, "Message sent with **Pyrogram**!")
204
+ message_id = getattr(getattr(getattr(msgs, "updates", "")[1], "message", ""), "id", "")
 
 
205
 
206
  print("Printing msg-id", message_id)
207
  chat_id = Telegram.FLOG_CHANNEL
 
222
  #await db.add_webfile(file_info)
223
  inserted_id = await db.add_file(file_info=file_info,db_type="TEMPORARY")
224
  await get_file_ids(False, inserted_id, MessageFile)
225
+ response = await gen_link(_id=inserted_id)
226
  await message.edit_text(
227
+ text=response["stream_text"],
228
  parse_mode=ParseMode.HTML,
229
  disable_web_page_preview=True,
230
+ reply_markup=response["reply_markup"],
231
  )
232
 
233
  #log_msg = await send_file(FileStream, db_id, file_info['file_id'], message)
 
236
  await client.send_message(chat_id=Telegram.ULOG_GROUP,
237
  text=f"**#EʀʀᴏʀTʀᴀᴄᴋᴇʙᴀᴄᴋ:** `{e}`",
238
  disable_web_page_preview=True)
239
+ print(f"Cᴀɴ'ᴛ Eᴅɪᴛ Bʀᴏᴀᴅᴄᴀsᴛ Mᴇssᴀɢᴇ!\nEʀʀᴏʀ: **Gɪᴠᴇ ᴍᴇ ᴇᴅɪᴛ ᴘᴇʀᴍɪssɪᴏɴ ɪɴ ᴜᴘᴅᴀᴛᴇs ᴀɴᴅ ʙɪɴ Cʜᴀɴɴᴇʟ!{traceback.format_exc()}**")
 
 
240
  await session.stop()
241
 
242
  return response