Skip to content
This repository has been archived by the owner on Jul 11, 2024. It is now read-only.

feat: Adds communication_disabled_until to support user timeouts #474

Merged
merged 5 commits into from
Mar 1, 2022

Conversation

aidenwallis
Copy link
Contributor

Description

Adds support for user timeouts using communication_disabled_until field on guild member objects.

https://discord.com/developers/docs/resources/guild#guild-member-object
https://discord.com/developers/docs/resources/guild#modify-guild-member

Breaking Change?

no

Checklist:

  • I have performed a self-review of my own code
  • Commented complex situations or referenced the discord documentation
  • Updated documentation
  • Added/Updated unit tests
  • Added/Updated benchmarks (if this is a performance critical component)

Roles []Snowflake `json:"roles"`
JoinedAt Time `json:"joined_at,omitempty"`
PremiumSince Time `json:"premium_since,omitempty"`
CommunicationDisabledUntil Time `json:"communication_disabled_until"`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me this makes more sense to be *Time as the field can be null, but it looks like other nullable time fields like PremiumSince do this, so am following that behaviour.

@@ -123,6 +123,8 @@ type UpdateMember struct {
Mute *bool `json:"mute,omitempty"`
Deaf *bool `json:"deaf,omitempty"`
ChannelID *Snowflake `json:"channel_id,omitempty"`
// CommunicationDisabledUntil defines when the user's timeout will expire and the user will be able to communicate in the guild again (up to 28 days in the future)
CommunicationDisabledUntil *Time `json:"communication_disabled_until,omitempty"`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One caveat is as we use omitempty, you can't set this field to null from what I can tell to remove a users timeout. Perhaps the Time struct could be extended to support returning null in MarshalJSON when you set something like Time.Null = true instead of returning an empty string if you set the time to zero: https://github.com/andersfylling/disgord/blob/master/struct.go#L85-L88

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to throw up a tests to show this behavior? A simple unit table tests or something.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a unit test to show it as TestUpdateMemberParams 👍

@aidenwallis aidenwallis changed the title Adds communication_disabled_until to support user timeouts feat: Adds communication_disabled_until to support user timeouts Feb 16, 2022
@andersfylling
Copy link
Owner

Nice work, and good catch on the Time struct. It should be updated indeed!

@andersfylling andersfylling merged commit 2c210e2 into andersfylling:master Mar 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants