-
-
Notifications
You must be signed in to change notification settings - Fork 131
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(model,http,http-ratelimiting): Add support for application role connections metadata get/set operations #2004
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use crate::{ | ||
request::application::role_connections::{GetMetadata, SetMetadata}, | ||
Client, | ||
}; | ||
use twilight_model::{ | ||
application::role_connection::Metadata, | ||
id::{marker::ApplicationMarker, Id}, | ||
}; | ||
|
||
/// Client interface for application role connections. | ||
#[derive(Debug)] | ||
pub struct RoleConnectionsClient<'a> { | ||
application_id: Id<ApplicationMarker>, | ||
client: &'a Client, | ||
} | ||
|
||
impl<'a> RoleConnectionsClient<'a> { | ||
/// Create a new interface for using interactions. | ||
pub(super) const fn new(client: &'a Client, application_id: Id<ApplicationMarker>) -> Self { | ||
Self { | ||
application_id, | ||
client, | ||
} | ||
} | ||
|
||
/// Get application role connections metadata. | ||
pub const fn metadata(&'a self) -> GetMetadata<'a> { | ||
GetMetadata::new(self.client, self.application_id) | ||
} | ||
|
||
/// Set the application role connections metadata. | ||
pub const fn set_metadata(&'a self, records: &'a [Metadata]) -> SetMetadata<'a> { | ||
SetMetadata::new(self.client, self.application_id, records) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::RoleConnectionsClient; | ||
use static_assertions::assert_impl_all; | ||
use std::fmt::Debug; | ||
|
||
assert_impl_all!(RoleConnectionsClient<'_>: Debug, Send, Sync); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod command; | ||
pub mod interaction; | ||
pub mod role_connections; | ||
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. As with in 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. I'm not sure what you're referring to. Just to be clear - this is the app-global part of the API, not the user-specific (or guild-specific) one. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use crate::{ | ||
client::Client, | ||
error::Error, | ||
request::{Request, TryIntoRequest}, | ||
response::{marker::ListBody, Response, ResponseFuture}, | ||
routing::Route, | ||
}; | ||
use std::future::IntoFuture; | ||
use twilight_model::{ | ||
application::role_connection::Metadata, | ||
id::{marker::ApplicationMarker, Id}, | ||
}; | ||
|
||
/// Get Application Role Connection Metadata Records. | ||
#[must_use = "requests must be configured and executed"] | ||
pub struct GetMetadata<'a> { | ||
application_id: Id<ApplicationMarker>, | ||
http: &'a Client, | ||
} | ||
|
||
impl<'a> GetMetadata<'a> { | ||
pub(crate) const fn new(http: &'a Client, application_id: Id<ApplicationMarker>) -> Self { | ||
Self { | ||
application_id, | ||
http, | ||
} | ||
} | ||
|
||
/// Execute the request, returning a future resolving to a [`Response`]. | ||
#[deprecated(since = "0.14.0", note = "use `.await` or `into_future` instead")] | ||
pub fn exec(self) -> ResponseFuture<ListBody<Metadata>> { | ||
self.into_future() | ||
} | ||
} | ||
|
||
impl IntoFuture for GetMetadata<'_> { | ||
type Output = Result<Response<ListBody<Metadata>>, Error>; | ||
|
||
type IntoFuture = ResponseFuture<ListBody<Metadata>>; | ||
|
||
fn into_future(self) -> Self::IntoFuture { | ||
let http = self.http; | ||
|
||
match self.try_into_request() { | ||
Ok(request) => http.request(request), | ||
Err(source) => ResponseFuture::error(source), | ||
} | ||
} | ||
} | ||
|
||
impl TryIntoRequest for GetMetadata<'_> { | ||
fn try_into_request(self) -> Result<Request, Error> { | ||
Ok( | ||
Request::builder(&Route::GetApplicationRoleConnectionMetadataRecords { | ||
application_id: self.application_id.get(), | ||
}) | ||
.build(), | ||
) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
mod get_metadata; | ||
mod set_metadata; | ||
|
||
pub use self::{get_metadata::GetMetadata, set_metadata::SetMetadata}; | ||
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. Naming could be improved, 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. True! However, these ones are for configuring and reading the metadata for the role connections that app provides. There also has be an API for setting the actual values of the role connections per user (the @me API). |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use crate::{ | ||
client::Client, | ||
error::Error, | ||
request::{Request, RequestBuilder, TryIntoRequest}, | ||
response::{marker::ListBody, Response, ResponseFuture}, | ||
routing::Route, | ||
}; | ||
use std::future::IntoFuture; | ||
use twilight_model::{ | ||
application::role_connection::Metadata, | ||
id::{marker::ApplicationMarker, Id}, | ||
}; | ||
|
||
/// Set a user's linked roles metadata for the given application. | ||
#[must_use = "requests must be configured and executed"] | ||
pub struct SetMetadata<'a> { | ||
application_id: Id<ApplicationMarker>, | ||
http: &'a Client, | ||
records: &'a [Metadata], | ||
} | ||
|
||
impl<'a> SetMetadata<'a> { | ||
pub(crate) const fn new( | ||
http: &'a Client, | ||
application_id: Id<ApplicationMarker>, | ||
records: &'a [Metadata], | ||
) -> Self { | ||
Self { | ||
application_id, | ||
http, | ||
records, | ||
} | ||
} | ||
|
||
/// Execute the request, returning a future resolving to a [`Response`]. | ||
#[deprecated(since = "0.14.0", note = "use `.await` or `into_future` instead")] | ||
pub fn exec(self) -> ResponseFuture<ListBody<Metadata>> { | ||
self.into_future() | ||
} | ||
} | ||
|
||
impl IntoFuture for SetMetadata<'_> { | ||
type Output = Result<Response<ListBody<Metadata>>, Error>; | ||
|
||
type IntoFuture = ResponseFuture<ListBody<Metadata>>; | ||
|
||
fn into_future(self) -> Self::IntoFuture { | ||
let http = self.http; | ||
|
||
match self.try_into_request() { | ||
Ok(request) => http.request(request), | ||
Err(source) => ResponseFuture::error(source), | ||
} | ||
} | ||
} | ||
|
||
impl TryIntoRequest for SetMetadata<'_> { | ||
fn try_into_request(self) -> Result<Request, Error> { | ||
Request::builder(&Route::SetApplicationRoleConnectionMetadataRecords { | ||
application_id: self.application_id.get(), | ||
}) | ||
.json(&self.records) | ||
.map(RequestBuilder::build) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod command; | ||
pub mod interaction; | ||
pub mod role_connection; | ||
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. I'd rather place this into |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
//! Application role connections models. | ||
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. I'd prefer a more descriptive module description. Something summarizing what and why role connections exists would be ideal. 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. This is largely a wip at the moment, the docs are either placeholders or taken straight out of the discord's docs (the uncapitalized ones). |
||
|
||
use std::collections::HashMap; | ||
|
||
zeylahellyer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
use serde::{Deserialize, Serialize}; | ||
use serde_repr::{Deserialize_repr, Serialize_repr}; | ||
|
||
/// Application Role Connection Metadata Type. | ||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Deserialize_repr, Serialize_repr)] | ||
#[repr(u8)] | ||
pub enum MetadataType { | ||
/// the metadata value (integer) is less than or equal to the guild's | ||
zeylahellyer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// configured value (integer) | ||
IntegerLessThanOrEqual = 1, | ||
/// the metadata value (integer) is greater than or equal to the guild's | ||
/// configured value (integer) | ||
IntegerGreaterThanOrEqual = 2, | ||
/// the metadata value (integer) is equal to the guild's configured value | ||
/// (integer) | ||
IntegerEqual = 3, | ||
/// the metadata value (integer) is not equal to the guild's configured | ||
/// value (integer) | ||
IntegerNotEqual = 4, | ||
/// the metadata value (ISO8601 string) is less than or equal to | ||
/// the guild's configured value (integer; days before current date) | ||
DatetimeLessThanOrEqual = 5, | ||
/// the metadata value (ISO8601 string) is greater than or equal to | ||
/// the guild's configured value (integer; days before current date) | ||
DatetimeGreaterThanOrEqual = 6, | ||
/// the metadata value (integer) is equal to the guild's configured value | ||
/// (integer; 1) | ||
BooleanEqual = 7, | ||
/// the metadata value (integer) is not equal to the guild's configured | ||
/// value (integer; 1) | ||
BooleanNotEqual = 8, | ||
} | ||
|
||
/// Application Role Connection Metadata Structure. | ||
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] | ||
pub struct Metadata { | ||
/// type of metadata value | ||
pub r#type: MetadataType, | ||
zeylahellyer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// dictionary key for the metadata field | ||
/// (must be a-z, 0-9, or _ characters; max 50 characters) | ||
pub key: String, | ||
/// name of the metadata field (max 100 characters) | ||
pub name: String, | ||
/// translations of the name | ||
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. Could you update the localization items' documentation to follow the same style as |
||
pub name_localizations: HashMap<String, String>, | ||
/// description of the metadata field (max 200 characters) | ||
pub description: String, | ||
/// translations of the description | ||
zeylahellyer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
pub description_localizations: HashMap<String, String>, | ||
} |
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.
This is unacceptable (not your fault), it's way to contrived. We need a RFC for how to handle routes requiring an
application_id
.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.
That's fine! I'll use this for now in my code as I need something that works immediately. I'll be looking forward to the RFC and the proper implementation of this feature but it is unlikely I'll be taking part in the RFC process itself in the near future.