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(guild): support guild incidents #1230

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
feat: incident actions editing
  • Loading branch information
shiftinv committed Oct 4, 2023
commit f7a6f38c2f591af4ac4efdd15082713ddc96816e
38 changes: 37 additions & 1 deletion disnake/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -2085,7 +2085,9 @@ async def edit(
splash: Optional[AssetBytes] = MISSING,
discovery_splash: Optional[AssetBytes] = MISSING,
community: bool = MISSING,
invites_disabled: bool = MISSING,
invites_disabled: Union[bool, datetime.timedelta, datetime.datetime] = MISSING,
# TODO: this literal is somewhat ugly
dms_disabled: Union[Literal[False], datetime.timedelta, datetime.datetime] = MISSING,
raid_alerts_disabled: bool = MISSING,
afk_channel: Optional[VoiceChannel] = MISSING,
owner: Snowflake = MISSING,
Expand Down Expand Up @@ -2266,6 +2268,40 @@ async def edit(
if vanity_code is not MISSING:
await http.change_vanity_code(self.id, vanity_code, reason=reason)

# TODO: consider turning this into a separate method instead
# TODO: also, we currently need to include the old data, otherwise existing fields get unset
if invites_disabled is not MISSING or dms_disabled is not MISSING:
payload: IncidentsDataPayload = {}

# this has turned out unnecessarily complex, but until we know more about how this
# works with the INVITES_DISABLED guild feature, it is how it is
if invites_disabled is not MISSING:
if invites_disabled is True:
pass
else:
if invites_disabled is False:
payload["invites_disabled_until"] = None
else:
if isinstance(invites_disabled, datetime.timedelta):
invites_disabled = utils.utcnow() + invites_disabled
payload["invites_disabled_until"] = utils.isoformat_utc(invites_disabled)
invites_disabled = (
MISSING # unset this so we don't try setting the guild feature below
)

if dms_disabled is not MISSING:
if dms_disabled is True:
raise ValueError("dms_disabled may not be set to `True`")
elif dms_disabled is False:
payload["dms_disabled_until"] = None
else:
if isinstance(dms_disabled, datetime.timedelta):
dms_disabled = utils.utcnow() + dms_disabled
payload["dms_disabled_until"] = utils.isoformat_utc(dms_disabled)

if payload:
await http.edit_guild_incident_actions(self.id, **payload)

fields: Dict[str, Any] = {}
if name is not MISSING:
fields["name"] = name
Expand Down
6 changes: 6 additions & 0 deletions disnake/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -1397,6 +1397,12 @@ def edit_guild(
Route("PATCH", "/guilds/{guild_id}", guild_id=guild_id), json=payload, reason=reason
)

def edit_guild_incident_actions(
self, guild_id: Snowflake, **payload: Any
) -> Response[guild.IncidentsData]:
r = Route("PUT", "/guilds/{guild_id}/incident-actions", guild_id=guild_id)
return self.request(r, json=payload)

def get_template(self, code: str) -> Response[template.Template]:
return self.request(Route("GET", "/guilds/templates/{code}", code=code))

Expand Down
2 changes: 1 addition & 1 deletion disnake/types/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class UnavailableGuild(TypedDict):
]


class IncidentsData(TypedDict):
class IncidentsData(TypedDict, total=False):
invites_disabled_until: Optional[str]
dms_disabled_until: Optional[str]
# TODO: raid_detected_at, dm_spam_detected_at ?
Expand Down