From 0723199ed2495d73dc9a62d33eab7481ca1245f0 Mon Sep 17 00:00:00 2001 From: NatrixAeria Date: Sat, 26 Sep 2020 18:21:09 +0200 Subject: Replace doule match with more readable code --- src/main.rs | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/src/main.rs b/src/main.rs index 8ac2edd..455da50 100644 --- a/src/main.rs +++ b/src/main.rs @@ -53,32 +53,37 @@ mod commands { .ok_or_else(|| Box::new(super::BotError::MissingGuild).into()) } + async fn create_channel_no_cache<'n, 'd>( + ctx: &Context, + guild: &Guild, + desc: ChannelDescriptor<'n, 'd>, + ) -> Result { + Ok(guild + .create_channel(ctx, |c| { + let c = c.name(desc.name).topic(desc.description).kind(desc.kind); + if let Some(parent) = desc.parent { + c.category(parent) + } else { + c + } + }) + .await?) + } + async fn create_channel<'n, 'd>( ctx: &Context, guild: &Guild, desc: ChannelDescriptor<'n, 'd>, ) -> Result { let channel = guild.channel_id_from_name(&ctx.cache, desc.name).await; - Ok( - match match channel { - Some(channel) => ctx.cache.guild_channel(channel).await, - None => None, - } { - Some(channel) => channel, - None => { - guild - .create_channel(ctx, |c| { - let c = c.name(desc.name).topic(desc.description).kind(desc.kind); - if let Some(parent) = desc.parent { - c.category(parent) - } else { - c - } - }) - .await? - } - }, - ) + let optional_channel = match channel { + Some(channel) => ctx.cache.guild_channel(channel).await, + None => None, + }; + match optional_channel { + Some(channel) => Ok(channel), + None => create_channel_no_cache(ctx, guild, desc).await, + } } #[command] -- cgit v1.2.3-54-g00ecf