diff --git a/examples/e05_command_framework/src/main.rs b/examples/e05_command_framework/src/main.rs index aa754deff6b..b5bb9d02891 100644 --- a/examples/e05_command_framework/src/main.rs +++ b/examples/e05_command_framework/src/main.rs @@ -351,7 +351,7 @@ async fn say(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult { // We do not want to clean channel mentions as they do not ping users. .clean_channel(false); - x = content_safe(&guild, x, settings, &msg.mentions); + x = content_safe(&guild, &x, settings, &msg.mentions); } msg.channel_id.say(&ctx.http, x).await?; diff --git a/examples/e11_gateway_intents/src/main.rs b/examples/e11_gateway_intents/src/main.rs index 6c43f3bdca1..c377a154d2f 100644 --- a/examples/e11_gateway_intents/src/main.rs +++ b/examples/e11_gateway_intents/src/main.rs @@ -34,7 +34,7 @@ async fn main() { let intents = GatewayIntents::GUILDS | GatewayIntents::GUILD_MESSAGES | GatewayIntents::MESSAGE_CONTENT; // Build our client. - let mut client = Client::builder(token, intents) + let mut client = Client::builder(&token, intents) .event_handler(Handler) .await .expect("Error creating client"); diff --git a/examples/e14_slash_commands/src/main.rs b/examples/e14_slash_commands/src/main.rs index ac2ab28f6e3..76026564090 100644 --- a/examples/e14_slash_commands/src/main.rs +++ b/examples/e14_slash_commands/src/main.rs @@ -75,7 +75,7 @@ async fn main() { let token = env::var("DISCORD_TOKEN").expect("Expected a token in the environment"); // Build our client. - let mut client = Client::builder(token, GatewayIntents::empty()) + let mut client = Client::builder(&token, GatewayIntents::empty()) .event_handler(Handler) .await .expect("Error creating client"); diff --git a/examples/e15_simple_dashboard/src/main.rs b/examples/e15_simple_dashboard/src/main.rs index 54c676b7d4f..95b87fe6e00 100644 --- a/examples/e15_simple_dashboard/src/main.rs +++ b/examples/e15_simple_dashboard/src/main.rs @@ -414,7 +414,7 @@ async fn main() -> Result<(), Box> { let intents = GatewayIntents::GUILD_MESSAGES | GatewayIntents::DIRECT_MESSAGES | GatewayIntents::MESSAGE_CONTENT; - let mut client = Client::builder(token, intents) + let mut client = Client::builder(&token, intents) .event_handler(Handler) .framework(framework) .type_map_insert::(components) diff --git a/examples/e17_message_components/src/main.rs b/examples/e17_message_components/src/main.rs index 2bfc60376e3..2bbd8b489a9 100644 --- a/examples/e17_message_components/src/main.rs +++ b/examples/e17_message_components/src/main.rs @@ -144,7 +144,7 @@ async fn main() { let intents = GatewayIntents::GUILD_MESSAGES | GatewayIntents::DIRECT_MESSAGES | GatewayIntents::MESSAGE_CONTENT; - let mut client = Client::builder(token, intents) + let mut client = Client::builder(&token, intents) .event_handler(Handler) .await .expect("Error creating client"); diff --git a/examples/testing/src/main.rs b/examples/testing/src/main.rs index d6c79dc5eed..2b5162905a9 100644 --- a/examples/testing/src/main.rs +++ b/examples/testing/src/main.rs @@ -400,5 +400,5 @@ async fn main() -> Result<(), serenity::Error> { env_logger::init(); let token = std::env::var("DISCORD_TOKEN").expect("Expected a token in the environment"); let intents = GatewayIntents::non_privileged() | GatewayIntents::MESSAGE_CONTENT; - Client::builder(token, intents).event_handler(Handler).await?.start().await + Client::builder(&token, intents).event_handler(Handler).await?.start().await } diff --git a/src/builder/bot_auth_parameters.rs b/src/builder/bot_auth_parameters.rs index bb72f485dec..f6b36dc653d 100644 --- a/src/builder/bot_auth_parameters.rs +++ b/src/builder/bot_auth_parameters.rs @@ -71,8 +71,8 @@ impl<'a> CreateBotAuthParameters<'a> { } /// Specify the client Id of your application. - pub fn client_id(mut self, client_id: impl Into) -> Self { - self.client_id = Some(client_id.into()); + pub fn client_id(mut self, client_id: ApplicationId) -> Self { + self.client_id = Some(client_id); self } @@ -107,8 +107,8 @@ impl<'a> CreateBotAuthParameters<'a> { } /// Specify the Id of the guild to prefill the dropdown picker for the user. - pub fn guild_id(mut self, guild_id: impl Into) -> Self { - self.guild_id = Some(guild_id.into()); + pub fn guild_id(mut self, guild_id: GuildId) -> Self { + self.guild_id = Some(guild_id); self } diff --git a/src/builder/create_channel.rs b/src/builder/create_channel.rs index 34cc6424fd5..1b85ec623fa 100644 --- a/src/builder/create_channel.rs +++ b/src/builder/create_channel.rs @@ -97,8 +97,8 @@ impl<'a> CreateChannel<'a> { /// Only for [`ChannelType::Text`], [`ChannelType::Voice`], [`ChannelType::News`], /// [`ChannelType::Stage`], [`ChannelType::Forum`] #[doc(alias = "parent_id")] - pub fn category(mut self, id: impl Into) -> Self { - self.parent_id = Some(id.into()); + pub fn category(mut self, id: ChannelId) -> Self { + self.parent_id = Some(id); self } diff --git a/src/builder/create_message.rs b/src/builder/create_message.rs index dc946556428..12d13db8105 100644 --- a/src/builder/create_message.rs +++ b/src/builder/create_message.rs @@ -225,8 +225,8 @@ impl<'a> CreateMessage<'a> { /// /// **Note**: This will replace all existing stickers. Use [`Self::add_sticker_id()`] to keep /// existing stickers. - pub fn sticker_id(self, sticker_id: impl Into) -> Self { - self.sticker_ids(vec![sticker_id.into()]) + pub fn sticker_id(self, sticker_id: StickerId) -> Self { + self.sticker_ids(vec![sticker_id]) } /// Sets a list of sticker IDs to include in the message. @@ -246,8 +246,8 @@ impl<'a> CreateMessage<'a> { /// /// **Note**: This will keep all existing stickers. Use [`Self::sticker_id()`] to replace /// existing sticker. - pub fn add_sticker_id(mut self, sticker_id: impl Into) -> Self { - self.sticker_ids.to_mut().push(sticker_id.into()); + pub fn add_sticker_id(mut self, sticker_id: StickerId) -> Self { + self.sticker_ids.to_mut().push(sticker_id); self } diff --git a/src/builder/create_scheduled_event.rs b/src/builder/create_scheduled_event.rs index 6a95910585a..603299b415a 100644 --- a/src/builder/create_scheduled_event.rs +++ b/src/builder/create_scheduled_event.rs @@ -62,8 +62,8 @@ impl<'a> CreateScheduledEvent<'a> { /// Sets the channel id of the scheduled event. Required if [`Self::kind`] is /// [`ScheduledEventType::StageInstance`] or [`ScheduledEventType::Voice`]. - pub fn channel_id>(mut self, channel_id: C) -> Self { - self.channel_id = Some(channel_id.into()); + pub fn channel_id(mut self, channel_id: ChannelId) -> Self { + self.channel_id = Some(channel_id); self } diff --git a/src/builder/edit_guild.rs b/src/builder/edit_guild.rs index 1de086e752d..c681631df01 100644 --- a/src/builder/edit_guild.rs +++ b/src/builder/edit_guild.rs @@ -147,8 +147,8 @@ impl<'a> EditGuild<'a> { /// /// **Note**: The current user must be the owner of the guild. #[inline] - pub fn owner(mut self, user_id: impl Into) -> Self { - self.owner_id = Some(user_id.into()); + pub fn owner(mut self, user_id: UserId) -> Self { + self.owner_id = Some(user_id); self } diff --git a/src/builder/edit_guild_welcome_screen.rs b/src/builder/edit_guild_welcome_screen.rs index 971956c4119..4972c08675e 100644 --- a/src/builder/edit_guild_welcome_screen.rs +++ b/src/builder/edit_guild_welcome_screen.rs @@ -111,8 +111,8 @@ impl<'a> CreateGuildWelcomeChannel<'a> { } /// The Id of the channel to show. - pub fn id(mut self, id: impl Into) -> Self { - self.channel_id = id.into(); + pub fn id(mut self, id: ChannelId) -> Self { + self.channel_id = id; self } diff --git a/src/builder/edit_guild_widget.rs b/src/builder/edit_guild_widget.rs index 5bd23f9ab98..3b8e64834f8 100644 --- a/src/builder/edit_guild_widget.rs +++ b/src/builder/edit_guild_widget.rs @@ -34,8 +34,8 @@ impl<'a> EditGuildWidget<'a> { } /// The server description shown in the welcome screen. - pub fn channel_id(mut self, id: impl Into) -> Self { - self.channel_id = Some(id.into()); + pub fn channel_id(mut self, id: ChannelId) -> Self { + self.channel_id = Some(id); self } diff --git a/src/builder/edit_member.rs b/src/builder/edit_member.rs index ca24608b268..5a062ecbad6 100644 --- a/src/builder/edit_member.rs +++ b/src/builder/edit_member.rs @@ -86,8 +86,8 @@ impl<'a> EditMember<'a> { /// /// [Move Members]: Permissions::MOVE_MEMBERS #[inline] - pub fn voice_channel(mut self, channel_id: impl Into) -> Self { - self.channel_id = Some(Some(channel_id.into())); + pub fn voice_channel(mut self, channel_id: ChannelId) -> Self { + self.channel_id = Some(Some(channel_id)); self } diff --git a/src/builder/edit_scheduled_event.rs b/src/builder/edit_scheduled_event.rs index 44afc3bf115..d0ecddf661d 100644 --- a/src/builder/edit_scheduled_event.rs +++ b/src/builder/edit_scheduled_event.rs @@ -50,8 +50,8 @@ impl<'a> EditScheduledEvent<'a> { /// [`kind`]: EditScheduledEvent::kind /// [`Voice`]: ScheduledEventType::Voice /// [`External`]: ScheduledEventType::External - pub fn channel_id(mut self, channel_id: impl Into) -> Self { - self.channel_id = Some(Some(channel_id.into())); + pub fn channel_id(mut self, channel_id: ChannelId) -> Self { + self.channel_id = Some(Some(channel_id)); self } diff --git a/src/builder/edit_webhook.rs b/src/builder/edit_webhook.rs index 2d3825ba183..4b5f5e892b1 100644 --- a/src/builder/edit_webhook.rs +++ b/src/builder/edit_webhook.rs @@ -37,8 +37,8 @@ impl<'a> EditWebhook<'a> { } /// Set the channel to move the webhook to. - pub fn channel_id(mut self, channel_id: impl Into) -> Self { - self.channel_id = Some(channel_id.into()); + pub fn channel_id(mut self, channel_id: ChannelId) -> Self { + self.channel_id = Some(channel_id); self } diff --git a/src/builder/edit_webhook_message.rs b/src/builder/edit_webhook_message.rs index 8b6f542c74c..fecfb2280e5 100644 --- a/src/builder/edit_webhook_message.rs +++ b/src/builder/edit_webhook_message.rs @@ -74,8 +74,8 @@ impl<'a> EditWebhookMessage<'a> { /// Edits a message within a given thread. If the provided thread Id doesn't belong to the /// current webhook, the API will return an error. #[inline] - pub fn in_thread(mut self, thread_id: impl Into) -> Self { - self.thread_id = Some(thread_id.into()); + pub fn in_thread(mut self, thread_id: ChannelId) -> Self { + self.thread_id = Some(thread_id); self } diff --git a/src/builder/execute_webhook.rs b/src/builder/execute_webhook.rs index 5ca549fa1c8..e4c57df9ff5 100644 --- a/src/builder/execute_webhook.rs +++ b/src/builder/execute_webhook.rs @@ -174,20 +174,20 @@ impl<'a> ExecuteWebhook<'a> { /// ```rust,no_run /// # use serenity::builder::ExecuteWebhook; /// # use serenity::http::Http; - /// # use serenity::model::webhook::Webhook; + /// # use serenity::model::{id::ChannelId, webhook::Webhook}; /// # /// # async fn run() -> Result<(), Box> { /// # let http: Http = unimplemented!(); /// let url = "https://discord.com/api/webhooks/245037420704169985/ig5AO-wdVWpCBtUUMxmgsWryqgsW3DChbKYOINftJ4DCrUbnkedoYZD0VOH1QLr-S3sV"; /// let mut webhook = Webhook::from_url(&http, url).await?; /// - /// let builder = ExecuteWebhook::new().in_thread(12345678).content("test"); + /// let builder = ExecuteWebhook::new().in_thread(ChannelId::new(12345678)).content("test"); /// webhook.execute(&http, false, builder).await?; /// # Ok(()) /// # } /// ``` - pub fn in_thread(mut self, thread_id: impl Into) -> Self { - self.thread_id = Some(thread_id.into()); + pub fn in_thread(mut self, thread_id: ChannelId) -> Self { + self.thread_id = Some(thread_id); self } diff --git a/src/builder/get_messages.rs b/src/builder/get_messages.rs index 1eff62aef89..dbd0187e9f6 100644 --- a/src/builder/get_messages.rs +++ b/src/builder/get_messages.rs @@ -60,21 +60,21 @@ impl GetMessages { } /// Indicates to retrieve the messages after a specific message, given its Id. - pub fn after(mut self, message_id: impl Into) -> Self { - self.search_filter = Some(SearchFilter::After(message_id.into())); + pub fn after(mut self, message_id: MessageId) -> Self { + self.search_filter = Some(SearchFilter::After(message_id)); self } /// Indicates to retrieve the messages _around_ a specific message, in other words in either /// direction from the message in time. - pub fn around(mut self, message_id: impl Into) -> Self { - self.search_filter = Some(SearchFilter::Around(message_id.into())); + pub fn around(mut self, message_id: MessageId) -> Self { + self.search_filter = Some(SearchFilter::Around(message_id)); self } /// Indicates to retrieve the messages before a specific message, given its Id. - pub fn before(mut self, message_id: impl Into) -> Self { - self.search_filter = Some(SearchFilter::Before(message_id.into())); + pub fn before(mut self, message_id: MessageId) -> Self { + self.search_filter = Some(SearchFilter::Before(message_id)); self } diff --git a/src/cache/mod.rs b/src/cache/mod.rs index 36ca9ec3ebe..63d9b963119 100644 --- a/src/cache/mod.rs +++ b/src/cache/mod.rs @@ -351,11 +351,7 @@ impl Cache { /// Retrieves a [`GuildChannel`] from the cache based on the given Id. #[inline] - pub fn channel>(&self, id: C) -> Option> { - self._channel(id.into()) - } - - fn _channel(&self, id: ChannelId) -> Option> { + pub fn channel(&self, id: ChannelId) -> Option> { let guild_id = *self.channels.get(&id)?; let guild_ref = self.guilds.get(&guild_id)?; let channel = guild_ref.try_map(|g| g.channels.get(&id)).ok(); @@ -389,17 +385,16 @@ impl Cache { /// Find all messages by user ID 8 in channel ID 7: /// /// ```rust,no_run + /// # use serenity::model::id::ChannelId; + /// # /// # let cache: serenity::cache::Cache = todo!(); - /// let messages_in_channel = cache.channel_messages(7); + /// let messages_in_channel = cache.channel_messages(ChannelId::new(7)); /// let messages_by_user = messages_in_channel /// .as_ref() /// .map(|msgs| msgs.values().filter(|m| m.author.id == 8).collect::>()); /// ``` - pub fn channel_messages( - &self, - channel_id: impl Into, - ) -> Option> { - self.messages.get(&channel_id.into()).map(CacheRef::from_ref) + pub fn channel_messages(&self, channel_id: ChannelId) -> Option> { + self.messages.get(&channel_id).map(CacheRef::from_ref) } /// Gets a reference to a guild from the cache based on the given `id`. @@ -410,19 +405,16 @@ impl Cache { /// /// ```rust,no_run /// # use serenity::cache::Cache; + /// # use serenity::model::id::GuildId; /// # /// # let cache = Cache::default(); /// // assuming the cache is in scope, e.g. via `Context` - /// if let Some(guild) = cache.guild(7) { + /// if let Some(guild) = cache.guild(GuildId::new(7)) { /// println!("Guild name: {}", guild.name); /// }; /// ``` #[inline] - pub fn guild>(&self, id: G) -> Option> { - self._guild(id.into()) - } - - fn _guild(&self, id: GuildId) -> Option> { + pub fn guild(&self, id: GuildId) -> Option> { self.guilds.get(&id).map(CacheRef::from_ref) } @@ -475,12 +467,8 @@ impl Cache { /// [`EventHandler::message`]: crate::client::EventHandler::message /// [`members`]: crate::model::guild::Guild::members #[inline] - pub fn member( - &self, - guild_id: impl Into, - user_id: impl Into, - ) -> Option> { - self._member(guild_id.into(), user_id.into()) + pub fn member(&self, guild_id: GuildId, user_id: UserId) -> Option> { + self._member(guild_id, user_id) } fn _member(&self, guild_id: GuildId, user_id: UserId) -> Option> { @@ -489,8 +477,8 @@ impl Cache { } #[inline] - pub fn guild_roles(&self, guild_id: impl Into) -> Option> { - self._guild_roles(guild_id.into()) + pub fn guild_roles(&self, guild_id: GuildId) -> Option> { + self._guild_roles(guild_id) } fn _guild_roles(&self, guild_id: GuildId) -> Option> { @@ -506,8 +494,8 @@ impl Cache { /// This method returns all channels from a guild of with the given `guild_id`. #[inline] - pub fn guild_channels(&self, guild_id: impl Into) -> Option> { - self._guild_channels(guild_id.into()) + pub fn guild_channels(&self, guild_id: GuildId) -> Option> { + self._guild_channels(guild_id) } fn _guild_channels(&self, guild_id: GuildId) -> Option> { @@ -550,15 +538,7 @@ impl Cache { /// /// [`EventHandler::message`]: crate::client::EventHandler::message #[inline] - pub fn message(&self, channel_id: C, message_id: M) -> Option> - where - C: Into, - M: Into, - { - self._message(channel_id.into(), message_id.into()) - } - - fn _message(&self, channel_id: ChannelId, message_id: MessageId) -> Option> { + pub fn message(&self, channel_id: ChannelId, message_id: MessageId) -> Option> { #[cfg(feature = "temp_cache")] if let Some(message) = self.temp_messages.get(&message_id) { return Some(CacheRef::from_arc(message)); @@ -579,11 +559,12 @@ impl Cache { /// Retrieve a role from the cache and print its name: /// /// ```rust,no_run + /// # use serenity::model::id::{GuildId, RoleId}; /// # use serenity::cache::Cache; /// # /// # let cache = Cache::default(); /// // assuming the cache is in scope, e.g. via `Context` - /// if let Some(role) = cache.role(7, 77) { + /// if let Some(role) = cache.role(GuildId::new(7), RoleId::new(77)) { /// println!("Role with Id 77 is called {}", role.name); /// }; /// ``` @@ -591,15 +572,7 @@ impl Cache { /// [`Guild`]: crate::model::guild::Guild /// [`roles`]: crate::model::guild::Guild::roles #[inline] - pub fn role(&self, guild_id: G, role_id: R) -> Option> - where - G: Into, - R: Into, - { - self._role(guild_id.into(), role_id.into()) - } - - fn _role(&self, guild_id: GuildId, role_id: RoleId) -> Option> { + pub fn role(&self, guild_id: GuildId, role_id: RoleId) -> Option> { let role = self.guilds.get(&guild_id)?.try_map(|g| g.roles.get(&role_id)).ok()?; Some(CacheRef::from_mapped_ref(role)) } diff --git a/src/client/mod.rs b/src/client/mod.rs index 0850cb57060..af15d3450d6 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -80,31 +80,14 @@ pub struct ClientBuilder { #[cfg(feature = "gateway")] impl ClientBuilder { - fn _new(http: Http, intents: GatewayIntents) -> Self { - Self { - data: TypeMap::new(), - http, - intents, - #[cfg(feature = "cache")] - cache_settings: CacheSettings::default(), - #[cfg(feature = "framework")] - framework: None, - #[cfg(feature = "voice")] - voice_manager: None, - event_handlers: vec![], - raw_event_handlers: vec![], - presence: PresenceData::default(), - } - } - /// Construct a new builder to call methods on for the client construction. The `token` will /// automatically be prefixed "Bot " if not already. /// /// **Panic**: If you have enabled the `framework`-feature (on by default), you must specify a /// framework via the [`Self::framework`] method, otherwise awaiting the builder will cause a /// panic. - pub fn new(token: impl AsRef, intents: GatewayIntents) -> Self { - Self::_new(Http::new(token.as_ref()), intents) + pub fn new(token: &str, intents: GatewayIntents) -> Self { + Self::new_with_http(Http::new(token), intents) } /// Construct a new builder with a [`Http`] instance to calls methods on for the client @@ -114,14 +97,26 @@ impl ClientBuilder { /// framework via the [`Self::framework`] method, otherwise awaiting the builder will cause a /// panic. pub fn new_with_http(http: Http, intents: GatewayIntents) -> Self { - Self::_new(http, intents) + Self { + data: TypeMap::new(), + http, + intents, + #[cfg(feature = "cache")] + cache_settings: CacheSettings::default(), + #[cfg(feature = "framework")] + framework: None, + #[cfg(feature = "voice")] + voice_manager: None, + event_handlers: vec![], + raw_event_handlers: vec![], + presence: PresenceData::default(), + } } /// Sets a token for the bot. If the token is not prefixed "Bot ", this method will /// automatically do so. - pub fn token(mut self, token: impl AsRef) -> Self { - self.http = Http::new(token.as_ref()); - + pub fn token(mut self, token: &str) -> Self { + self.http = Http::new(token); self } @@ -595,7 +590,7 @@ pub struct Client { } impl Client { - pub fn builder(token: impl AsRef, intents: GatewayIntents) -> ClientBuilder { + pub fn builder(token: &str, intents: GatewayIntents) -> ClientBuilder { ClientBuilder::new(token, intents) } diff --git a/src/http/client.rs b/src/http/client.rs index 797082e014a..25f227886df 100644 --- a/src/http/client.rs +++ b/src/http/client.rs @@ -64,7 +64,7 @@ pub struct HttpBuilder { impl HttpBuilder { /// Construct a new builder to call methods on for the HTTP construction. The `token` will /// automatically be prefixed "Bot " if not already. - pub fn new(token: impl AsRef) -> Self { + pub fn new(token: &str) -> Self { Self { client: None, ratelimiter: None, @@ -83,7 +83,7 @@ impl HttpBuilder { /// Sets a token for the bot. If the token is not prefixed "Bot ", this method will /// automatically do so. - pub fn token(mut self, token: impl AsRef) -> Self { + pub fn token(mut self, token: &str) -> Self { self.token = SecretString::new(parse_token(token)); self } @@ -156,8 +156,8 @@ impl HttpBuilder { } } -fn parse_token(token: impl AsRef) -> String { - let token = token.as_ref().trim(); +fn parse_token(token: &str) -> String { + let token = token.trim(); if token.starts_with("Bot ") || token.starts_with("Bearer ") { token.to_string() diff --git a/src/model/application/command_interaction.rs b/src/model/application/command_interaction.rs index 57a7b137c2e..dc97c61ce49 100644 --- a/src/model/application/command_interaction.rs +++ b/src/model/application/command_interaction.rs @@ -169,10 +169,10 @@ impl CommandInteraction { pub async fn edit_followup( &self, cache_http: impl CacheHttp, - message_id: impl Into, + message_id: MessageId, builder: CreateInteractionResponseFollowup<'_>, ) -> Result { - builder.execute(cache_http, (Some(message_id.into()), &self.token)).await + builder.execute(cache_http, (Some(message_id), &self.token)).await } /// Deletes a followup message. @@ -181,12 +181,12 @@ impl CommandInteraction { /// /// May return [`Error::Http`] if the API returns an error. Such as if the response was already /// deleted. - pub async fn delete_followup>( + pub async fn delete_followup( &self, http: impl AsRef, - message_id: M, + message_id: MessageId, ) -> Result<()> { - http.as_ref().delete_followup_message(&self.token, message_id.into()).await + http.as_ref().delete_followup_message(&self.token, message_id).await } /// Gets a followup message. @@ -195,12 +195,12 @@ impl CommandInteraction { /// /// May return [`Error::Http`] if the API returns an error. Such as if the response was /// deleted. - pub async fn get_followup>( + pub async fn get_followup( &self, http: impl AsRef, - message_id: M, + message_id: MessageId, ) -> Result { - http.as_ref().get_followup_message(&self.token, message_id.into()).await + http.as_ref().get_followup_message(&self.token, message_id).await } /// Helper function to defer an interaction. diff --git a/src/model/application/component_interaction.rs b/src/model/application/component_interaction.rs index c6ae4489ca1..6fb20c98643 100644 --- a/src/model/application/component_interaction.rs +++ b/src/model/application/component_interaction.rs @@ -150,10 +150,10 @@ impl ComponentInteraction { pub async fn edit_followup( &self, cache_http: impl CacheHttp, - message_id: impl Into, + message_id: MessageId, builder: CreateInteractionResponseFollowup<'_>, ) -> Result { - builder.execute(cache_http, (Some(message_id.into()), &self.token)).await + builder.execute(cache_http, (Some(message_id), &self.token)).await } /// Deletes a followup message. @@ -162,12 +162,12 @@ impl ComponentInteraction { /// /// May return [`Error::Http`] if the API returns an error. Such as if the response was already /// deleted. - pub async fn delete_followup>( + pub async fn delete_followup( &self, http: impl AsRef, - message_id: M, + message_id: MessageId, ) -> Result<()> { - http.as_ref().delete_followup_message(&self.token, message_id.into()).await + http.as_ref().delete_followup_message(&self.token, message_id).await } /// Gets a followup message. @@ -176,12 +176,12 @@ impl ComponentInteraction { /// /// May return [`Error::Http`] if the API returns an error. Such as if the response was /// deleted. - pub async fn get_followup>( + pub async fn get_followup( &self, http: impl AsRef, - message_id: M, + message_id: MessageId, ) -> Result { - http.as_ref().get_followup_message(&self.token, message_id.into()).await + http.as_ref().get_followup_message(&self.token, message_id).await } /// Helper function to defer an interaction. diff --git a/src/model/application/modal_interaction.rs b/src/model/application/modal_interaction.rs index 777138e6f34..1ae3faff940 100644 --- a/src/model/application/modal_interaction.rs +++ b/src/model/application/modal_interaction.rs @@ -149,10 +149,10 @@ impl ModalInteraction { pub async fn edit_followup( &self, cache_http: impl CacheHttp, - message_id: impl Into, + message_id: MessageId, builder: CreateInteractionResponseFollowup<'_>, ) -> Result { - builder.execute(cache_http, (Some(message_id.into()), &self.token)).await + builder.execute(cache_http, (Some(message_id), &self.token)).await } /// Deletes a followup message. @@ -161,12 +161,12 @@ impl ModalInteraction { /// /// May return [`Error::Http`] if the API returns an error. Such as if the response was already /// deleted. - pub async fn delete_followup>( + pub async fn delete_followup( &self, http: impl AsRef, - message_id: M, + message_id: MessageId, ) -> Result<()> { - http.as_ref().delete_followup_message(&self.token, message_id.into()).await + http.as_ref().delete_followup_message(&self.token, message_id).await } /// Helper function to defer an interaction. diff --git a/src/model/channel/channel_id.rs b/src/model/channel/channel_id.rs index a221dda6d39..d9747b962b7 100644 --- a/src/model/channel/channel_id.rs +++ b/src/model/channel/channel_id.rs @@ -124,10 +124,10 @@ impl ChannelId { pub async fn create_reaction( self, http: impl AsRef, - message_id: impl Into, + message_id: MessageId, reaction_type: impl Into, ) -> Result<()> { - http.as_ref().create_reaction(self, message_id.into(), &reaction_type.into()).await + http.as_ref().create_reaction(self, message_id, &reaction_type.into()).await } /// Deletes this channel, returning the channel on a successful deletion. @@ -157,12 +157,8 @@ impl ChannelId { /// /// [Manage Messages]: Permissions::MANAGE_MESSAGES #[inline] - pub async fn delete_message( - self, - http: impl AsRef, - message_id: impl Into, - ) -> Result<()> { - http.as_ref().delete_message(self, message_id.into(), None).await + pub async fn delete_message(self, http: impl AsRef, message_id: MessageId) -> Result<()> { + http.as_ref().delete_message(self, message_id, None).await } /// Deletes all messages by Ids from the given vector in the given channel. @@ -240,12 +236,11 @@ impl ChannelId { pub async fn delete_reaction( self, http: impl AsRef, - message_id: impl Into, + message_id: MessageId, user_id: Option, reaction_type: impl Into, ) -> Result<()> { let http = http.as_ref(); - let message_id = message_id.into(); let reaction_type = reaction_type.into(); match user_id { Some(user_id) => http.delete_reaction(self, message_id, user_id, &reaction_type).await, @@ -267,9 +262,9 @@ impl ChannelId { pub async fn delete_reactions( self, http: impl AsRef, - message_id: impl Into, + message_id: MessageId, ) -> Result<()> { - http.as_ref().delete_message_reactions(self, message_id.into()).await + http.as_ref().delete_message_reactions(self, message_id).await } /// Deletes all [`Reaction`]s of the given emoji to a message within the channel. @@ -285,12 +280,10 @@ impl ChannelId { pub async fn delete_reaction_emoji( self, http: impl AsRef, - message_id: impl Into, + message_id: MessageId, reaction_type: impl Into, ) -> Result<()> { - http.as_ref() - .delete_message_reaction_emoji(self, message_id.into(), &reaction_type.into()) - .await + http.as_ref().delete_message_reaction_emoji(self, message_id, &reaction_type.into()).await } /// Edits a channel's settings. @@ -350,10 +343,10 @@ impl ChannelId { pub async fn edit_message( self, cache_http: impl CacheHttp, - message_id: impl Into, + message_id: MessageId, builder: EditMessage<'_>, ) -> Result { - builder.execute(cache_http, (self, message_id.into())).await + builder.execute(cache_http, (self, message_id)).await } /// Follows the News Channel @@ -369,9 +362,9 @@ impl ChannelId { pub async fn follow( self, http: impl AsRef, - target_channel_id: impl Into, + target_channel_id: ChannelId, ) -> Result { - http.as_ref().follow_news_channel(self, target_channel_id.into()).await + http.as_ref().follow_news_channel(self, target_channel_id).await } /// Attempts to find a [`GuildChannel`] by its Id in the cache. @@ -450,10 +443,8 @@ impl ChannelId { pub async fn message( self, cache_http: impl CacheHttp, - message_id: impl Into, + message_id: MessageId, ) -> Result { - let message_id = message_id.into(); - #[cfg(feature = "cache")] if let Some(cache) = cache_http.cache() { if let Some(message) = cache.message(self, message_id) { @@ -552,8 +543,8 @@ impl ChannelId { /// /// [Manage Messages]: Permissions::MANAGE_MESSAGES #[inline] - pub async fn pin(self, http: impl AsRef, message_id: impl Into) -> Result<()> { - http.as_ref().pin_message(self, message_id.into(), None).await + pub async fn pin(self, http: impl AsRef, message_id: MessageId) -> Result<()> { + http.as_ref().pin_message(self, message_id, None).await } /// Crossposts a [`Message`]. @@ -569,12 +560,8 @@ impl ChannelId { /// author of the message. /// /// [Manage Messages]: Permissions::MANAGE_MESSAGES - pub async fn crosspost( - self, - http: impl AsRef, - message_id: impl Into, - ) -> Result { - http.as_ref().crosspost_message(self, message_id.into()).await + pub async fn crosspost(self, http: impl AsRef, message_id: MessageId) -> Result { + http.as_ref().crosspost_message(self, message_id).await } /// Gets the list of [`Message`]s which are pinned to the channel. @@ -616,7 +603,7 @@ impl ChannelId { pub async fn reaction_users( self, http: impl AsRef, - message_id: impl Into, + message_id: MessageId, reaction_type: impl Into, limit: Option, after: impl Into>, @@ -626,7 +613,7 @@ impl ChannelId { http.as_ref() .get_reaction_users( self, - message_id.into(), + message_id, &reaction_type.into(), limit, after.into().map(UserId::get), @@ -800,12 +787,8 @@ impl ChannelId { /// /// [Manage Messages]: Permissions::MANAGE_MESSAGES #[inline] - pub async fn unpin( - self, - http: impl AsRef, - message_id: impl Into, - ) -> Result<()> { - http.as_ref().unpin_message(self, message_id.into(), None).await + pub async fn unpin(self, http: impl AsRef, message_id: MessageId) -> Result<()> { + http.as_ref().unpin_message(self, message_id, None).await } /// Retrieves the channel's webhooks. @@ -937,10 +920,10 @@ impl ChannelId { pub async fn create_thread_from_message( self, cache_http: impl CacheHttp, - message_id: impl Into, + message_id: MessageId, builder: CreateThread<'_>, ) -> Result { - builder.execute(cache_http, (self, Some(message_id.into()))).await + builder.execute(cache_http, (self, Some(message_id))).await } /// Creates a thread that is not connected to a message. diff --git a/src/model/channel/guild_channel.rs b/src/model/channel/guild_channel.rs index 7559a7a3853..bebb1674cc4 100644 --- a/src/model/channel/guild_channel.rs +++ b/src/model/channel/guild_channel.rs @@ -418,7 +418,7 @@ impl GuildChannel { pub async fn delete_reaction( &self, http: impl AsRef, - message_id: impl Into, + message_id: MessageId, user_id: Option, reaction_type: impl Into, ) -> Result<()> { @@ -440,7 +440,7 @@ impl GuildChannel { pub async fn delete_reactions( &self, http: impl AsRef, - message_id: impl Into, + message_id: MessageId, ) -> Result<()> { self.id.delete_reactions(http, message_id).await } @@ -503,7 +503,7 @@ impl GuildChannel { pub async fn edit_message( &self, cache_http: impl CacheHttp, - message_id: impl Into, + message_id: MessageId, builder: EditMessage<'_>, ) -> Result { self.id.edit_message(cache_http, message_id, builder).await @@ -566,10 +566,10 @@ impl GuildChannel { pub async fn edit_voice_state( &self, cache_http: impl CacheHttp, - user_id: impl Into, + user_id: UserId, builder: EditVoiceState, ) -> Result<()> { - builder.execute(cache_http, (self.guild_id, self.id, Some(user_id.into()))).await + builder.execute(cache_http, (self.guild_id, self.id, Some(user_id))).await } /// Edits the current user's voice state in a stage channel. @@ -638,7 +638,7 @@ impl GuildChannel { pub async fn follow( &self, http: impl AsRef, - target_channel_id: impl Into, + target_channel_id: ChannelId, ) -> Result { self.id.follow(http, target_channel_id).await } @@ -688,7 +688,7 @@ impl GuildChannel { pub async fn message( &self, cache_http: impl CacheHttp, - message_id: impl Into, + message_id: MessageId, ) -> Result { self.id.message(cache_http, message_id).await } @@ -739,7 +739,7 @@ impl GuildChannel { /// None => return, /// }; /// - /// if let Ok(permissions) = channel.permissions_for_user(&context.cache, &msg.author) { + /// if let Ok(permissions) = channel.permissions_for_user(&context.cache, msg.author.id) { /// println!("The user's permissions: {:?}", permissions); /// } /// } @@ -758,11 +758,10 @@ impl GuildChannel { pub fn permissions_for_user( &self, cache: impl AsRef, - user_id: impl Into, + user_id: UserId, ) -> Result { let guild = self.guild(&cache).ok_or(Error::Model(ModelError::GuildNotFound))?; - let member = - guild.members.get(&user_id.into()).ok_or(Error::Model(ModelError::MemberNotFound))?; + let member = guild.members.get(&user_id).ok_or(Error::Model(ModelError::MemberNotFound))?; Ok(guild.user_permissions_in(self, member)) } @@ -777,11 +776,7 @@ impl GuildChannel { /// /// [Manage Messages]: Permissions::MANAGE_MESSAGES #[inline] - pub async fn pin( - &self, - http: impl AsRef, - message_id: impl Into, - ) -> Result<()> { + pub async fn pin(&self, http: impl AsRef, message_id: MessageId) -> Result<()> { self.id.pin(http, message_id).await } @@ -823,7 +818,7 @@ impl GuildChannel { pub async fn reaction_users( &self, http: impl AsRef, - message_id: impl Into, + message_id: MessageId, reaction_type: impl Into, limit: Option, after: impl Into>, @@ -938,11 +933,7 @@ impl GuildChannel { /// /// [Manage Messages]: Permissions::MANAGE_MESSAGES #[inline] - pub async fn unpin( - &self, - http: impl AsRef, - message_id: impl Into, - ) -> Result<()> { + pub async fn unpin(&self, http: impl AsRef, message_id: MessageId) -> Result<()> { self.id.unpin(http, message_id).await } @@ -994,8 +985,8 @@ impl GuildChannel { ChannelType::News | ChannelType::Text => Ok(guild .members .iter() - .filter(|e| { - self.permissions_for_user(cache, e.0) + .filter(|(id, _)| { + self.permissions_for_user(cache, **id) .map(|p| p.contains(Permissions::VIEW_CHANNEL)) .unwrap_or(false) }) @@ -1116,7 +1107,7 @@ impl GuildChannel { pub async fn create_thread_from_message( &self, cache_http: impl CacheHttp, - message_id: impl Into, + message_id: MessageId, builder: CreateThread<'_>, ) -> Result { self.id.create_thread_from_message(cache_http, message_id, builder).await diff --git a/src/model/channel/message.rs b/src/model/channel/message.rs index 7c1b64a2f86..53ecaaf2610 100644 --- a/src/model/channel/message.rs +++ b/src/model/channel/message.rs @@ -692,8 +692,8 @@ impl Message { /// Checks whether the message mentions passed [`UserId`]. #[inline] - pub fn mentions_user_id(&self, id: impl Into) -> bool { - let id = id.into(); + #[must_use] + pub fn mentions_user_id(&self, id: UserId) -> bool { self.mentions.iter().any(|mentioned_user| mentioned_user.id == id) } diff --git a/src/model/channel/private_channel.rs b/src/model/channel/private_channel.rs index db0bb9a1024..348d80cddd8 100644 --- a/src/model/channel/private_channel.rs +++ b/src/model/channel/private_channel.rs @@ -62,7 +62,7 @@ impl PrivateChannel { pub async fn create_reaction( &self, http: impl AsRef, - message_id: impl Into, + message_id: MessageId, reaction_type: impl Into, ) -> Result<()> { self.id.create_reaction(http, message_id, reaction_type).await @@ -125,7 +125,7 @@ impl PrivateChannel { pub async fn delete_reaction( &self, http: impl AsRef, - message_id: impl Into, + message_id: MessageId, user_id: Option, reaction_type: impl Into, ) -> Result<()> { @@ -152,7 +152,7 @@ impl PrivateChannel { pub async fn edit_message( &self, cache_http: impl CacheHttp, - message_id: impl Into, + message_id: MessageId, builder: EditMessage<'_>, ) -> Result { self.id.edit_message(cache_http, message_id, builder).await @@ -178,7 +178,7 @@ impl PrivateChannel { pub async fn message( &self, cache_http: impl CacheHttp, - message_id: impl Into, + message_id: MessageId, ) -> Result { self.id.message(cache_http, message_id).await } @@ -224,7 +224,7 @@ impl PrivateChannel { pub async fn reaction_users( &self, http: impl AsRef, - message_id: impl Into, + message_id: MessageId, reaction_type: impl Into, limit: Option, after: impl Into>, @@ -238,11 +238,7 @@ impl PrivateChannel { /// /// Returns [`Error::Http`] if the number of pinned messages would exceed the 50 message limit. #[inline] - pub async fn pin( - &self, - http: impl AsRef, - message_id: impl Into, - ) -> Result<()> { + pub async fn pin(&self, http: impl AsRef, message_id: MessageId) -> Result<()> { self.id.pin(http, message_id).await } @@ -363,11 +359,7 @@ impl PrivateChannel { /// Returns [`Error::Http`] if the current user lacks permission, if the message was deleted, /// or if the channel already has the limit of 50 pinned messages. #[inline] - pub async fn unpin( - &self, - http: impl AsRef, - message_id: impl Into, - ) -> Result<()> { + pub async fn unpin(&self, http: impl AsRef, message_id: MessageId) -> Result<()> { self.id.unpin(http, message_id).await } } diff --git a/src/model/error.rs b/src/model/error.rs index 22de21ce5fd..ebaae2f4e1b 100644 --- a/src/model/error.rs +++ b/src/model/error.rs @@ -26,7 +26,7 @@ use super::Permissions; /// #[cfg(feature = "client")] /// impl EventHandler for Handler { /// async fn guild_ban_removal(&self, context: Context, guild_id: GuildId, user: User) { -/// match guild_id.ban(&context, user, 8).await { +/// match guild_id.ban(&context, user.id, 8).await { /// Ok(()) => { /// // Ban successful. /// }, diff --git a/src/model/guild/guild_id.rs b/src/model/guild/guild_id.rs index 889caa0ec97..e0d8d3ea36a 100644 --- a/src/model/guild/guild_id.rs +++ b/src/model/guild/guild_id.rs @@ -65,12 +65,8 @@ impl GuildId { /// /// [Manage Guild]: Permissions::MANAGE_GUILD #[inline] - pub async fn automod_rule( - self, - http: impl AsRef, - rule_id: impl Into, - ) -> Result { - http.as_ref().get_automod_rule(self, rule_id.into()).await + pub async fn automod_rule(self, http: impl AsRef, rule_id: RuleId) -> Result { + http.as_ref().get_automod_rule(self, rule_id).await } /// Creates an auto moderation [`Rule`] in the guild. @@ -135,10 +131,10 @@ impl GuildId { pub async fn edit_automod_rule( self, cache_http: impl CacheHttp, - rule_id: impl Into, + rule_id: RuleId, builder: EditAutoModRule<'_>, ) -> Result { - builder.execute(cache_http, (self, Some(rule_id.into()))).await + builder.execute(cache_http, (self, Some(rule_id))).await } /// Deletes an auto moderation [`Rule`] from the guild. @@ -152,12 +148,8 @@ impl GuildId { /// /// [Manage Guild]: Permissions::MANAGE_GUILD #[inline] - pub async fn delete_automod_rule( - self, - http: impl AsRef, - rule_id: impl Into, - ) -> Result<()> { - http.as_ref().delete_automod_rule(self, rule_id.into(), None).await + pub async fn delete_automod_rule(self, http: impl AsRef, rule_id: RuleId) -> Result<()> { + http.as_ref().delete_automod_rule(self, rule_id, None).await } /// Adds a [`User`] to this guild with a valid OAuth2 access token. @@ -172,10 +164,10 @@ impl GuildId { pub async fn add_member( self, cache_http: impl CacheHttp, - user_id: impl Into, + user_id: UserId, builder: AddMember<'_>, ) -> Result> { - builder.execute(cache_http, (self, user_id.into())).await + builder.execute(cache_http, (self, user_id)).await } /// Ban a [`User`] from the guild, deleting a number of days' worth of messages (`dmd`) between @@ -211,8 +203,8 @@ impl GuildId { /// /// [Ban Members]: Permissions::BAN_MEMBERS #[inline] - pub async fn ban(self, http: impl AsRef, user: impl Into, dmd: u8) -> Result<()> { - self._ban(http, user.into(), dmd, None).await + pub async fn ban(self, http: impl AsRef, user: UserId, dmd: u8) -> Result<()> { + self._ban(http, user, dmd, None).await } /// Ban a [`User`] from the guild with a reason. Refer to [`Self::ban`] to further @@ -226,11 +218,11 @@ impl GuildId { pub async fn ban_with_reason( self, http: impl AsRef, - user: impl Into, + user: UserId, dmd: u8, - reason: impl AsRef, + reason: &str, ) -> Result<()> { - self._ban(http, user.into(), dmd, Some(reason.as_ref())).await + self._ban(http, user, dmd, Some(reason)).await } async fn _ban( @@ -395,10 +387,9 @@ impl GuildId { pub async fn create_integration( self, http: impl AsRef, - integration_id: impl Into, + integration_id: IntegrationId, kind: &str, ) -> Result<()> { - let integration_id = integration_id.into(); let map = json!({ "id": integration_id, "type": kind, @@ -494,12 +485,8 @@ impl GuildId { /// [Create Guild Expressions]: Permissions::CREATE_GUILD_EXPRESSIONS /// [Manage Guild Expressions]: Permissions::MANAGE_GUILD_EXPRESSIONS #[inline] - pub async fn delete_emoji( - self, - http: impl AsRef, - emoji_id: impl Into, - ) -> Result<()> { - http.as_ref().delete_emoji(self, emoji_id.into(), None).await + pub async fn delete_emoji(self, http: impl AsRef, emoji_id: EmojiId) -> Result<()> { + http.as_ref().delete_emoji(self, emoji_id, None).await } /// Deletes an integration by Id from the guild. @@ -516,9 +503,9 @@ impl GuildId { pub async fn delete_integration( self, http: impl AsRef, - integration_id: impl Into, + integration_id: IntegrationId, ) -> Result<()> { - http.as_ref().delete_guild_integration(self, integration_id.into(), None).await + http.as_ref().delete_guild_integration(self, integration_id, None).await } /// Deletes a [`Role`] by Id from the guild. @@ -534,12 +521,8 @@ impl GuildId { /// /// [Manage Roles]: Permissions::MANAGE_ROLES #[inline] - pub async fn delete_role( - self, - http: impl AsRef, - role_id: impl Into, - ) -> Result<()> { - http.as_ref().delete_role(self, role_id.into(), None).await + pub async fn delete_role(self, http: impl AsRef, role_id: RoleId) -> Result<()> { + http.as_ref().delete_role(self, role_id, None).await } /// Deletes a specified scheduled event in the guild. @@ -557,9 +540,9 @@ impl GuildId { pub async fn delete_scheduled_event( self, http: impl AsRef, - event_id: impl Into, + event_id: ScheduledEventId, ) -> Result<()> { - http.as_ref().delete_scheduled_event(self, event_id.into()).await + http.as_ref().delete_scheduled_event(self, event_id).await } /// Deletes a [`Sticker`] by id from the guild. @@ -576,12 +559,8 @@ impl GuildId { /// [Create Guild Expressions]: Permissions::CREATE_GUILD_EXPRESSIONS /// [Manage Guild Expressions]: Permissions::MANAGE_GUILD_EXPRESSIONS #[inline] - pub async fn delete_sticker( - self, - http: impl AsRef, - sticker_id: impl Into, - ) -> Result<()> { - http.as_ref().delete_sticker(self, sticker_id.into(), None).await + pub async fn delete_sticker(self, http: impl AsRef, sticker_id: StickerId) -> Result<()> { + http.as_ref().delete_sticker(self, sticker_id, None).await } /// Edits the current guild with new data where specified. @@ -620,14 +599,14 @@ impl GuildId { pub async fn edit_emoji( self, http: impl AsRef, - emoji_id: impl Into, + emoji_id: EmojiId, name: &str, ) -> Result { let map = json!({ "name": name, }); - http.as_ref().edit_emoji(self, emoji_id.into(), &map, None).await + http.as_ref().edit_emoji(self, emoji_id, &map, None).await } /// Edits the properties a guild member, such as muting or nicknaming them. Returns the new @@ -662,10 +641,10 @@ impl GuildId { pub async fn edit_member( self, cache_http: impl CacheHttp, - user_id: impl Into, + user_id: UserId, builder: EditMember<'_>, ) -> Result { - builder.execute(cache_http, (self, user_id.into())).await + builder.execute(cache_http, (self, user_id)).await } /// Edits the guild's MFA level. Returns the new level on success. @@ -743,10 +722,10 @@ impl GuildId { pub async fn edit_role( self, cache_http: impl CacheHttp, - role_id: impl Into, + role_id: RoleId, builder: EditRole<'_>, ) -> Result { - builder.execute(cache_http, (self, Some(role_id.into()))).await + builder.execute(cache_http, (self, Some(role_id))).await } /// Modifies a scheduled event in the guild with the data set, if any. @@ -764,10 +743,10 @@ impl GuildId { pub async fn edit_scheduled_event( self, cache_http: impl CacheHttp, - event_id: impl Into, + event_id: ScheduledEventId, builder: EditScheduledEvent<'_>, ) -> Result { - builder.execute(cache_http, (self, event_id.into())).await + builder.execute(cache_http, (self, event_id)).await } /// Edits a sticker. @@ -803,10 +782,10 @@ impl GuildId { pub async fn edit_sticker( self, cache_http: impl CacheHttp, - sticker_id: impl Into, + sticker_id: StickerId, builder: EditSticker<'_>, ) -> Result { - builder.execute(cache_http, (self, sticker_id.into())).await + builder.execute(cache_http, (self, sticker_id)).await } /// Edit the position of a [`Role`] relative to all others in the [`Guild`]. @@ -829,10 +808,10 @@ impl GuildId { pub async fn edit_role_position( self, http: impl AsRef, - role_id: impl Into, + role_id: RoleId, position: u16, ) -> Result> { - http.as_ref().edit_role_position(self, role_id.into(), position, None).await + http.as_ref().edit_role_position(self, role_id, position, None).await } /// Edits the guild's welcome screen. @@ -1013,8 +992,8 @@ impl GuildId { /// /// [Kick Members]: Permissions::KICK_MEMBERS #[inline] - pub async fn kick(self, http: impl AsRef, user_id: impl Into) -> Result<()> { - http.as_ref().kick_member(self, user_id.into(), None).await + pub async fn kick(self, http: impl AsRef, user_id: UserId) -> Result<()> { + http.as_ref().kick_member(self, user_id, None).await } /// # Errors @@ -1025,10 +1004,10 @@ impl GuildId { pub async fn kick_with_reason( self, http: impl AsRef, - user_id: impl Into, + user_id: UserId, reason: &str, ) -> Result<()> { - http.as_ref().kick_member(self, user_id.into(), Some(reason)).await + http.as_ref().kick_member(self, user_id, Some(reason)).await } /// Returns a guild [`Member`] object for the current user. @@ -1065,13 +1044,7 @@ impl GuildId { /// Returns an [`Error::Http`] if the user is not in the guild, or if the guild is otherwise /// unavailable #[inline] - pub async fn member( - self, - cache_http: impl CacheHttp, - user_id: impl Into, - ) -> Result { - let user_id = user_id.into(); - + pub async fn member(self, cache_http: impl CacheHttp, user_id: UserId) -> Result { #[cfg(feature = "cache")] { if let Some(cache) = cache_http.cache() { @@ -1150,10 +1123,10 @@ impl GuildId { pub async fn move_member( self, cache_http: impl CacheHttp, - user_id: impl Into, - channel_id: impl Into, + user_id: UserId, + channel_id: ChannelId, ) -> Result { - let builder = EditMember::new().voice_channel(channel_id.into()); + let builder = EditMember::new().voice_channel(channel_id); self.edit_member(cache_http, user_id, builder).await } @@ -1178,7 +1151,7 @@ impl GuildId { pub async fn disconnect_member( self, cache_http: impl CacheHttp, - user_id: impl Into, + user_id: UserId, ) -> Result { self.edit_member(cache_http, user_id, EditMember::new().disconnect_member()).await } @@ -1265,10 +1238,10 @@ impl GuildId { pub async fn scheduled_event( self, http: impl AsRef, - event_id: impl Into, + event_id: ScheduledEventId, with_user_count: bool, ) -> Result { - http.as_ref().get_scheduled_event(self, event_id.into(), with_user_count).await + http.as_ref().get_scheduled_event(self, event_id, with_user_count).await } /// Fetches a list of all scheduled events in the guild. If `with_user_count` is set to `true`, @@ -1304,10 +1277,10 @@ impl GuildId { pub async fn scheduled_event_users( self, http: impl AsRef, - event_id: impl Into, + event_id: ScheduledEventId, limit: Option, ) -> Result> { - http.as_ref().get_scheduled_event_users(self, event_id.into(), limit, None, None).await + http.as_ref().get_scheduled_event_users(self, event_id, limit, None, None).await } /// Fetches a list of interested users for the specified event, with additional options and @@ -1324,14 +1297,12 @@ impl GuildId { pub async fn scheduled_event_users_optioned( self, http: impl AsRef, - event_id: impl Into, + event_id: ScheduledEventId, limit: Option, target: Option, with_member: Option, ) -> Result> { - http.as_ref() - .get_scheduled_event_users(self, event_id.into(), limit, target, with_member) - .await + http.as_ref().get_scheduled_event_users(self, event_id, limit, target, with_member).await } /// Returns the Id of the shard associated with the guild. @@ -1389,9 +1360,9 @@ impl GuildId { pub async fn start_integration_sync( self, http: impl AsRef, - integration_id: impl Into, + integration_id: IntegrationId, ) -> Result<()> { - http.as_ref().start_integration_sync(self, integration_id.into()).await + http.as_ref().start_integration_sync(self, integration_id).await } /// Starts a prune of [`Member`]s. @@ -1420,8 +1391,8 @@ impl GuildId { /// /// [Ban Members]: Permissions::BAN_MEMBERS #[inline] - pub async fn unban(self, http: impl AsRef, user_id: impl Into) -> Result<()> { - http.as_ref().remove_ban(self, user_id.into(), None).await + pub async fn unban(self, http: impl AsRef, user_id: UserId) -> Result<()> { + http.as_ref().remove_ban(self, user_id, None).await } /// Retrieve's the guild's vanity URL. diff --git a/src/model/guild/member.rs b/src/model/guild/member.rs index 9179f88fa79..cbde1d1fee7 100644 --- a/src/model/guild/member.rs +++ b/src/model/guild/member.rs @@ -99,8 +99,8 @@ impl Member { /// /// [Manage Roles]: Permissions::MANAGE_ROLES #[inline] - pub async fn add_role(&self, http: impl AsRef, role_id: impl Into) -> Result<()> { - http.as_ref().add_member_role(self.guild_id, self.user.id, role_id.into(), None).await + pub async fn add_role(&self, http: impl AsRef, role_id: RoleId) -> Result<()> { + http.as_ref().add_member_role(self.guild_id, self.user.id, role_id, None).await } /// Adds one or multiple [`Role`]s to the member. @@ -114,7 +114,7 @@ impl Member { /// /// [Manage Roles]: Permissions::MANAGE_ROLES pub async fn add_roles(&self, http: impl AsRef, role_ids: &[RoleId]) -> Result<()> { - for role_id in role_ids { + for &role_id in role_ids { self.add_role(http.as_ref(), role_id).await?; } @@ -149,7 +149,7 @@ impl Member { &self, http: impl AsRef, dmd: u8, - reason: impl AsRef, + reason: &str, ) -> Result<()> { self.guild_id.ban_with_reason(http, self.user.id, dmd, reason).await } @@ -402,7 +402,7 @@ impl Member { pub async fn move_to_voice_channel( &self, cache_http: impl CacheHttp, - channel: impl Into, + channel: ChannelId, ) -> Result { self.guild_id.move_member(cache_http, self.user.id, channel).await } @@ -454,12 +454,8 @@ impl Member { /// lacks permission. /// /// [Manage Roles]: Permissions::MANAGE_ROLES - pub async fn remove_role( - &self, - http: impl AsRef, - role_id: impl Into, - ) -> Result<()> { - http.as_ref().remove_member_role(self.guild_id, self.user.id, role_id.into(), None).await + pub async fn remove_role(&self, http: impl AsRef, role_id: RoleId) -> Result<()> { + http.as_ref().remove_member_role(self.guild_id, self.user.id, role_id, None).await } /// Removes one or multiple [`Role`]s from the member. @@ -473,7 +469,7 @@ impl Member { /// /// [Manage Roles]: Permissions::MANAGE_ROLES pub async fn remove_roles(&self, http: impl AsRef, role_ids: &[RoleId]) -> Result<()> { - for role_id in role_ids { + for &role_id in role_ids { self.remove_role(http.as_ref(), role_id).await?; } diff --git a/src/model/guild/mod.rs b/src/model/guild/mod.rs index 68bb7cc8c16..2fbf503f1d7 100644 --- a/src/model/guild/mod.rs +++ b/src/model/guild/mod.rs @@ -307,11 +307,7 @@ impl Guild { /// /// [Manage Guild]: Permissions::MANAGE_GUILD #[inline] - pub async fn automod_rule( - &self, - http: impl AsRef, - rule_id: impl Into, - ) -> Result { + pub async fn automod_rule(&self, http: impl AsRef, rule_id: RuleId) -> Result { self.id.automod_rule(http, rule_id).await } @@ -350,7 +346,7 @@ impl Guild { pub async fn edit_automod_rule( &self, cache_http: impl CacheHttp, - rule_id: impl Into, + rule_id: RuleId, builder: EditAutoModRule<'_>, ) -> Result { self.id.edit_automod_rule(cache_http, rule_id, builder).await @@ -367,11 +363,7 @@ impl Guild { /// /// [Manage Guild]: Permissions::MANAGE_GUILD #[inline] - pub async fn delete_automod_rule( - &self, - http: impl AsRef, - rule_id: impl Into, - ) -> Result<()> { + pub async fn delete_automod_rule(&self, http: impl AsRef, rule_id: RuleId) -> Result<()> { self.id.delete_automod_rule(http, rule_id).await } @@ -435,12 +427,7 @@ impl Guild { } #[cfg(feature = "cache")] - pub fn channel_id_from_name( - &self, - cache: impl AsRef, - name: impl AsRef, - ) -> Option { - let name = name.as_ref(); + pub fn channel_id_from_name(&self, cache: impl AsRef, name: &str) -> Option { let guild_channels = cache.as_ref().guild_channels(self.id)?; for (id, channel) in guild_channels.iter() { @@ -481,13 +468,8 @@ impl Guild { /// /// [Ban Members]: Permissions::BAN_MEMBERS #[inline] - pub async fn ban( - &self, - cache_http: impl CacheHttp, - user: impl Into, - dmd: u8, - ) -> Result<()> { - self._ban_with_reason(cache_http, user.into(), dmd, "").await + pub async fn ban(&self, cache_http: impl CacheHttp, user: UserId, dmd: u8) -> Result<()> { + self.ban_with_reason(cache_http, user, dmd, "").await } /// Ban a [`User`] from the guild with a reason. Refer to [`Self::ban`] to further @@ -499,16 +481,6 @@ impl Guild { /// [`Error::ExceededLimit`] may also be returned if the reason is too long. #[inline] pub async fn ban_with_reason( - &self, - cache_http: impl CacheHttp, - user: impl Into, - dmd: u8, - reason: impl AsRef, - ) -> Result<()> { - self._ban_with_reason(cache_http, user.into(), dmd, reason.as_ref()).await - } - - async fn _ban_with_reason( &self, cache_http: impl CacheHttp, user: UserId, @@ -572,7 +544,7 @@ impl Guild { pub async fn add_member( &self, cache_http: impl CacheHttp, - user_id: impl Into, + user_id: UserId, builder: AddMember<'_>, ) -> Result> { self.id.add_member(cache_http, user_id, builder).await @@ -734,7 +706,7 @@ impl Guild { pub async fn create_integration( &self, http: impl AsRef, - integration_id: impl Into, + integration_id: IntegrationId, kind: &str, ) -> Result<()> { self.id.create_integration(http, integration_id, kind).await @@ -973,11 +945,7 @@ impl Guild { /// [Create Guild Expressions]: Permissions::CREATE_GUILD_EXPRESSIONS /// [Manage Guild Expressions]: Permissions::MANAGE_GUILD_EXPRESSIONS #[inline] - pub async fn delete_emoji( - &self, - http: impl AsRef, - emoji_id: impl Into, - ) -> Result<()> { + pub async fn delete_emoji(&self, http: impl AsRef, emoji_id: EmojiId) -> Result<()> { self.id.delete_emoji(http, emoji_id).await } @@ -995,7 +963,7 @@ impl Guild { pub async fn delete_integration( &self, http: impl AsRef, - integration_id: impl Into, + integration_id: IntegrationId, ) -> Result<()> { self.id.delete_integration(http, integration_id).await } @@ -1012,11 +980,7 @@ impl Guild { /// /// [Manage Roles]: Permissions::MANAGE_ROLES #[inline] - pub async fn delete_role( - &self, - http: impl AsRef, - role_id: impl Into, - ) -> Result<()> { + pub async fn delete_role(&self, http: impl AsRef, role_id: RoleId) -> Result<()> { self.id.delete_role(http, role_id).await } @@ -1035,7 +999,7 @@ impl Guild { pub async fn delete_scheduled_event( &self, http: impl AsRef, - event_id: impl Into, + event_id: ScheduledEventId, ) -> Result<()> { self.id.delete_scheduled_event(http, event_id).await } @@ -1057,7 +1021,7 @@ impl Guild { pub async fn delete_sticker( &self, http: impl AsRef, - sticker_id: impl Into, + sticker_id: StickerId, ) -> Result<()> { self.id.delete_sticker(http, sticker_id).await } @@ -1127,7 +1091,7 @@ impl Guild { pub async fn edit_emoji( &self, http: impl AsRef, - emoji_id: impl Into, + emoji_id: EmojiId, name: &str, ) -> Result { self.id.edit_emoji(http, emoji_id, name).await @@ -1150,7 +1114,7 @@ impl Guild { pub async fn edit_member( &self, cache_http: impl CacheHttp, - user_id: impl Into, + user_id: UserId, builder: EditMember<'_>, ) -> Result { self.id.edit_member(cache_http, user_id, builder).await @@ -1219,7 +1183,7 @@ impl Guild { pub async fn edit_role( &self, cache_http: impl CacheHttp, - role_id: impl Into, + role_id: RoleId, builder: EditRole<'_>, ) -> Result { self.id.edit_role(cache_http, role_id, builder).await @@ -1245,7 +1209,7 @@ impl Guild { pub async fn edit_role_position( &self, http: impl AsRef, - role_id: impl Into, + role_id: RoleId, position: u16, ) -> Result> { self.id.edit_role_position(http, role_id, position).await @@ -1266,7 +1230,7 @@ impl Guild { pub async fn edit_scheduled_event( &self, cache_http: impl CacheHttp, - event_id: impl Into, + event_id: ScheduledEventId, builder: EditScheduledEvent<'_>, ) -> Result { self.id.edit_scheduled_event(cache_http, event_id, builder).await @@ -1308,7 +1272,7 @@ impl Guild { pub async fn edit_sticker( &self, cache_http: impl CacheHttp, - sticker_id: impl Into, + sticker_id: StickerId, builder: EditSticker<'_>, ) -> Result { self.id.edit_sticker(cache_http, sticker_id, builder).await @@ -1357,11 +1321,8 @@ impl Guild { /// /// Returns an [`Error::Http`] if the current user is not in the guild. #[inline] - pub async fn get( - cache_http: impl CacheHttp, - guild_id: impl Into, - ) -> Result { - guild_id.into().to_partial_guild(cache_http).await + pub async fn get(cache_http: impl CacheHttp, guild_id: GuildId) -> Result { + guild_id.to_partial_guild(cache_http).await } /// Returns which of two [`User`]s has a higher [`Member`] hierarchy. @@ -1381,10 +1342,10 @@ impl Guild { pub fn greater_member_hierarchy( &self, cache: impl AsRef, - lhs_id: impl Into, - rhs_id: impl Into, + lhs_id: UserId, + rhs_id: UserId, ) -> Option { - self._greater_member_hierarchy(&cache, lhs_id.into(), rhs_id.into()) + self._greater_member_hierarchy(&cache, lhs_id, rhs_id) } #[cfg(feature = "cache")] @@ -1525,7 +1486,7 @@ impl Guild { /// /// [Kick Members]: Permissions::KICK_MEMBERS #[inline] - pub async fn kick(&self, http: impl AsRef, user_id: impl Into) -> Result<()> { + pub async fn kick(&self, http: impl AsRef, user_id: UserId) -> Result<()> { self.id.kick(http, user_id).await } @@ -1537,7 +1498,7 @@ impl Guild { pub async fn kick_with_reason( &self, http: impl AsRef, - user_id: impl Into, + user_id: UserId, reason: &str, ) -> Result<()> { self.id.kick_with_reason(http, user_id, reason).await @@ -1580,10 +1541,8 @@ impl Guild { pub async fn member( &self, cache_http: impl CacheHttp, - user_id: impl Into, + user_id: UserId, ) -> Result> { - let user_id = user_id.into(); - if let Some(member) = self.members.get(&user_id) { Ok(Cow::Borrowed(member)) } else { @@ -1903,8 +1862,8 @@ impl Guild { pub async fn move_member( &self, cache_http: impl CacheHttp, - user_id: impl Into, - channel_id: impl Into, + user_id: UserId, + channel_id: ChannelId, ) -> Result { self.id.move_member(cache_http, user_id, channel_id).await } @@ -2076,7 +2035,7 @@ impl Guild { pub async fn scheduled_event( &self, http: impl AsRef, - event_id: impl Into, + event_id: ScheduledEventId, with_user_count: bool, ) -> Result { self.id.scheduled_event(http, event_id, with_user_count).await @@ -2115,7 +2074,7 @@ impl Guild { pub async fn scheduled_event_users( &self, http: impl AsRef, - event_id: impl Into, + event_id: ScheduledEventId, limit: Option, ) -> Result> { self.id.scheduled_event_users(http, event_id, limit).await @@ -2135,7 +2094,7 @@ impl Guild { pub async fn scheduled_event_users_optioned( &self, http: impl AsRef, - event_id: impl Into, + event_id: ScheduledEventId, limit: Option, target: Option, with_member: Option, @@ -2202,7 +2161,7 @@ impl Guild { pub async fn start_integration_sync( &self, http: impl AsRef, - integration_id: impl Into, + integration_id: IntegrationId, ) -> Result<()> { self.id.start_integration_sync(http, integration_id).await } @@ -2248,11 +2207,7 @@ impl Guild { /// Otherwise will return an [`Error::Http`] if the current user does not have permission. /// /// [Ban Members]: Permissions::BAN_MEMBERS - pub async fn unban( - &self, - cache_http: impl CacheHttp, - user_id: impl Into, - ) -> Result<()> { + pub async fn unban(&self, cache_http: impl CacheHttp, user_id: UserId) -> Result<()> { #[cfg(feature = "cache")] { if let Some(cache) = cache_http.cache() { diff --git a/src/model/guild/partial_guild.rs b/src/model/guild/partial_guild.rs index f4a158ce439..8a8d128f920 100644 --- a/src/model/guild/partial_guild.rs +++ b/src/model/guild/partial_guild.rs @@ -209,11 +209,7 @@ impl PartialGuild { /// /// [Manage Guild]: Permissions::MANAGE_GUILD #[inline] - pub async fn automod_rule( - &self, - http: impl AsRef, - rule_id: impl Into, - ) -> Result { + pub async fn automod_rule(&self, http: impl AsRef, rule_id: RuleId) -> Result { self.id.automod_rule(http, rule_id).await } @@ -252,7 +248,7 @@ impl PartialGuild { pub async fn edit_automod_rule( &self, cache_http: impl CacheHttp, - rule_id: impl Into, + rule_id: RuleId, builder: EditAutoModRule<'_>, ) -> Result { self.id.edit_automod_rule(cache_http, rule_id, builder).await @@ -269,11 +265,7 @@ impl PartialGuild { /// /// [Manage Guild]: Permissions::MANAGE_GUILD #[inline] - pub async fn delete_automod_rule( - &self, - http: impl AsRef, - rule_id: impl Into, - ) -> Result<()> { + pub async fn delete_automod_rule(&self, http: impl AsRef, rule_id: RuleId) -> Result<()> { self.id.delete_automod_rule(http, rule_id).await } @@ -300,12 +292,7 @@ impl PartialGuild { /// /// [Ban Members]: Permissions::BAN_MEMBERS #[inline] - pub async fn ban( - &self, - http: impl AsRef, - user: impl Into, - dmd: u8, - ) -> Result<()> { + pub async fn ban(&self, http: impl AsRef, user: UserId, dmd: u8) -> Result<()> { self.ban_with_reason(http, user, dmd, "").await } @@ -320,9 +307,9 @@ impl PartialGuild { pub async fn ban_with_reason( &self, http: impl AsRef, - user: impl Into, + user: UserId, dmd: u8, - reason: impl AsRef, + reason: &str, ) -> Result<()> { self.id.ban_with_reason(http, user, dmd, reason).await } @@ -384,12 +371,7 @@ impl PartialGuild { } #[cfg(feature = "cache")] - pub fn channel_id_from_name( - &self, - cache: impl AsRef, - name: impl AsRef, - ) -> Option { - let name = name.as_ref(); + pub fn channel_id_from_name(&self, cache: impl AsRef, name: &str) -> Option { let guild_channels = cache.as_ref().guild_channels(self.id)?; for (id, channel) in guild_channels.iter() { @@ -486,7 +468,7 @@ impl PartialGuild { pub async fn create_integration( &self, http: impl AsRef, - integration_id: impl Into, + integration_id: IntegrationId, kind: &str, ) -> Result<()> { self.id.create_integration(http, integration_id, kind).await @@ -696,11 +678,7 @@ impl PartialGuild { /// [Create Guild Expressions]: Permissions::CREATE_GUILD_EXPRESSIONS /// [Manage Guild Expressions]: Permissions::MANAGE_GUILD_EXPRESSIONS #[inline] - pub async fn delete_emoji( - &self, - http: impl AsRef, - emoji_id: impl Into, - ) -> Result<()> { + pub async fn delete_emoji(&self, http: impl AsRef, emoji_id: EmojiId) -> Result<()> { self.id.delete_emoji(http, emoji_id).await } @@ -718,7 +696,7 @@ impl PartialGuild { pub async fn delete_integration( &self, http: impl AsRef, - integration_id: impl Into, + integration_id: IntegrationId, ) -> Result<()> { self.id.delete_integration(http, integration_id).await } @@ -736,11 +714,7 @@ impl PartialGuild { /// /// [Manage Roles]: Permissions::MANAGE_ROLES #[inline] - pub async fn delete_role( - &self, - http: impl AsRef, - role_id: impl Into, - ) -> Result<()> { + pub async fn delete_role(&self, http: impl AsRef, role_id: RoleId) -> Result<()> { self.id.delete_role(http, role_id).await } @@ -761,7 +735,7 @@ impl PartialGuild { pub async fn delete_sticker( &self, http: impl AsRef, - sticker_id: impl Into, + sticker_id: StickerId, ) -> Result<()> { self.id.delete_sticker(http, sticker_id).await } @@ -811,7 +785,7 @@ impl PartialGuild { pub async fn edit_emoji( &self, http: impl AsRef, - emoji_id: impl Into, + emoji_id: EmojiId, name: &str, ) -> Result { self.id.edit_emoji(http, emoji_id, name).await @@ -834,7 +808,7 @@ impl PartialGuild { pub async fn edit_member( &self, cache_http: impl CacheHttp, - user_id: impl Into, + user_id: UserId, builder: EditMember<'_>, ) -> Result { self.id.edit_member(cache_http, user_id, builder).await @@ -894,7 +868,7 @@ impl PartialGuild { pub async fn edit_role( &self, cache_http: impl CacheHttp, - role_id: impl Into, + role_id: RoleId, builder: EditRole<'_>, ) -> Result { self.id.edit_role(cache_http, role_id, builder).await @@ -920,7 +894,7 @@ impl PartialGuild { pub async fn edit_role_position( &self, http: impl AsRef, - role_id: impl Into, + role_id: RoleId, position: u16, ) -> Result> { self.id.edit_role_position(http, role_id, position).await @@ -962,7 +936,7 @@ impl PartialGuild { pub async fn edit_sticker( &self, cache_http: impl CacheHttp, - sticker_id: impl Into, + sticker_id: StickerId, builder: EditSticker<'_>, ) -> Result { self.id.edit_sticker(cache_http, sticker_id, builder).await @@ -1009,11 +983,8 @@ impl PartialGuild { /// Returns [`Error::Http`] if the current user is not /// in the guild. #[inline] - pub async fn get( - cache_http: impl CacheHttp, - guild_id: impl Into, - ) -> Result { - guild_id.into().to_partial_guild(cache_http).await + pub async fn get(cache_http: impl CacheHttp, guild_id: GuildId) -> Result { + guild_id.to_partial_guild(cache_http).await } /// Returns which of two [`User`]s has a higher [`Member`] hierarchy. @@ -1033,10 +1004,10 @@ impl PartialGuild { pub fn greater_member_hierarchy( &self, cache: impl AsRef, - lhs_id: impl Into, - rhs_id: impl Into, + lhs_id: UserId, + rhs_id: UserId, ) -> Option { - self._greater_member_hierarchy(&cache, lhs_id.into(), rhs_id.into()) + self._greater_member_hierarchy(&cache, lhs_id, rhs_id) } #[cfg(feature = "cache")] @@ -1191,7 +1162,7 @@ impl PartialGuild { /// /// [Kick Members]: Permissions::KICK_MEMBERS #[inline] - pub async fn kick(&self, http: impl AsRef, user_id: impl Into) -> Result<()> { + pub async fn kick(&self, http: impl AsRef, user_id: UserId) -> Result<()> { self.id.kick(http, user_id).await } @@ -1203,7 +1174,7 @@ impl PartialGuild { pub async fn kick_with_reason( &self, http: impl AsRef, - user_id: impl Into, + user_id: UserId, reason: &str, ) -> Result<()> { self.id.kick_with_reason(http, user_id, reason).await @@ -1300,11 +1271,7 @@ impl PartialGuild { /// Returns [`Error::Http`] if the member is not in the Guild, or if the Guild is otherwise /// unavailable. #[inline] - pub async fn member( - &self, - cache_http: impl CacheHttp, - user_id: impl Into, - ) -> Result { + pub async fn member(&self, cache_http: impl CacheHttp, user_id: UserId) -> Result { self.id.member(cache_http, user_id).await } @@ -1345,8 +1312,8 @@ impl PartialGuild { pub async fn move_member( &self, cache_http: impl CacheHttp, - user_id: impl Into, - channel_id: impl Into, + user_id: UserId, + channel_id: ChannelId, ) -> Result { self.id.move_member(cache_http, user_id, channel_id).await } @@ -1440,7 +1407,7 @@ impl PartialGuild { pub async fn start_integration_sync( &self, http: impl AsRef, - integration_id: impl Into, + integration_id: IntegrationId, ) -> Result<()> { self.id.start_integration_sync(http, integration_id).await } @@ -1456,7 +1423,7 @@ impl PartialGuild { /// [Ban Members]: Permissions::BAN_MEMBERS /// [`Guild::unban`]: crate::model::guild::Guild::unban #[inline] - pub async fn unban(&self, http: impl AsRef, user_id: impl Into) -> Result<()> { + pub async fn unban(&self, http: impl AsRef, user_id: UserId) -> Result<()> { self.id.unban(http, user_id).await } diff --git a/src/model/invite.rs b/src/model/invite.rs index 54321a19d72..a2492cf4d53 100644 --- a/src/model/invite.rs +++ b/src/model/invite.rs @@ -77,10 +77,10 @@ impl Invite { #[inline] pub async fn create( cache_http: impl CacheHttp, - channel_id: impl Into, + channel_id: ChannelId, builder: CreateInvite<'_>, ) -> Result { - channel_id.into().create_invite(cache_http, builder).await + channel_id.create_invite(cache_http, builder).await } /// Deletes the invite. diff --git a/src/model/user.rs b/src/model/user.rs index e41b730d15f..5733146eb37 100644 --- a/src/model/user.rs +++ b/src/model/user.rs @@ -526,10 +526,10 @@ impl User { pub async fn has_role( &self, cache_http: impl CacheHttp, - guild_id: impl Into, - role: impl Into, + guild_id: GuildId, + role: RoleId, ) -> Result { - guild_id.into().member(cache_http, self).await.map(|m| m.roles.contains(&role.into())) + guild_id.member(cache_http, self.id).await.map(|m| m.roles.contains(&role)) } /// Refreshes the information about the user. @@ -589,13 +589,7 @@ impl User { /// /// If none is used, it returns [`None`]. #[inline] - pub async fn nick_in( - &self, - cache_http: impl CacheHttp, - guild_id: impl Into, - ) -> Option { - let guild_id = guild_id.into(); - + pub async fn nick_in(&self, cache_http: impl CacheHttp, guild_id: GuildId) -> Option { // This can't be removed because `GuildId::member` clones the entire `Member` struct if // it's present in the cache, which is expensive. #[cfg(feature = "cache")] @@ -611,7 +605,7 @@ impl User { // At this point we're guaranteed to do an API call. guild_id - .member(cache_http, &self.id) + .member(cache_http, self.id) .await .ok() .and_then(|member| member.nick) diff --git a/src/model/webhook.rs b/src/model/webhook.rs index edd191f905f..de0b4aab7b9 100644 --- a/src/model/webhook.rs +++ b/src/model/webhook.rs @@ -251,8 +251,8 @@ impl Webhook { /// /// May also return an [`Error::Json`] if there is an error in deserialising Discord's /// response. - pub async fn from_id(http: impl AsRef, webhook_id: impl Into) -> Result { - http.as_ref().get_webhook(webhook_id.into()).await + pub async fn from_id(http: impl AsRef, webhook_id: WebhookId) -> Result { + http.as_ref().get_webhook(webhook_id).await } /// Retrieves a webhook given its Id and unique token. @@ -285,10 +285,10 @@ impl Webhook { /// response. pub async fn from_id_with_token( http: impl AsRef, - webhook_id: impl Into, + webhook_id: WebhookId, token: &str, ) -> Result { - http.as_ref().get_webhook_with_token(webhook_id.into(), token).await + http.as_ref().get_webhook_with_token(webhook_id, token).await } /// Retrieves a webhook given its url. diff --git a/src/utils/content_safe.rs b/src/utils/content_safe.rs index 249fd6edfb9..1a3bf1ee4b1 100644 --- a/src/utils/content_safe.rs +++ b/src/utils/content_safe.rs @@ -90,12 +90,8 @@ impl Default for ContentSafeOptions { /// } /// } /// ``` -pub fn content_safe( - guild: &Guild, - s: impl AsRef, - options: ContentSafeOptions, - users: &[User], -) -> String { +#[must_use] +pub fn content_safe(guild: &Guild, s: &str, options: ContentSafeOptions, users: &[User]) -> String { let mut content = clean_mentions(guild, s, options, users); if options.get_clean_here() { @@ -109,13 +105,7 @@ pub fn content_safe( content } -fn clean_mentions( - guild: &Guild, - s: impl AsRef, - options: ContentSafeOptions, - users: &[User], -) -> String { - let s = s.as_ref(); +fn clean_mentions(guild: &Guild, s: &str, options: ContentSafeOptions, users: &[User]) -> String { let mut content = String::with_capacity(s.len()); let mut brackets = s.match_indices(|c| c == '<' || c == '>').peekable(); let mut progress = 0; diff --git a/src/utils/mod.rs b/src/utils/mod.rs index e681ad0f3d7..838710e3690 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -258,11 +258,9 @@ pub fn parse_channel_mention(mention: &str) -> Option { /// ``` /// /// [`Emoji`]: crate::model::guild::Emoji -pub fn parse_emoji(mention: impl AsRef) -> Option { - let mention = mention.as_ref(); - +#[must_use] +pub fn parse_emoji(mention: &str) -> Option { let len = mention.len(); - if !(6..=56).contains(&len) { return None; } @@ -325,8 +323,8 @@ pub fn parse_emoji(mention: impl AsRef) -> Option { /// /// assert_eq!(parse_quotes(command), expected); /// ``` -pub fn parse_quotes(s: impl AsRef) -> Vec { - let s = s.as_ref(); +#[must_use] +pub fn parse_quotes(s: &str) -> Vec { let mut args = vec![]; let mut in_string = false; let mut escaping = false; diff --git a/src/utils/token.rs b/src/utils/token.rs index 4a8d8e27c96..6059ebe9296 100644 --- a/src/utils/token.rs +++ b/src/utils/token.rs @@ -27,9 +27,9 @@ use std::{fmt, str}; /// /// Returns a [`InvalidToken`] when one of the above checks fail. The type of failure is not /// specified. -pub fn validate(token: impl AsRef) -> Result<(), InvalidToken> { +pub fn validate(token: &str) -> Result<(), InvalidToken> { // Tokens can be preceded by "Bot " (that's how the Discord API expects them) - let mut parts = token.as_ref().trim_start_matches("Bot ").split('.'); + let mut parts = token.trim_start_matches("Bot ").split('.'); let is_valid = parts.next().is_some_and(|p| !p.is_empty()) && parts.next().is_some_and(|p| !p.is_empty())