thundra.storage package

Submodules

thundra.storage.file module

class thundra.storage.file.File(URL, mimetype, fileSHA256, fileLength, mediaKey, fileEncSHA256, directPath, mediaKeyTimestamp, type, viewOnce=None, caption=None, height=None, width=None, seconds=None, ptt=None, pageCount=None, isAnimated=None)[source]

Bases: object

A class representing a file with various attributes related to its metadata and content.

url

The URL of the file.

Type:

str

mimetype

The MIME type of the file.

Type:

str

fileSha256

The SHA-256 hash of the file.

Type:

bytes

fileLength

The length of the file in bytes.

Type:

int

mediaKey

The media key for encryption.

Type:

bytes

fileEncSha256

The encrypted SHA-256 hash of the file.

Type:

bytes

directPath

The direct path to the file.

Type:

str

mediaKeyTimestamp

The timestamp for the media key.

Type:

int

type

The type of the file.

Type:

type

viewOnce

Indicates if the file is view-once media. Default is None.

Type:

Optional[bool]

caption

The caption of the file. Default is None.

Type:

Optional[str]

height

The height of the media (if applicable). Default is None.

Type:

Optional[int]

width

The width of the media (if applicable). Default is None.

Type:

Optional[int]

seconds

The duration of the media in seconds (if applicable). Default is None.

Type:

Optional[int]

ptt

Indicates if the file is a push-to-talk audio. Default is None.

Type:

Optional[bool]

pageCount

The number of pages in the file (if applicable). Default is None.

Type:

Optional[int]

isAnimated

Indicates if the file is an animated media. Default is None.

Type:

Optional[bool]

URL: str
caption: Optional[str] = None
directPath: str
download(client, mediatype)[source]

Download the file using the provided client and media type.

Parameters:
  • client (NewClient) – The client to use for downloading the file.

  • mediatype (MediaType) – The type of media being downloaded.

Returns:

The downloaded file as bytes.

Return type:

bytes

fileEncSHA256: bytes
fileLength: int
fileSHA256: bytes
classmethod from_message(message)[source]

Create a File instance from a MediaMessageType message.

Parameters:

message (MediaMessageType) – The message containing media information.

Returns:

An instance of the File class.

Return type:

File

height: Optional[int] = None
isAnimated: Optional[bool] = None
mediaKey: bytes
mediaKeyTimestamp: int
mimetype: str
pageCount: Optional[int] = None
ptt: Optional[bool] = None
seconds: Optional[int] = None
type: type
viewOnce: Optional[bool] = None
width: Optional[int] = None
class thundra.storage.file.FileRegistry[source]

Bases: dict[str, File]

A registry to manage files, allowing updates while maintaining a maximum number of stored files.

update(id, data, max_data)[source]

Update the registry with a new file, ensuring the number of files does not exceed max_data.

Parameters:
  • id (str) – The unique identifier for the file.

  • data (File) – The file to be added or updated in the registry.

  • max_data (int) – The maximum number of files allowed in the registry.

class thundra.storage.file.StorageRegistry(max_files=10)[source]

Bases: dict[str, FileRegistry]

A storage registry to manage user-specific file registries.

max_files

The maximum number of files allowed per user registry.

Type:

int

get_file(user_id, file_id)[source]

Retrieve a specific file from the user’s registry.

Parameters:
  • user_id (str) – The unique identifier for the user.

  • file_id (str) – The unique identifier for the file.

Returns:

The requested file.

Return type:

File

get_files(user_id)[source]

Retrieve all files from the user’s registry.

Parameters:

user_id (str) – The unique identifier for the user.

Returns:

The registry of files for the user.

Return type:

FileRegistry

get_files_by_type(user_id, types)[source]

Retrieve files of specific types from the user’s registry.

Parameters:
  • user_id (str) – The unique identifier for the user.

  • types (Iterable[type]) – The types of files to retrieve.

Yield:

The files of the specified types.

Return type:

Generator[File, None, None]

max_files: int = 10
save(user_id, file_id, file)[source]

Save a file in the user’s registry, ensuring the number of files does not exceed max_files.

Parameters:
  • user_id (str) – The unique identifier for the user.

  • file_id (str) – The unique identifier for the file.

  • file (File) – The file to be saved in the registry.

Module contents

class thundra.storage.File(URL, mimetype, fileSHA256, fileLength, mediaKey, fileEncSHA256, directPath, mediaKeyTimestamp, type, viewOnce=None, caption=None, height=None, width=None, seconds=None, ptt=None, pageCount=None, isAnimated=None)[source]

Bases: object

A class representing a file with various attributes related to its metadata and content.

url

The URL of the file.

Type:

str

mimetype

The MIME type of the file.

Type:

str

fileSha256

The SHA-256 hash of the file.

Type:

bytes

fileLength

The length of the file in bytes.

Type:

int

mediaKey

The media key for encryption.

Type:

bytes

fileEncSha256

The encrypted SHA-256 hash of the file.

Type:

bytes

directPath

The direct path to the file.

Type:

str

mediaKeyTimestamp

The timestamp for the media key.

Type:

int

type

The type of the file.

Type:

type

viewOnce

Indicates if the file is view-once media. Default is None.

Type:

Optional[bool]

caption

The caption of the file. Default is None.

Type:

Optional[str]

height

The height of the media (if applicable). Default is None.

Type:

Optional[int]

width

The width of the media (if applicable). Default is None.

Type:

Optional[int]

seconds

The duration of the media in seconds (if applicable). Default is None.

Type:

Optional[int]

ptt

Indicates if the file is a push-to-talk audio. Default is None.

Type:

Optional[bool]

pageCount

The number of pages in the file (if applicable). Default is None.

Type:

Optional[int]

isAnimated

Indicates if the file is an animated media. Default is None.

Type:

Optional[bool]

URL: str
caption: Optional[str] = None
directPath: str
download(client, mediatype)[source]

Download the file using the provided client and media type.

Parameters:
  • client (NewClient) – The client to use for downloading the file.

  • mediatype (MediaType) – The type of media being downloaded.

Returns:

The downloaded file as bytes.

Return type:

bytes

fileEncSHA256: bytes
fileLength: int
fileSHA256: bytes
classmethod from_message(message)[source]

Create a File instance from a MediaMessageType message.

Parameters:

message (MediaMessageType) – The message containing media information.

Returns:

An instance of the File class.

Return type:

File

height: Optional[int] = None
isAnimated: Optional[bool] = None
mediaKey: bytes
mediaKeyTimestamp: int
mimetype: str
pageCount: Optional[int] = None
ptt: Optional[bool] = None
seconds: Optional[int] = None
type: type
viewOnce: Optional[bool] = None
width: Optional[int] = None
class thundra.storage.FileRegistry[source]

Bases: dict[str, File]

A registry to manage files, allowing updates while maintaining a maximum number of stored files.

update(id, data, max_data)[source]

Update the registry with a new file, ensuring the number of files does not exceed max_data.

Parameters:
  • id (str) – The unique identifier for the file.

  • data (File) – The file to be added or updated in the registry.

  • max_data (int) – The maximum number of files allowed in the registry.