summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNatrixAeria <upezu@student.kit.edu>2020-09-26 18:21:09 +0200
committerNatrixAeria <upezu@student.kit.edu>2020-09-26 18:21:09 +0200
commit0723199ed2495d73dc9a62d33eab7481ca1245f0 (patch)
tree1e8230bd3b410aca0bea36b0f17a02b46d4175e9
parent52376d0a993cab721c94ccc2a410aad213701dda (diff)
Replace doule match with more readable code
-rw-r--r--src/main.rs45
1 files 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<GuildChannel, CommandError> {
+ 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<GuildChannel, CommandError> {
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]