-
Notifications
You must be signed in to change notification settings - Fork 1
dsdrive_api
class HookTool()A tool to send data to multiple webhooks
Attributes:
-
hookslist - A list of webhook URLs -
indexint - The index of the current webhook URL
Methods:
-
get_hook- Get the current webhook URL -
send- Send data to the current webhook URL -
get- Send a GET request to a URL, handling rate limits and nothing
def get_hook()Get the current webhook URL
def send(*args, **kwargs)Send data to the current webhook URL, handling rate limits
Arguments:
-
*args- Arguments to be passed to requests.post -
**kwargs- Keyword arguments to be passed to requests.post
Returns:
-
requests.Response- The response of the request
def get(*args, **kwargs)Send a GET request to a URL, handling rate limits and nothing
Arguments:
-
*args- Arguments to be passed to requests.get -
**kwargs- Keyword arguments to be passed to requests.get
Returns:
-
requests.Response- The response of the request
class DSFile(BytesIO)A file-like object that can be used to read and write files on DSdrive
Attributes:
-
pathstr - The path of the file -
dsdriveDSdriveApi - The DSdriveApi object -
modestr - The mode of the file -
_readbool - Whether the file is readable -
_writebool - Whether the file is writable
Methods:
-
readable- Whether the file is readable -
writable- Whether the file is writable -
read- Read the file -
write- Write to the file -
close- Close the file
def __init__(path, dsdrive, mode="r", zero_size=False)Create a DSFile object
Arguments:
-
pathstr - The path of the file -
dsdriveDSdriveApi - The DSdriveApi object -
modestr - The mode of the file -
zero_sizebool - Whether the file is empty
def read(size=-1) -> bytesRead the file
Arguments:
-
sizeint - The number of bytes to read. If -1, read the whole file
Returns:
-
bytes- The bytes read
Raises:
-
OSError- If the file is not readable
def write(b: bytes) -> intRead the file
Arguments:
-
bbytes - The bytes to write
Returns:
-
int- The number of bytes written
Raises:
-
OSError- If the file is not writable
def close()Close the file, and send the file to DSdrive if the file is writable
class DSdriveApi()A wrapper class for DSdriveApiWebhook and DSdriveApiBot
def __init__(*args, **kwargs)Create a DSdriveApi object, where the backend api is either DSdriveApiWebhook or DSdriveApiBot, depending on the value of use_bot
class DSdriveApiBase()A base class for DSdrive API implementations
def encrypt(data: bytes)Encrypt data
Arguments:
-
databytes - The data to encrypt -
encryption_funcfunction - The encryption function to use
Returns:
-
encryptedbytes - The encrypted data
def decrypt(data: bytes)Decrypt data
Arguments:
-
databytes - The data to decrypt -
encryption_funcfunction - The decryption function to use
Returns:
-
decryptedbytes - The decrypted data
def path_splitter(path: str)Split a path into a list
Arguments:
-
pathstr - The path to split
Returns:
-
filelistlist - The list of directories
def open_binary(path: str, mode: str = "r")Open a file
Arguments:
-
pathstr - The path of the file -
modestr - The mode of the file
Returns:
-
IODSFile - The file-like object
class DSdriveApiWebhook(DSdriveApiBase)A class to interact with Discord's file storage system
Attributes:
-
dbpymongo.database.Database - The database object -
hookHookTool - The HookTool object -
root_idbson.objectid.ObjectId - The ID of the root directory
Methods:
-
clear- Clear the database, very dangerous -
path_splitter- Split a path into a list of directories -
makedirs- Create directories -
find- Find a path -
send_file- Send a file to DSdrive -
open_binary- Open a file -
get_file_urls- Get the URLs of a file -
download_file- Download a file -
list_dir- List a directory -
remove_file- Remove a file -
remove_dir- Remove a directory -
remove_tree- Remove a tree -
get_info- Get the info of a file or directory -
set_info- Set the info of a file or directory
def __init__(url: str,
hook: HookTool,
url_expire_policy: BaseExpirePolicy = ApiExpirePolicy,
token: Optional[str] = None,
key: Union[str, bytes] = "despacito") -> NoneCreate a DSdriveApi object, creates the root directory if it doesn't exist
Arguments:
-
urlstr - The URL of the MongoDB database -
hookHookTool - The HookTool object
def clear()Clear the database safely
def makedirs(paths: list, allow_many: bool = False, exist_ok: bool = False)Create directories
Arguments:
-
pathslist - The list of directories to create -
allow_manybool - Whether to allow creating multiple directories -
exist_okbool - Whether to allow creating directories that already exist
Returns:
-
codeint - An error code, or 0 if successful -
parent_idUnion[ObjectID, None] - The ID of the last directory created
def find(paths: str, return_obj: bool = False)Find a path
Arguments:
-
pathslist - The list of directories to find -
return_objbool - Whether to return the object found or the ID of the object found
Returns:
-
codeint - An error code, or 0 if successful -
found_idUnion[ObjectID, None] - The ID of the last position found
def send_file(path: str, file_obj: Union[str, BytesIO, DSFile, None] = None)Send a file to Didcord
Arguments:
-
pathstr - The path to send the file to -
file_objUnion[str, BytesIO, DSFile] - The file to send
def get_file_urls(path: str)Get the URLs of a file
Arguments:
-
pathstr - The path of the file
Returns:
-
filelistlist - The list of URLs of the file
def download_file(path_src: str, path_dst: Optional[str] = None)Download a file from Discord to the local filesystem
Arguments:
-
path_srcstr - The path of the file on Discord -
path_dststr - The path of the file on the local filesystem
def list_dir(path: str)List a directory
Arguments:
-
pathstr - The path of the directory
Returns:
-
codeint - an error code, or 0 if successful -
filelistUnion[Iterable, None] - A list of files and directories, or None if an error occured
def remove_file(path: str)Remove a file
Arguments:
-
pathstr - The path of the file
Returns:
-
codeint - An error code, or 0 if successful
def remove_dir(path: str)Remove a directory
Arguments:
-
pathstr - The path of the directory
Returns:
-
codeint - An error code, or 0 if successful
def remove_tree(path: str)Remove a tree, not implemented yet
Arguments:
-
pathstr - The path of the tree
Returns:
-
codeint - An error code, or 0 if successful
def rename(path_src: str,
path_dst: str,
overwrite: bool = False,
create_dirs: bool = False,
preserve_timestamps: bool = False)Rename a file or directory
Arguments:
-
path_srcstr - The path of the file or directory -
path_dststr - The new path of the file or directory
Returns:
-
codeint - An error code, or 0 if successful
def copy(path_src: str,
path_dst: str,
overwrite: bool = False,
create_dirs: bool = False,
preserve_timestamps: bool = False)Copy a file or directory
Arguments:
-
path_srcstr - The path of the file or directory -
path_dststr - The new path of the file or directory
Returns:
-
codeint - An error code, or 0 if successful
def get_info(path: str)Get the info of a file or directory
Arguments:
-
pathstr - The path of the file or directory
Returns:
-
codeint - An error code, or 0 if successful -
infodict - The info of the file or directory
def set_info(path: str, info: dict)Set the info of a file or directory
Arguments:
-
pathstr - The path of the file or directory -
infodict - The info you want to set
Returns:
-
codeint - An error code, or 0 if successful