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

add support for edit_current_application endpoint #3035

Open
wants to merge 3 commits into
base: next
Choose a base branch
from

Conversation

ivinjabraham
Copy link
Contributor

@ivinjabraham ivinjabraham commented Nov 13, 2024

Fixes #2977

@github-actions github-actions bot added the http Related to the `http` module. label Nov 13, 2024
Copy link
Member

@jamesbt365 jamesbt365 left a comment

Choose a reason for hiding this comment

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

Use the provided to_vec function instead of importing it from serde_json.

@jamesbt365
Copy link
Member

Also you haven't added anything but the low level http interface? Http usually shouldn't be directly used and you should probably add a builder like how our other stuff interacts with http.

@ivinjabraham
Copy link
Contributor Author

Use the provided to_vec function instead of importing it from serde_json.

Pesky auto-import. Should be fixed now.

Also you haven't added anything but the low level http interface? Http usually shouldn't be directly used and you should probably add a builder like how our other stuff interacts with http.

Right, so I'll make a edit_current_application_info.rs and impl Builder along with the required structs and methods?

@ivinjabraham
Copy link
Contributor Author

ivinjabraham commented Nov 15, 2024

It seems the CurrentApplicationInfo struct is out of date. There are few fields such as event_webhook_url and event_webhook_status that are missing. I'll send in a PR for that first.

Doc for reference

@ivinjabraham ivinjabraham changed the base branch from current to next November 15, 2024 15:09
@ivinjabraham ivinjabraham force-pushed the current branch 2 times, most recently from 5ba44d9 to 24ffd92 Compare November 15, 2024 15:45
@github-actions github-actions bot added the model Related to the `model` module. label Nov 17, 2024
@github-actions github-actions bot added the builder Related to the `builder` module. label Nov 17, 2024
@ivinjabraham ivinjabraham force-pushed the current branch 3 times, most recently from 20d45ab to 8fd6b7e Compare November 17, 2024 16:41
Copy link
Member

@jamesbt365 jamesbt365 left a comment

Choose a reason for hiding this comment

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

edit_current_appllication_info.rs -> edit_current_application_info.rs

@ivinjabraham ivinjabraham force-pushed the current branch 2 times, most recently from 8c6dd76 to 6a5d2a5 Compare November 17, 2024 18:04
@ivinjabraham ivinjabraham marked this pull request as ready for review November 18, 2024 03:43
Comment on lines 50 to 54
/// Interactions endpoint URL for the app.
///
/// To update an Interactions endpoint URL via the API, the URL must be valid according
/// to the [Receiving an Interaction]
/// (https://discord.com/developers/docs/interactions/receiving-and-responding#receiving-an-interaction) documentation.
Copy link
Collaborator

Choose a reason for hiding this comment

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

These docs are private and therefore unnecessary. I'd recommend instead incorporating them into the docs for the methods themselves.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, of course. Fixed it now.

Comment on lines 52 to 97
pub terms_of_service_url: Option<FixedString>,
pub bot: User,
#[serde(default)]
pub privacy_policy_url: Option<FixedString>,
pub owner: Option<User>,
// omitted `summary` because it deprecated
pub verify_key: FixedString,
pub terms_of_service_url: Option<String>,
#[serde(default)]
pub privacy_policy_url: Option<String>,
#[serde(default)]
pub owner: User,
pub verify_key: String,
pub team: Option<Team>,
#[serde(default)]
pub guild_id: Option<GuildId>,
#[serde(default)]
pub guild: Option<PartialGuild>,
#[serde(default)]
pub primary_sku_id: Option<SkuId>,
#[serde(default)]
pub slug: Option<FixedString>,
pub slug: String,
#[serde(default)]
pub cover_image: Option<FixedString>,
pub cover_image: String,
#[serde(default)]
pub flags: Option<ApplicationFlags>,
#[serde(default)]
pub tags: Option<Vec<String>>,
pub approximate_guild_count: Option<u32>,
#[serde(default)]
pub install_params: Option<InstallParams>,
pub approximate_user_install_count: Option<u32>,
#[serde(default)]
pub redirect_uris: Vec<String>,
#[serde(default)]
pub custom_install_url: Option<FixedString>,
pub interactions_endpoint_url: Option<String>,
/// The application's role connection verification entry point, which when configured will
/// render the app as a verification method in the guild role verification configuration.
pub role_connections_verification_url: Option<FixedString>,
#[serde(default)]
pub role_connections_verification_url: Option<String>,
#[serde(default)]
pub event_webhooks_url: Option<String>,
pub event_webhook_status: EventWebhookStatus,
#[serde(default)]
pub event_webhook_type: Vec<EventWebhookType>,
#[serde(default)]
pub tags: Option<Vec<String>>,
#[serde(default)]
pub install_params: Option<InstallParams>,
#[serde(default)]
pub integration_types_config: HashMap<InstallationContext, InstallationContextConfig>,
pub approximate_guild_count: Option<u32>,
pub approximate_user_install_count: Option<u32>,
pub guild: Option<PartialGuild>,
pub redirect_uris: Option<Vec<String>>,
pub interactions_endpoint_url: Option<String>,
#[serde(default)]
pub custom_install_url: String,
Copy link
Member

Choose a reason for hiding this comment

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

You have replaced a bunch of FixedString here with String, I'm assuming it's just a leftover from when this PR targeted current, can you change it back to use FixedString (for performance reasons).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, they were leftovers. I've changed them back to FixedString now.

Comment on lines 306 to 323
impl InstallParams {
#[must_use]
pub fn new() -> Self {
Self::default()
}

#[must_use]
pub fn scopes(mut self, scopes: Vec<Scope>) -> Self {
self.scopes = FixedArray::from_vec_trunc(scopes);
self
}

#[must_use]
pub fn permissions(mut self, permissions: Permissions) -> Self {
self.permissions = permissions;
self
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Please make this an CreateInstallParams in the new module to avoid mixing memory-optimised (FixedArray) and compute-optimised (Vec) types. This would also allow for new to take both the required fields, scopes and permissions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made the requested changes, I've also squashed the two commits since they're intertwined now.

Comment on lines 92 to 101
pub fn icon(mut self, hash: &str) -> Self {
if let Ok(image_hash) = hash.parse() {
self.icon = Some(image_hash);
} else {
println!("Error parsing image hash while constructing EditCurrentApplicationInfo");
}
self
}

/// Default rich presence invite cover image for the app.
pub fn cover_image(mut self, hash: &str) -> Self {
if let Ok(image_hash) = hash.parse() {
self.cover_image = Some(image_hash);
} else {
println!("Error parsing image hash while constructing EditCurrentApplicationInfo");
}
self
}
Copy link
Member

Choose a reason for hiding this comment

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

  1. Please don't take types just to parse them into different types.
  2. Please don't print on the user's behalf.
  3. This is meant to be base64 image data, not an image hash, as the docs say.

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've removed the unnecessary code and changed it to accept base64 data instead.

@jamesbt365
Copy link
Member

I think everything in CurrentApplicationInfo can use FixedString (String replacment) and FixedArray (Vec replacement)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
builder Related to the `builder` module. http Related to the `http` module. model Related to the `model` module.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing endpoint: Edit Current Application
4 participants