PyZipline/pyzipline/models.py

212 lines
7.3 KiB
Python
Raw Normal View History

"""This is a list of all the models used in PyZipline. They are used to represent the data returned from the Zipline API."""
2023-12-20 21:37:02 -05:00
from typing import List, Dict, Optional, Union
2023-12-19 05:36:18 -05:00
from datetime import datetime
class Embed:
"""Embed object used for checking embeds
2023-12-20 21:37:02 -05:00
Attributes:
color (Optional[str]): String of the embed's color
title (Optional[str]): String of the embed's title
siteName (Optional[str]): String of the embed's site name
description (Optional[str]): String of the embed's description
"""
2023-12-19 05:36:18 -05:00
def __init__(
self,
color: str,
title: str,
siteName: str,
description: str,
**kwargs
):
self.color = color
self.title = title
self.siteName = siteName
self.description = description
self.__dict__.update(kwargs)
class File:
"""File object used for uploading files to Zipline
2023-12-20 21:37:02 -05:00
Attributes:
createdAt (datetime.datetime): Datetime object of when the file was created
id (int): ID of the file
mimetype (str): String of the file's mimetype
views (int): Integer of the number of views the file has
name (str): String of the file's name
size (int): Integer of the file's size in bytes
favorite (bool): Boolean of whether the file is favorited
originalName (str = None): (optional) String of the file's original name
url (str = None): (optional) String of the file's URL
maxViews (int = None): (optional) Integer of the file's maximum number of views
expiredAt (datetime.datetime = None): (optional) Datetime object of when the file will expire
thumbnail (str = None): (optional) String of the file's thumbnail URL
folderId (int = None): (optional) Integer of the file's folder ID
"""
2023-12-19 05:36:18 -05:00
def __init__(
self,
createdAt: datetime,
2023-12-20 23:50:03 -05:00
id: int, # pylint: disable=redefined-builtin
2023-12-19 05:36:18 -05:00
mimetype: str,
views: int,
name: str,
size: int,
favorite: bool,
originalName: str = None,
url: str = None,
maxViews: int = None,
expiredAt: Union[datetime, None] = None,
thumbnail: str = None,
folderId: int = None,
**kwargs
):
self.createdAt = createdAt
self.id = id
self.mimetype = mimetype
self.views = views
self.name = name
self.size = size
self.favorite = favorite
self.originalName = originalName
self.url = url
self.maxViews = maxViews
self.expiredAt = expiredAt
self.thumbnail = thumbnail
self.folderId = folderId
self.__dict__.update(kwargs)
class Result:
"""Result returned from low-level RestAdapter
2023-12-20 21:37:02 -05:00
Attributes:
success (bool): Boolean of whether the request was successful
status_code (int): Standard HTTP Status code
message (str = ''): Human readable result
data (List[Dict] = None): Python List of Dictionaries (or maybe just a single Dictionary on error)
"""
def __init__(self, success: bool, status_code: int, message: str = '', data: List[Dict] = None):
self.success = success
self.status_code = status_code
self.message = message
2023-12-19 05:36:18 -05:00
self.data = data if data else []
class Invite:
"""Invite object used for managing invites
2023-12-20 21:37:02 -05:00
Attributes:
id (int): Integer ID of the invite
code (str): String of the invite's code
createdAt (datetime): Datetime object of when the invite was created
expiredAt (datetime): Datetime object of when the invite will expire
used (bool): Boolean of whether the invite has been used
createdById (int): Integer ID of the user who created the invite
"""
2023-12-19 05:36:18 -05:00
def __init__(
self,
2023-12-20 23:50:03 -05:00
id: int, # pylint: disable=redefined-builtin
2023-12-19 05:36:18 -05:00
code: str,
createdAt: datetime,
expiredAt: datetime,
used: bool,
createdById: int,
**kwargs
):
self.id = id
self.code = code
self.createdAt = createdAt
self.expiredAt = expiredAt
self.used = used
self.createdById = createdById
self.__dict__.update(kwargs)
class OAuth:
"""OAuth object used for managing OAuth
2023-12-20 21:37:02 -05:00
Attributes:
id (int): Integer ID of the OAuth
provider (str): String of the OAuth's provider, one of 'DISCORD', 'GITHUB', 'GOOGLE'
userId (int): Integer ID of the user who owns the OAuth
providerId (str): String of the OAuth's provider ID
username (str): String of the OAuth's connected account's username
token (str): String of the OAuth's access token
2023-12-20 21:37:02 -05:00
refresh (Optional[str]): String of the OAuth's refresh token
"""
2023-12-19 05:36:18 -05:00
def __init__(
self,
2023-12-20 23:50:03 -05:00
id: int, # pylint: disable=redefined-builtin
2023-12-19 05:36:18 -05:00
provider: str,
userId: int,
providerId: str,
username: str,
token: str,
2023-12-20 21:37:02 -05:00
refresh: Optional[str],
2023-12-19 05:36:18 -05:00
**kwargs
):
self.id = id
self.provider = provider
self.userId = userId
self.providerId = providerId
self.username = username
self.token = token
self.refresh = refresh
self.__dict__.update(kwargs)
class User:
"""User object used for managing users
2023-12-20 21:37:02 -05:00
Attributes:
id (int): Integer ID of the user
uuid (str): String of the user's UUID
username (str): String of the user's username
2023-12-20 21:37:02 -05:00
avatar (Optional[str]): String of the user's avatar, base64 encoded
token (str): String of the user's token
administrator (bool): Boolean of whether the user is an administrator
superAdmin (bool): Boolean of whether the user is a super administrator
systemTheme (str): String of the user's system theme
embed (Embed): Embed object of the user's embed
2023-12-20 21:37:02 -05:00
totpSecret (Optional[str]): String of the user's TOTP secret
domains (List[str]): List of Strings of the user's domains
2023-12-20 21:37:02 -05:00
oauth (Optional[List[OAuth]] = None): (optional) List of OAuth objects
ratelimit (Optional[datetime] = None): (optional) Datetime object of when the user's ratelimit expires
"""
2023-12-19 05:36:18 -05:00
def __init__(
self,
2023-12-20 23:50:03 -05:00
id: int, # pylint: disable=redefined-builtin
2023-12-19 05:36:18 -05:00
uuid: str,
username: str,
2023-12-20 21:37:02 -05:00
avatar: Optional[str],
2023-12-19 05:36:18 -05:00
token: str,
administrator: bool,
superAdmin: bool,
systemTheme: str,
embed: Embed,
2023-12-20 21:37:02 -05:00
totpSecret: Optional[str],
2023-12-19 05:36:18 -05:00
domains: List[str],
2023-12-20 21:37:02 -05:00
oauth: Optional[List['OAuth']] = [],
ratelimit: Optional[datetime] = None,
2023-12-19 05:36:18 -05:00
**kwargs
):
self.id = id
self.uuid = uuid
self.username = username
self.avatar = avatar
self.token = token
self.administrator = administrator
self.superAdmin = superAdmin
self.systemTheme = systemTheme
2023-12-20 21:37:02 -05:00
self.embed = Embed(**embed)
2023-12-19 05:36:18 -05:00
self.totpSecret = totpSecret
self.domains = domains
self.oauth = oauth
self.ratelimit = ratelimit
self.__dict__.update(kwargs)
2023-12-20 21:37:02 -05:00
for oauth_entry in self.oauth:
OAuth(**oauth_entry)
self.oauth.append(oauth_entry)