From 4cd0249427dcbb92810089223cac57755ab8114e Mon Sep 17 00:00:00 2001 From: "Sarah A." Date: Sun, 15 Oct 2023 20:52:02 +0100 Subject: [PATCH 1/3] Add Context::guild_channel() --- src/structs/context.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/structs/context.rs b/src/structs/context.rs index 86965ca94313..750b0e60d3c6 100644 --- a/src/structs/context.rs +++ b/src/structs/context.rs @@ -2,6 +2,8 @@ use std::borrow::Cow; +use ::serenity::model::prelude::GuildChannel; + use crate::serenity_prelude as serenity; // needed for proc macro @@ -214,6 +216,18 @@ context_methods! { } } + /// Return the guild channel of this context, if we are inside a guild. + #[cfg(feature = "cache")] + await (guild_channel self) + (pub async fn guild_channel(self) -> Option) { + if let Ok(channel) = self.channel_id().to_channel(self.serenity_context()).await { + if let serenity::Channel::Guild(guild_channel) = channel { + return Some(guild_channel); + } + } + None + } + // Doesn't fit in with the rest of the functions here but it's convenient /// Return the guild of this context, if we are inside a guild. /// From a75224290e722d61d60d34b719a45c9d06cdb75a Mon Sep 17 00:00:00 2001 From: "Sarah A." Date: Sun, 15 Oct 2023 20:54:56 +0100 Subject: [PATCH 2/3] Fix erroneous import --- src/structs/context.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/structs/context.rs b/src/structs/context.rs index 750b0e60d3c6..05dd56c8cac9 100644 --- a/src/structs/context.rs +++ b/src/structs/context.rs @@ -2,8 +2,6 @@ use std::borrow::Cow; -use ::serenity::model::prelude::GuildChannel; - use crate::serenity_prelude as serenity; // needed for proc macro From 50e7972279dfad29851beeed59c046215acb803a Mon Sep 17 00:00:00 2001 From: kangalio Date: Sun, 15 Oct 2023 23:25:15 +0200 Subject: [PATCH 3/3] Succumb to clippy --- src/structs/context.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/structs/context.rs b/src/structs/context.rs index 05dd56c8cac9..877a5c5ac47c 100644 --- a/src/structs/context.rs +++ b/src/structs/context.rs @@ -218,10 +218,8 @@ context_methods! { #[cfg(feature = "cache")] await (guild_channel self) (pub async fn guild_channel(self) -> Option) { - if let Ok(channel) = self.channel_id().to_channel(self.serenity_context()).await { - if let serenity::Channel::Guild(guild_channel) = channel { - return Some(guild_channel); - } + if let Ok(serenity::Channel::Guild(guild_channel)) = self.channel_id().to_channel(self.serenity_context()).await { + return Some(guild_channel); } None }