-
-
Notifications
You must be signed in to change notification settings - Fork 482
feat: Guild Builder #2662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
DA-344
wants to merge
8
commits into
Pycord-Development:master
from
DA-344:feat/create-guild-parameters
Closed
feat: Guild Builder #2662
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
325417d
feat: Add more Client.create_guild parameters and make it return a Gu…
DA-344 4de7469
chore: Update channel.py:__all__ and added guild_builder to __init__.py
DA-344 5029863
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] ec60303
Merge branch 'master' of https://github.com/Pycord-Development/pycord…
DA-344 2f37843
chore: Update builder
DA-344 2c2b5b0
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] da9f389
fix: Client.create_guild return on docstring
DA-344 1458bcc
Merge branch 'feat/create-guild-parameters' of https://github.com/DA-…
DA-344 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
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 |
---|---|---|
|
@@ -42,16 +42,23 @@ | |
from .backoff import ExponentialBackoff | ||
from .channel import PartialMessageable, _threaded_channel_factory | ||
from .emoji import AppEmoji, GuildEmoji | ||
from .enums import ChannelType, Status | ||
from .enums import ( | ||
ChannelType, | ||
ContentFilter, | ||
NotificationLevel, | ||
Status, | ||
VerificationLevel, | ||
) | ||
from .errors import * | ||
from .flags import ApplicationFlags, Intents | ||
from .gateway import * | ||
from .guild import Guild | ||
from .guild_builder import GuildBuilder | ||
from .http import HTTPClient | ||
from .invite import Invite | ||
from .iterators import EntitlementIterator, GuildIterator | ||
from .mentions import AllowedMentions | ||
from .monetization import SKU, Entitlement | ||
from .monetization import SKU | ||
from .object import Object | ||
from .stage_instance import StageInstance | ||
from .state import ConnectionState | ||
|
@@ -1597,15 +1604,21 @@ async def create_guild( | |
self, | ||
*, | ||
name: str, | ||
icon: bytes = MISSING, | ||
icon: bytes | None = MISSING, | ||
code: str = MISSING, | ||
verification_level: VerificationLevel = MISSING, | ||
content_filter: ContentFilter = MISSING, | ||
notification_level: NotificationLevel = MISSING, | ||
afk_timeout: int = MISSING, | ||
) -> Guild: | ||
"""|coro| | ||
|
||
Creates a :class:`.Guild`. | ||
|
||
Bot accounts in more than 10 guilds are not allowed to create guilds. | ||
|
||
Also see :meth:`.Client.build_guild`. | ||
|
||
Parameters | ||
---------- | ||
name: :class:`str` | ||
|
@@ -1617,30 +1630,108 @@ async def create_guild( | |
The code for a template to create the guild with. | ||
|
||
.. versionadded:: 1.4 | ||
verification_level: :class:`VerificationLevel` | ||
The verification level. | ||
|
||
.. versionadded:: 2.7 | ||
content_filter: :class:`ContentFilter` | ||
The explicit content filter level. | ||
|
||
.. versionadded:: 2.7 | ||
notification_level: :class:`NotificationLevel` | ||
The default message notification level. | ||
|
||
.. versionadded:: 2.7 | ||
afk_timeout: :class:`int` | ||
The afk timeout in seconds. | ||
|
||
.. versionadded:: 2.7 | ||
|
||
Returns | ||
------- | ||
:class:`.Guild` | ||
The guild created. This is not the same guild that is | ||
added to cache. | ||
|
||
Raises | ||
------ | ||
:exc:`HTTPException` | ||
Guild creation failed. | ||
:exc:`InvalidArgument` | ||
Invalid icon image format given. Must be PNG or JPG. | ||
""" | ||
if icon is not MISSING: | ||
icon_base64 = utils._bytes_to_base64_data(icon) | ||
else: | ||
icon_base64 = None | ||
if code is MISSING: | ||
code = None # type: ignore | ||
|
||
if code: | ||
data = await self.http.create_from_template(code, name, icon_base64) | ||
else: | ||
data = await self.http.create_guild(name, icon_base64) | ||
return Guild(data=data, state=self._connection) | ||
metadata = {} | ||
|
||
if verification_level is not MISSING: | ||
metadata["verification_level"] = verification_level.value | ||
if content_filter is not MISSING: | ||
metadata["explicit_content_filter"] = content_filter.value | ||
if notification_level is not MISSING: | ||
metadata["default_message_notifications"] = notification_level.value | ||
if afk_timeout is not MISSING: | ||
metadata["afk_timeout"] = afk_timeout | ||
|
||
# TODO: remove support of passing ``None`` to ``icon``. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure why you rewrote it like this, the old code for |
||
if icon is None: | ||
icon = MISSING | ||
|
||
builder = GuildBuilder( | ||
state=self._connection, name=name, icon=icon, code=code, metadata=metadata # type: ignore | ||
) | ||
return await builder | ||
|
||
def build_guild( | ||
self, | ||
*, | ||
name: str, | ||
icon: bytes = MISSING, | ||
verification_level: VerificationLevel = MISSING, | ||
content_filter: ContentFilter = MISSING, | ||
notification_level: NotificationLevel = MISSING, | ||
afk_timeout: int = MISSING, | ||
) -> GuildBuilder: | ||
"""Creates a :class:`.GuildBuilder` object to create a guild. | ||
|
||
Also see :meth:`.Client.create_guild`. | ||
|
||
.. versionadded:: 2.7 | ||
|
||
Parameters | ||
---------- | ||
name: :class:`str` | ||
The guild name. | ||
icon: :class:`bytes` | ||
The :term:`py:bytes-like object` representing the icon. See :meth:`.ClientUser.edit` | ||
for more details on what is expected. | ||
verification_level: :class:`VerificationLevel` | ||
The verification level. | ||
content_filter: :class:`ContentFilter` | ||
The explicit content filter level. | ||
notification_level: :class:`NotificationLevel` | ||
The defualt message notification level. | ||
afk_timeout: :class:`int` | ||
The afk timeout in seconds. | ||
|
||
Returns | ||
------- | ||
:class:`GuildBuilder` | ||
The guild builder to create the new guild. | ||
""" | ||
|
||
metadata = {} | ||
|
||
if verification_level is not MISSING: | ||
metadata["verification_level"] = verification_level.value | ||
if content_filter is not MISSING: | ||
metadata["explicit_content_filter"] = content_filter.value | ||
if notification_level is not MISSING: | ||
metadata["default_message_notifications"] = notification_level.value | ||
if afk_timeout is not MISSING: | ||
metadata["afk_timeout"] = afk_timeout | ||
|
||
return GuildBuilder( | ||
state=self._connection, | ||
name=name, | ||
icon=icon, | ||
code=None, | ||
metadata=metadata, | ||
) | ||
|
||
async def fetch_stage_instance(self, channel_id: int, /) -> StageInstance: | ||
"""|coro| | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally don't know if
code
should useGuildBuilder
, considering all the new parameters would be ignored (if anything it should raise a ValueError for passing it with them), though regardless i suggestcreate_guild
be completely detached fromGuildBuilder
so all of its logic can remain isolated inbuild_guild
(though i think you've said you're planning on this, either way there's no rush)Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also why type ignore ? If needed used an overload.