This repository was archived by the owner on Aug 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Add some models classes #6
Open
Gugu7264
wants to merge
26
commits into
nextcord:master
Choose a base branch
from
Gugu7264:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 14 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
35a51bd
chore: Update gitignore
Gugu7264 13f91cd
feat: Added User and ClientUser models
Gugu7264 adffec1
chore: Rename folders and added snowflake type
Gugu7264 60ee0df
refactor: moved BaseUser in protocols
Gugu7264 9d9c2cf
Merge branch 'nextcord:master' into master
Gugu7264 36a0f4b
fix: fixed relative imports
Gugu7264 d6baf9c
feat: adding Messageable and Embed models
Gugu7264 d5f7404
refactor: renamed embed functions
Gugu7264 1c0f1eb
feat: added InvalidArgument exception
Gugu7264 a3663cc
feat: Added Embed class and Embed* classes
Gugu7264 9a1d3ab
feat: switched video and provider to properties, added [from/to]_dict…
Gugu7264 1accd2a
feat: added allowed_mentions, modified embed, started work on channel…
Gugu7264 24f737e
Merge branch 'nextcord:master' into master
Gugu7264 31e0af9
refactor: linted
Gugu7264 91c5386
style: switched to comments for license
Gugu7264 9b2b62e
revert: remove abc.py ; early WIP
Gugu7264 8c1cd9e
fix: pull upstream and resolve conflicts
Gugu7264 53484c4
refactor/fix: moves code around and fixes typehinting
Gugu7264 6d711aa
Delete abc.py
Gugu7264 1cd594d
chore: subclass Protocol and use cls()
Gugu7264 3e08309
Merge branch 'master' of https://github.com/nextcord/nextcord-v3
Gugu7264 da41a2c
chore: fix mypy errors
Gugu7264 40b3721
Merge branch 'master' of https://github.com/nextcord/nextcord-v3
Gugu7264 3bb752b
fix: from_dict and to_dict now working almost entirely
Gugu7264 f66da5f
chore: change test
Gugu7264 cf51ca2
refactor: rename SnowflakeArray to SnowflakeList
Gugu7264 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -140,3 +140,4 @@ cython_debug/ | |
# Editors | ||
.vscode/ | ||
.idea/ | ||
.nova/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
""" | ||
The MIT License (MIT) | ||
Copyright (c) 2021-present vcokltfre & tag-epic | ||
Permission is hereby granted, free of charge, to any person obtaining a | ||
copy of this software and associated documentation files (the "Software"), | ||
to deal in the Software without restriction, including without limitation | ||
the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
and/or sell copies of the Software, and to permit persons to whom the | ||
Gugu7264 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Software is furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
DEALINGS IN THE SOFTWARE. | ||
""" | ||
from __future__ import annotations | ||
|
||
from logging import getLogger | ||
from typing import TYPE_CHECKING, Union | ||
|
||
if TYPE_CHECKING: | ||
... | ||
|
||
|
||
Role, User = None # TODO: DEFINE and import | ||
Gugu7264 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
logger = getLogger(__name__) | ||
|
||
|
||
class AllowedMentions: | ||
def __init__( | ||
self, | ||
*, | ||
everyone: bool = False, | ||
roles: Union[bool, list[Role], Role] = False, | ||
users: Union[bool, User, list[User]] = True, | ||
replied_user: bool = None, | ||
): | ||
self.everyone = everyone | ||
self.roles = roles | ||
self.users = users | ||
self.replied_user = replied_user | ||
|
||
def to_dict(self): | ||
allowed = {"parse": []} | ||
if self.everyone: | ||
allowed["parse"].append("everyone") | ||
|
||
if isinstance(self.roles, bool) and self.roles: | ||
allowed["parse"].append("roles") | ||
elif isinstance(self.roles, list): | ||
allowed["roles"] = [r.id for r in self.roles] | ||
elif isinstance(self.roles, Role): | ||
allowed["roles"] = [self.roles.id] | ||
|
||
if isinstance(self.users, bool) and self.roles: | ||
allowed["parse"].append("users") | ||
elif isinstance(self.users, list): | ||
allowed["users"] = [u.id for u in self.roles] | ||
elif isinstance(self.users, User): | ||
allowed["users"] = [self.users.id] | ||
|
||
if self.replied_user: | ||
allowed["replied_user"] = bool(self.replied_user) | ||
|
||
@classmethod | ||
def none(cls): | ||
return cls.__init__( | ||
everyone=False, roles=False, users=False, replied_user=False | ||
) | ||
|
||
@classmethod | ||
def all(cls): | ||
return cls.__init__(everyone=True, roles=True, users=True, replied_user=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
""" | ||
The MIT License (MIT) | ||
Copyright (c) 2021-present vcokltfre & tag-epic | ||
Permission is hereby granted, free of charge, to any person obtaining a | ||
copy of this software and associated documentation files (the "Software"), | ||
to deal in the Software without restriction, including without limitation | ||
the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
and/or sell copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
DEALINGS IN THE SOFTWARE. | ||
""" | ||
from __future__ import annotations | ||
|
||
from logging import getLogger | ||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from ..client.state import State | ||
|
||
logger = getLogger(__name__) | ||
|
||
|
||
class Channel: | ||
def __init__(self, *, state: State, data: dict): | ||
Gugu7264 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
""" | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2021-present vcokltfre & tag-epic | ||
Permission is hereby granted, free of charge, to any person obtaining a | ||
copy of this software and associated documentation files (the "Software"), | ||
to deal in the Software without restriction, including without limitation | ||
the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
and/or sell copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
DEALINGS IN THE SOFTWARE. | ||
""" | ||
from __future__ import annotations | ||
|
||
from dataclasses import dataclass | ||
from logging import getLogger | ||
from typing import TYPE_CHECKING, Optional | ||
|
||
if TYPE_CHECKING: | ||
from datetime import datetime | ||
|
||
|
||
logger = getLogger(__name__) | ||
|
||
|
||
@dataclass(frozen=True) | ||
class EmbedFile: | ||
url: str | ||
proxy_url: Optional[str] = None | ||
height: Optional[int] = None | ||
TAG-Epic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
width: Optional[int] = None | ||
|
||
|
||
@dataclass(frozen=True) | ||
class EmbedThumbnail(EmbedFile): | ||
... | ||
|
||
|
||
@dataclass(frozen=True) | ||
class EmbedVideo(EmbedFile): | ||
url: Optional[str] = None | ||
|
||
|
||
@dataclass(frozen=True) | ||
class EmbedImage(EmbedFile): | ||
... | ||
|
||
|
||
@dataclass(frozen=True) | ||
class EmbedProvider: | ||
name: Optional[str] = None | ||
url: Optional[str] = None | ||
|
||
|
||
@dataclass(frozen=True) | ||
class EmbedAuthor: | ||
name: str | ||
url: Optional[str] = None | ||
icon_url: Optional[str] = None | ||
proxy_icon_url: Optional[str] = None | ||
|
||
|
||
@dataclass(frozen=True) | ||
class EmbedFooter: | ||
text: str | ||
icon_url: Optional[str] = None | ||
proxy_icon_url: Optional[str] = None | ||
|
||
|
||
class EmbedField: | ||
def __init__(self, name: str, value: str, *, inline: bool = None): | ||
self.name = str(name) | ||
self.value = str(value) | ||
self.inline = bool(inline) | ||
|
||
|
||
class Embed: | ||
__slots__ = ( | ||
"title", | ||
"description", | ||
"url", | ||
"timestamp", | ||
"color", | ||
"footer", | ||
"image", | ||
"thumbnail", | ||
"author", | ||
"fields", | ||
"provider", | ||
"video", | ||
) | ||
|
||
def __init__( | ||
self, | ||
*, | ||
title: Optional[str] = None, | ||
description: Optional[str] = None, | ||
url: Optional[str] = None, | ||
timestamp: Optional[datetime] = None, | ||
color: Optional[int] = None, | ||
footer: Optional[EmbedFooter] = None, | ||
image: Optional[EmbedImage] = None, | ||
thumbnail: Optional[EmbedThumbnail] = None, | ||
author: Optional[EmbedAuthor] = None, | ||
fields: Optional[list[EmbedField]] = [], | ||
): | ||
self.title = str(title) if title is not None else None | ||
self.description = str(description) if description is not None else None | ||
self.url = str(url) if url is not None else None | ||
self.color = int(color) if color is not None else None | ||
self.timestamp = timestamp | ||
|
||
self.footer = footer if isinstance(footer, EmbedFooter) else None | ||
self.image = image if isinstance(image, EmbedImage) else None | ||
self.thumbnail = thumbnail if isinstance(thumbnail, EmbedThumbnail) else None | ||
self.author = author if isinstance(author, EmbedAuthor) else None | ||
self.fields = fields if isinstance(fields, list) else [] | ||
|
||
def add_field( | ||
self, name: str, value: str, *, inline: bool = None, position: int = None | ||
) -> None: | ||
if position is not None: | ||
self.fields.insert(position, EmbedField(name, value, inline=inline)) | ||
else: | ||
self.fields.append(EmbedField(name, value, inline=inline)) | ||
|
||
def edit_field( | ||
self, index: int, name: str = None, value: str = None, *, inline: bool = None | ||
) -> None: | ||
if name is not None: | ||
self.fields[index].name = name | ||
if value is not None: | ||
self.fields[index].value = value | ||
if inline is not None: | ||
self.fields[index].inline = inline | ||
|
||
def remove_field(self, *, index: int) -> None: | ||
try: | ||
del self.fields[index] | ||
except IndexError: | ||
pass | ||
|
||
@property | ||
def video(self): | ||
return self._video | ||
|
||
@property | ||
def provider(self): | ||
return self._provider | ||
|
||
@classmethod | ||
def from_dict(cls, data: dict): | ||
embed = cls.__init__() | ||
for key, value in data.items(): | ||
Gugu7264 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if key in ["video", "provider"]: | ||
setattr(embed, "_" + key, value) | ||
elif key in embed.__slots__: | ||
setattr(embed, key, value) | ||
else: | ||
continue # TODO: Unknown key, should it raise an error? | ||
|
||
return embed | ||
|
||
def to_dict(self): | ||
data = {} | ||
for key in self.__slots__: | ||
if key in ["video", "provider"]: | ||
data[key] = getattr(self, "_" + key) | ||
else: | ||
data[key] = getattr(self, key) | ||
|
||
return data |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.