Skip to content

feat(cache,http,model)!: add AfkTimeout for Guild::afk_timeout#1922

Merged
7596ff merged 3 commits intonextfrom
itohatweb/feat/guild-afk-timeout-values
Jan 6, 2023
Merged

feat(cache,http,model)!: add AfkTimeout for Guild::afk_timeout#1922
7596ff merged 3 commits intonextfrom
itohatweb/feat/guild-afk-timeout-values

Conversation

@itohatweb
Copy link
Member

@itohatweb itohatweb commented Sep 16, 2022

The AFK timeout of a guild has been represented as an integer, despite the fact that the AFK timeout of a guild can only be a select list of integers rather than a freeform value. To achieve a nice UX while maintaining the representation of an integer, a newtype over an integer with associated constants for known valid values has been introduced.

Example:

use twilight_model::guild::AfkTimeout;

assert_eq!(300, AfkTimeout::FIVE_MINUETES.get());
assert_eq!(300, AfkTimeout::FIVE_MINUTES); // impl PartialEq<AfkTimeout> for u16

Reference: #1904

Closes: #1904

@github-actions github-actions bot added c-cache Affects the cache crate c-model Affects the model crate m-breaking change Breaks the public API. t-feature Addition of a new feature labels Sep 16, 2022
@itohatweb itohatweb linked an issue Sep 16, 2022 that may be closed by this pull request
@github-actions github-actions bot added the c-http Affects the http crate label Sep 16, 2022
@itohatweb itohatweb changed the title feat(cache/inmemory,model)!: add AfkTimeout for Guild::afk_timeout feat(cache/inmemory,http,model)!: add AfkTimeout for Guild::afk_timeout Sep 16, 2022
7596ff
7596ff previously requested changes Sep 16, 2022
Copy link
Member

@vilgotf vilgotf left a comment

Choose a reason for hiding this comment

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

How about using associated consts and a newtype?

pub struct AfkTimeout(u16);

impl AfkTimeout {
    pub const ONE_MINUTE: Self = Self(60);
    // etc
}

Rework AFK timeouts from being a simple integer to a newtype with
associated constants for valid values and parsing into
`std::time::Duration`s.

BREAKING CHANGES: `Guild::afk_timeout` and similar are now
`twilight_model::guild::AfkTimeout` instead of an integer.
@spring4175 spring4175 force-pushed the itohatweb/feat/guild-afk-timeout-values branch from 30299c5 to f86a3a7 Compare December 28, 2022 04:54
@spring4175 spring4175 changed the base branch from old-next to next December 28, 2022 04:54
@github-actions github-actions bot added c-all Affects all crates or the project as a whole c-book Affects the book c-gateway Affects the gateway crate c-gateway-queue Affects the gateway queue crate c-http-ratelimiting Affects the http ratelimiting crate t-ci Anything to do with CI. c-model Affects the model crate and removed c-model Affects the model crate c-gateway Affects the gateway crate c-gateway-queue Affects the gateway queue crate c-book Affects the book c-http-ratelimiting Affects the http ratelimiting crate labels Dec 28, 2022
@spring4175 spring4175 requested a review from 7596ff December 28, 2022 05:20
@7596ff 7596ff changed the title feat(cache/inmemory,http,model)!: add AfkTimeout for Guild::afk_timeout feat(cache,http,model)!: add AfkTimeout for Guild::afk_timeout Dec 29, 2022
Copy link
Member

@vilgotf vilgotf left a comment

Choose a reason for hiding this comment

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

Using associated consts looks slick!

Comment on lines +51 to +55
impl From<u16> for AfkTimeout {
fn from(value: u16) -> Self {
Self(value)
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Just highlighting that this allows any value

Copy link
Member

Choose a reason for hiding this comment

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

I think this is fine since it's non exaustive and we have no guarantee discord won't add any extra values later

@7596ff 7596ff merged commit c5fb4db into next Jan 6, 2023
@7596ff 7596ff deleted the itohatweb/feat/guild-afk-timeout-values branch January 6, 2023 23:20
@spring4175 spring4175 mentioned this pull request Jan 8, 2023
16 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c-all Affects all crates or the project as a whole c-cache Affects the cache crate c-http Affects the http crate c-model Affects the model crate m-breaking change Breaks the public API. t-ci Anything to do with CI. t-feature Addition of a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Guild::afk_timeout values

5 participants