Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 107 additions & 0 deletions EpikCord/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,48 @@


class InstallParams:
"""
Attributes:
----------
scopes: :class:``
The scopes that are used by the install params.
permissions: :class:`Epikcord.flags.Permission`
The permissions that the application requires.
"""
def __init__(self, data: InstallParamsData):
"""
Parameters:
----------
data: :class:`discord_typings.InstallParamsData`
The data used to construct the class.
Note
----
Should never be manually constructed.
"""
self.scopes = data["scopes"]
self.permissions = Permissions(int(data["permissions"]))


class TeamMember:
"""
Attributes:
----------
membership_state: :class:`discord_typings.TeamMembershipState`
The status of the membership of this member.
permissions: :class:`list[str]`
The permissions that they have. As of now this is always ["*"].
team_id: :class:`int`
The id of the team.
user: :class:`User`
The user object for this member.
"""
def __init__(self, data: TeamMemberData):
"""
Parameters:
----------
data: :class:`discord_typings.TeamMemberData`
The data of the TeamMember
"""
self.membership_state = TeamMembershipState(data["membership_state"])
self.permissions = data["permissions"]
self.team_id = int(data["team_id"])
Expand All @@ -22,7 +57,27 @@ def __init__(self, data: TeamMemberData):


class Team:
"""
Attributes:
----------
icon: :class:``
The icon of the team.
id: :class:`int`
The id of the team.
members: :class:`list`
The members in the team.
name: :class:`str`
The name of the team.
owner_user_id: :class:`int`
The owner id of the team.
"""
def __init__(self, data: TeamData):
"""
Parameters:
----------
data: :class:`discord_typings.TeamData`
The data of the team
"""
self.icon = data["icon"]
self.id = int(data["id"])
self.members = [TeamMember(member) for member in data["members"]]
Expand All @@ -31,7 +86,59 @@ def __init__(self, data: TeamData):


class Application:
"""
Attributes:
----------
id: :class:`int`
The id of the application
name: :class:`str`
The name of the application
icon: :class:``
The icon of the application
description: :class:`str`
The description of the application
rpc_origins: :class:`list[str]`
A list of RPC origins for the application
bot_public: :class:`bool`
A boolean representing if the bot is public
bot_require_code_grant: :class:`bool`
A boolean representing if the bot requires a code grant
terms_of_service_url: :class:`str`
The Terms of Service url.
privacy_policy_url = :class:`str`
The Privacy Policy url
owner: :class:``
The owner of the application.
verify_key: :class:`str`
A string used to verify signatures for receiving interactions via HTTP.
team: :class:`Epikcord.application.Team`
The team the application is in.
guild_id: :class:`int`
The id of guild
primary_sku_id: :class:`int`
...
slug: :class:``
...
cover_image: :class:``
...
flags: :class:`Epikcord.flags.ApplicationFlags`
...
tags: :class:``
...
install_params: :class:`Optional[InstallParams]`
The install parameters of the application.
self.custom_install_url: :class:`Optional[str]`
The URL to redirect users to once they click "Add Bot" in the client.
self.role_connections_verification_url: :class:`Optional[str]`
The URL that users are redirected to if they want to link a role.
"""
def __init__(self, data: ApplicationData):
"""
Paramters:
---------
data: :class:`discord_typings.ApplicationData`
The data of the Application
"""
self.id = int(data["id"])
self.name = data["name"]
self.icon = data.get("icon")
Expand Down
101 changes: 100 additions & 1 deletion EpikCord/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,31 @@ class LocatedError:


class HTTPException(EpikCordException):
"""Exception raised when the webserver throws an error.

This inherits from :class:`EpikcordException`.


Attributes
----------
body: :class:`dict`
...
code: :class:``
The error code.
message: :class:``
The message it returns.
errors: :class:`dict`
The errors it returns.
errors_list: :class:`list`
...
"""
def __init__(self, data: Dict):
"""
Parameters:
----------
data: :class:`typing.Dict`
...
"""
self.body = data
self.code = data.get("code")
self.message = data.get("message")
Expand All @@ -28,7 +52,21 @@ def __init__(self, data: Dict):
)

def extract_errors(self, d, key_path=None):
"""Get _errors key from the given dictionary."""
"""Get _errors key from the given dictionary.

Parameters:
----------
d: :class:`dict`
...
key_path: :class:``
...

Returns
-------
...:
...

"""
if key_path is None:
key_path = []

Expand All @@ -53,50 +91,111 @@ def extract_errors(self, d, key_path=None):


class NotFound(HTTPException):
"""Exception that's raised when status code 404 occurs.

This inherits from :class:`HTTPException`.
"""
...


class Forbidden(HTTPException):
"""Exception that's raised when status code 403 occurs.

This inherits from :class:`HTTPException`.
"""
...


class Unauthorized(HTTPException):
"""Exception raised due to

This inherits from :class:`HTTPException`.
"""
...


class BadRequest(HTTPException):
"""Exception raised due to

This inherits from :class:`HTTPException`.
"""
...


class TooManyRetries(EpikCordException):
"""Exception raised when

This inherits from :class:`EpikCordException`.
"""
...


class ClosedWebSocketConnection(EpikCordException):
"""Exception raised due to

This inherits from :class:`EpikCordException`.
"""
...


class DisallowedIntents(ClosedWebSocketConnection):
"""Exception raised due to

This inherits from :class:`EpikCordException`.
"""
...


class InvalidIntents(ClosedWebSocketConnection):
"""Exception raised when an intent does not exist.

This inherits from :class:`EpikCordException`.
"""
...


class InvalidToken(ClosedWebSocketConnection):
"""Exception raised when fails to log you in from improper credentials.

This inherits from :class:`EpikCordException`.
"""
...


class GatewayRateLimited(ClosedWebSocketConnection):
"""Exception that's raised when status code 429 occurs.

This inherits from :class:`EpikCordException`.
"""
...


class ShardingRequired(ClosedWebSocketConnection):
"""Exception raised due to

This inherits from :class:`EpikCordException`.
"""
...


class UnknownMimeType(EpikCordException):
"""Exception raised due to

This inherits from :class:`EpikCordException`.

Attributes:
----------
filename: :class:``
The name of the file.
message: :class:`str`
The message raised by error.
"""
def __init__(self, filename):
"""
Parameters:
----------
filename: :class:``
The name of the file.
"""
self.filename = filename
self.message = f"Cannot resolve mime type for file `{filename}`."
Loading