Skip to content
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

feat: Implement Onboarding features #2127

Merged
merged 41 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
feadbca
initial onboarding impl.
NeloBlivion Jun 16, 2023
6368fb9
Implement main edit function
NeloBlivion Jun 16, 2023
93d8350
implement shorthand edit
NeloBlivion Jun 16, 2023
3eee4ac
typo
NeloBlivion Jun 16, 2023
9800890
better doc
NeloBlivion Jun 16, 2023
cecf1a6
misc
NeloBlivion Jun 16, 2023
7dca3f9
fix enums
NeloBlivion Jun 16, 2023
d607fea
fix repr
NeloBlivion Jun 16, 2023
32d7bee
docs adjust
NeloBlivion Jun 16, 2023
085b0ec
fix edit args
NeloBlivion Jun 16, 2023
8f69296
import fixes
NeloBlivion Jun 16, 2023
4b473f7
docs clarify
NeloBlivion Jun 16, 2023
f8075f5
final touches?
NeloBlivion Jun 16, 2023
a421f3e
randint...?
NeloBlivion Jun 16, 2023
6de5886
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 16, 2023
8001991
Merge branch 'master' into onboarding
NeloBlivion Jun 16, 2023
6a7d37c
typefix
NeloBlivion Jun 16, 2023
7f51458
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 16, 2023
eec8e67
docs updates
NeloBlivion Jun 18, 2023
80b1194
cleanup
NeloBlivion Jun 18, 2023
cbcadf2
Merge branch 'master' into onboarding
NeloBlivion Jun 25, 2023
11f096c
Merge branch 'master' into onboarding
NeloBlivion Jun 29, 2023
97d8f3e
Merge branch 'master' into onboarding
Lulalaby Jul 24, 2023
c7741ac
Merge branch 'master' into onboarding
Lulalaby Jul 27, 2023
abb4ee2
Merge branch 'master' into onboarding
NeloBlivion Jan 30, 2024
e5d9d2f
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 30, 2024
2f1b06f
Update enum
NeloBlivion Jan 31, 2024
514a6af
Update enums
NeloBlivion Jan 31, 2024
7a5844f
Replace _guild with guild
NeloBlivion Jan 31, 2024
652d6ea
Add new PromptOptions fields
NeloBlivion Jan 31, 2024
57afa9b
Update to_dict for emoji changes and exchange randint for generate_sn…
NeloBlivion Jan 31, 2024
a5c34fa
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 31, 2024
e713a54
Final push
NeloBlivion Jan 31, 2024
44449ee
Merge branch 'master' into onboarding
NeloBlivion Jan 31, 2024
2cf4138
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 31, 2024
f710cb3
remove debug lines
NeloBlivion Jan 31, 2024
17a87ea
thanku doruk
NeloBlivion Jan 31, 2024
a0d1532
chore: minimal changes
Dorukyum Jan 31, 2024
f2537fa
chore: finalize
Dorukyum Jan 31, 2024
47e89cd
chore: promise this is the last
Dorukyum Jan 31, 2024
d01ffc9
Merge branch 'master' into onboarding
Lulalaby Jan 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ These changes are available on the `master` branch, but have not yet been releas
([#2322](https://github.com/Pycord-Development/pycord/pull/2322))
- Added `User.avatar_decoration`.
([#2131](https://github.com/Pycord-Development/pycord/pull/2131))
- Added support for guild onboarding related features.
([#2127](https://github.com/Pycord-Development/pycord/pull/2127))

### Changed

Expand Down
1 change: 1 addition & 0 deletions discord/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
from .mentions import *
from .message import *
from .object import *
from .onboarding import *
from .partial_emoji import *
from .permissions import *
from .player import *
Expand Down
32 changes: 32 additions & 0 deletions discord/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
"AutoModActionType",
"AutoModKeywordPresetType",
"ApplicationRoleConnectionMetadataType",
"PromptType",
"OnboardingMode",
"ReactionType",
)

Expand Down Expand Up @@ -428,6 +430,11 @@ class AuditLogAction(Enum):
auto_moderation_user_communication_disabled = 145
creator_monetization_request_created = 150
creator_monetization_terms_accepted = 151
onboarding_question_create = 163
onboarding_question_update = 164
onboarding_update = 167
server_guide_create = 190
server_guide_update = 191

@property
def category(self) -> AuditLogActionCategory | None:
Expand Down Expand Up @@ -490,6 +497,11 @@ def category(self) -> AuditLogActionCategory | None:
AuditLogAction.auto_moderation_user_communication_disabled: None,
AuditLogAction.creator_monetization_request_created: None,
AuditLogAction.creator_monetization_terms_accepted: None,
AuditLogAction.onboarding_question_create: AuditLogActionCategory.create,
AuditLogAction.onboarding_question_update: AuditLogActionCategory.update,
AuditLogAction.onboarding_update: AuditLogActionCategory.update,
AuditLogAction.server_guide_create: AuditLogActionCategory.create,
AuditLogAction.server_guide_update: AuditLogActionCategory.update,
}
return lookup[self]

Expand Down Expand Up @@ -530,6 +542,12 @@ def target_type(self) -> str | None:
return "application_command_permission"
elif v < 146:
return "auto_moderation_rule"
elif v < 152:
return "monetization"
elif v < 168:
return "onboarding"
NeloBlivion marked this conversation as resolved.
Show resolved Hide resolved
elif v < 192:
return "server_guide"


class UserFlags(Enum):
Expand Down Expand Up @@ -946,6 +964,20 @@ class ApplicationRoleConnectionMetadataType(Enum):
boolean_not_equal = 8


class PromptType(Enum):
"""Guild Onboarding Prompt Type"""

multiple_choice = 0
dropdown = 1


class OnboardingMode(Enum):
"""Guild Onboarding Mode"""

default = 0
advanced = 1
NeloBlivion marked this conversation as resolved.
Show resolved Hide resolved


class ReactionType(Enum):
"""The reaction type"""

Expand Down
83 changes: 83 additions & 0 deletions discord/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
from .iterators import AuditLogIterator, BanIterator, MemberIterator
from .member import Member, VoiceState
from .mixins import Hashable
from .onboarding import Onboarding
from .permissions import PermissionOverwrite
from .role import Role
from .scheduled_events import ScheduledEvent, ScheduledEventLocation
Expand Down Expand Up @@ -3842,6 +3843,88 @@ async def create_auto_moderation_rule(
)
return AutoModRule(state=self._state, data=data)

async def onboarding(self):
"""|coro|

Returns the :class:`Onboarding` flow for the guild.

.. versionadded:: 2.5

Returns
-------
:class:`Onboarding`
The onboarding flow for the guild.

Raises
------
HTTPException
Retrieving the onboarding flow failed somehow.
"""
data = await self._state.http.get_onboarding(self.id)
return Onboarding(data=data, guild=self)

async def edit_onboarding(
self,
*,
prompts: list[OnboardingPrompt] | None = MISSING,
default_channels: list[Snowflake] | None = MISSING,
enabled: bool | None = MISSING,
mode: OnboardingMode | None = MISSING,
reason: str | None = MISSING,
) -> Onboarding:
"""|coro|

A shorthand for :attr:`Onboarding.edit` without fetching the onboarding flow.

You must have the :attr:`~Permissions.manage_guild` and :attr:`~Permissions.manage_roles` permissions in the
guild to do this.

Parameters
----------

prompts: Optional[List[:class:`OnboardingPrompt`]]
The new list of prompts for this flow.
default_channels: Optional[List[:class:`Snowflake`]]
The new default channels that users are opted into.
enabled: Optional[:class:`bool`]
Whether onboarding should be enabled. Setting this to ``True`` requires
the guild to have ``COMMUNITY`` in :attr:`~Guild.features` and at
least 7 ``default_channels``.
mode: Optional[:class:`OnboardingMode`]
The new onboarding mode.
reason: Optional[:class:`str`]
The reason that shows up on Audit log.

Returns
-------
:class:`Onboarding`
The updated onboarding flow.

Raises
------

HTTPException
Editing the onboarding flow failed somehow.
Forbidden
You don't have permissions to edit the onboarding flow.
"""

fields: dict[str, Any] = {}
if prompts is not MISSING:
fields["prompts"] = [prompt.to_dict() for prompt in prompts]

if default_channels is not MISSING:
fields["default_channel_ids"] = [channel.id for channel in default_channels]

if enabled is not MISSING:
fields["enabled"] = enabled

if mode is not MISSING:
fields["mode"] = mode.value

new = await self._state.http.edit_onboarding(self.id, fields, reason=reason)
return Onboarding(data=new, guild=self)

async def delete_auto_moderation_rule(
self,
id: int,
Expand Down
24 changes: 24 additions & 0 deletions discord/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
invite,
member,
message,
onboarding,
role,
scheduled_events,
sticker,
Expand Down Expand Up @@ -2884,6 +2885,29 @@ def update_application_role_connection_metadata_records(
)
return self.request(r, json=payload)

# Onboarding

def get_onboarding(self, guild_id: Snowflake) -> Response[onboarding.Onboarding]:
return self.request(
Route("GET", "/guilds/{guild_id}/onboarding", guild_id=guild_id)
)

def edit_onboarding(
self, guild_id: Snowflake, payload: Any, *, reason: str | None = None
) -> Response[onboarding.Onboarding]:
keys = (
"prompts",
"default_channel_ids",
"enabled",
"mode",
)
payload = {key: val for key, val in payload.items() if key in keys}
return self.request(
Route("PUT", "/guilds/{guild_id}/onboarding", guild_id=guild_id),
json=payload,
reason=reason,
)

# Misc

def application_info(self) -> Response[appinfo.AppInfo]:
Expand Down