-
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:
-
hooks
list - A list of webhook URLs -
index
int - 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:
-
path
str - The path of the file -
dsdrive
DSdriveApi - The DSdriveApi object -
mode
str - The mode of the file -
_read
bool - Whether the file is readable -
_write
bool - 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:
-
path
str - The path of the file -
dsdrive
DSdriveApi - The DSdriveApi object -
mode
str - The mode of the file -
zero_size
bool - Whether the file is empty
def read(size=-1) -> bytes
Read the file
Arguments:
-
size
int - 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) -> int
Read the file
Arguments:
-
b
bytes - 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:
-
data
bytes - The data to encrypt -
encryption_func
function - The encryption function to use
Returns:
-
encrypted
bytes - The encrypted data
def decrypt(data: bytes)
Decrypt data
Arguments:
-
data
bytes - The data to decrypt -
encryption_func
function - The decryption function to use
Returns:
-
decrypted
bytes - The decrypted data
def path_splitter(path: str)
Split a path into a list
Arguments:
-
path
str - The path to split
Returns:
-
filelist
list - The list of directories
def open_binary(path: str, mode: str = "r")
Open a file
Arguments:
-
path
str - The path of the file -
mode
str - The mode of the file
Returns:
-
IO
DSFile - The file-like object
class DSdriveApiWebhook(DSdriveApiBase)
A class to interact with Discord's file storage system
Attributes:
-
db
pymongo.database.Database - The database object -
hook
HookTool - The HookTool object -
root_id
bson.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") -> None
Create a DSdriveApi object, creates the root directory if it doesn't exist
Arguments:
-
url
str - The URL of the MongoDB database -
hook
HookTool - The HookTool object
def clear()
Clear the database safely
def makedirs(paths: list, allow_many: bool = False, exist_ok: bool = False)
Create directories
Arguments:
-
paths
list - The list of directories to create -
allow_many
bool - Whether to allow creating multiple directories -
exist_ok
bool - Whether to allow creating directories that already exist
Returns:
-
code
int - An error code, or 0 if successful -
parent_id
Union[ObjectID, None] - The ID of the last directory created
def find(paths: str, return_obj: bool = False)
Find a path
Arguments:
-
paths
list - The list of directories to find -
return_obj
bool - Whether to return the object found or the ID of the object found
Returns:
-
code
int - An error code, or 0 if successful -
found_id
Union[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:
-
path
str - The path to send the file to -
file_obj
Union[str, BytesIO, DSFile] - The file to send
def get_file_urls(path: str)
Get the URLs of a file
Arguments:
-
path
str - The path of the file
Returns:
-
filelist
list - 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_src
str - The path of the file on Discord -
path_dst
str - The path of the file on the local filesystem
def list_dir(path: str)
List a directory
Arguments:
-
path
str - The path of the directory
Returns:
-
code
int - an error code, or 0 if successful -
filelist
Union[Iterable, None] - A list of files and directories, or None if an error occured
def remove_file(path: str)
Remove a file
Arguments:
-
path
str - The path of the file
Returns:
-
code
int - An error code, or 0 if successful
def remove_dir(path: str)
Remove a directory
Arguments:
-
path
str - The path of the directory
Returns:
-
code
int - An error code, or 0 if successful
def remove_tree(path: str)
Remove a tree, not implemented yet
Arguments:
-
path
str - The path of the tree
Returns:
-
code
int - 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_src
str - The path of the file or directory -
path_dst
str - The new path of the file or directory
Returns:
-
code
int - 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_src
str - The path of the file or directory -
path_dst
str - The new path of the file or directory
Returns:
-
code
int - An error code, or 0 if successful
def get_info(path: str)
Get the info of a file or directory
Arguments:
-
path
str - The path of the file or directory
Returns:
-
code
int - An error code, or 0 if successful -
info
dict - The info of the file or directory
def set_info(path: str, info: dict)
Set the info of a file or directory
Arguments:
-
path
str - The path of the file or directory -
info
dict - The info you want to set
Returns:
-
code
int - An error code, or 0 if successful