def __init__(self): """ MegaFiles is the mongo collection that holds the documents for the files that are uploaded via the bot. Functions: insert_new_files: save new documents to the collection that contains details of the new files that are uploaded. count_files_by_url: count and returns the number of documents for the file with the same url. get_files_by_url: returns the documents for the files with a given url. get_file_by_file_id: returns the document for the file with the given telegram file_id. get_file_by_file_name: returns the documents for the files with the given file name. """ self.files_collection = MegaDB().db['files']
def __init__(self): """ MegaUsers is the mongo collection for the documents that holds the details of the users such as their download settings, gdrive and etc, for them users who uses the bot. Functions: insert_user: insert new documents, that contains the details of the new users who started using the bot. get_user: return the document that contains the user_id for the the given telegram user id. update_dld_settings: set/update the dld_settings field for the document with the given telegram user id. update_cst_thumb: set/update the custom_thumbnail field for the document with the given telegram user id. update_gdrive: set/update the gdrive_key and gdrive_key_location for the document with the given telegram user id. """ self.user_collection = MegaDB().db["users"]
class MegaUsers: def __init__(self): self.user_collection = MegaDB().db["users"] async def insert_user(self, user_id: int): if self.user_collection.count({"user_id": user_id}) > 0: return False else: self.user_collection.insert_one({ "user_id": user_id, "dld_settings": "default", "custom_thumbnail": None }) async def get_user(self, user_id: int): return self.user_collection.find_one({"user_id": user_id}) async def update_dld_settings(self, user_id: int, data: str): self.user_collection.update_one({"user_id": user_id}, {"$set": { "dld_settings": data }}) async def update_cst_thumb(self, user_id: int, thumb: typing.Union[bytes, str]): self.user_collection.update_one({"user_id": user_id}, {"$set": { "custom_thumbnail": thumb }})
class MegaFiles: def __init__(self): self.files_collection = MegaDB().db['files'] async def insert_new_files(self, file_name: str, filed_id: str, msg_id: int, chat_id: int, url: str, file_type: str): self.files_collection.insert_one({ "file_name": file_name, "file_id": filed_id, "msg_id": msg_id, "chat_id": chat_id, "url": url, "file_type": file_type }) async def count_files_by_url(self, url: str): return self.files_collection.count({"url": url}) async def get_file_by_url(self, url: str): return self.files_collection.find({"url": url}) async def get_file_by_file_id(self, file_id: str): return self.files_collection.find_one({"file_id": file_id}) async def get_file_by_name(self, file_name: str): return self.files_collection.find( {"file_name": re.compile(file_name, re.IGNORECASE)})
class MegaFiles: def __init__(self): """ MegaFiles is the mongo collection that holds the documents for the files that are uploaded via the bot. Functions: insert_new_files: save new documents to the collection that contains details of the new files that are uploaded. count_files_by_url: count and returns the number of documents for the file with the same url. get_files_by_url: returns the documents for the files with a given url. get_file_by_file_id: returns the document for the file with the given telegram file_id. get_file_by_file_name: returns the documents for the files with the given file name. """ self.files_collection = MegaDB().db['files'] async def insert_new_files(self, file_name: str, filed_id: str, msg_id: int, chat_id: int, url: str, file_type: str): self.files_collection.insert_one({ "file_name": file_name, "file_id": filed_id, "msg_id": msg_id, "chat_id": chat_id, "url": url, "file_type": file_type }) async def count_files_by_url(self, url: str): return self.files_collection.count({"url": url}) async def get_file_by_url(self, url: str): return self.files_collection.find({"url": url}) async def get_file_by_file_id(self, file_id: str): return self.files_collection.find_one({"file_id": file_id}) async def get_file_by_name(self, file_name: str, row_limit: int): return self.files_collection.find({ "file_name": re.compile(file_name, re.IGNORECASE) }).limit(row_limit)
class MegaUsers: def __init__(self): """ MegaUsers is the mongo collection for the documents that holds the details of the users such as their download settings, gdrive and etc, for them users who uses the bot. Functions: insert_user: insert new documents, that contains the details of the new users who started using the bot. get_user: return the document that contains the user_id for the the given telegram user id. update_dld_settings: set/update the dld_settings field for the document with the given telegram user id. update_cst_thumb: set/update the custom_thumbnail field for the document with the given telegram user id. update_gdrive: set/update the gdrive_key and gdrive_key_location for the document with the given telegram user id. """ self.user_collection = MegaDB().db["users"] async def insert_user(self, user_id: int): if self.user_collection.count({"user_id": user_id}) > 0: return False else: self.user_collection.insert_one({ "user_id": user_id, "dld_settings": "default", "custom_thumbnail": None }) async def get_user(self, user_id: int): return self.user_collection.find_one({"user_id": user_id}) async def update_dld_settings(self, user_id: int, data: str): self.user_collection.update_one({"user_id": user_id}, {"$set": { "dld_settings": data }}) async def update_cst_thumb(self, user_id: int, thumb: typing.Union[bytes, str]): self.user_collection.update_one({"user_id": user_id}, {"$set": { "custom_thumbnail": thumb }}) async def update_gdrive(self, user_id: int, key_file: typing.Union[bytes, str], key_location: str): self.user_collection.update_one({"user_id": user_id}, { "$set": { "gdrive_key": key_file, "gdrive_key_location": key_location } }) async def update_yt_cookie(self, user_id: int, cookie_file: typing.Union[bytes, str], cookie_file_location: str): self.user_collection.update_one({"user_id": user_id}, { "$set": { "yt_cookie": cookie_file, "yt_cookie_location": cookie_file_location } }) async def update_file_rename_settings(self, user_id: int, dld_type: str): self.user_collection.update_one({"user_id": user_id}, {"$set": { "f_rename_type": dld_type }}) async def update_seedr_username(self, user_id: int, seedr_username: str): self.user_collection.update_one( {"user_id": user_id}, {"$set": { "seedr_username": seedr_username }}) async def update_seedr_paswd(self, user_id: int, seedr_passwd: str): self.user_collection.update_one( {"user_id": user_id}, {"$set": { "seedr_passwd": seedr_passwd }})
def __init__(self): self.files_collection = MegaDB().db['files']
def __init__(self): self.user_collection = MegaDB().db["users"]