forked from sorceress/rustcord
Clean up match statements in main.rs
This commit is contained in:
parent
7c43b9e1cd
commit
e5bc576c83
85
src/main.rs
85
src/main.rs
|
@ -14,7 +14,8 @@ use serenity::{
|
||||||
},
|
},
|
||||||
framework::standard::{
|
framework::standard::{
|
||||||
macros::{check, command, group, hook},
|
macros::{check, command, group, hook},
|
||||||
Args, CommandOptions, CommandResult, DispatchError, Reason, StandardFramework,
|
Args, CommandError, CommandOptions, CommandResult, DispatchError, Reason,
|
||||||
|
StandardFramework,
|
||||||
},
|
},
|
||||||
model::{
|
model::{
|
||||||
channel::{Message, ReactionType},
|
channel::{Message, ReactionType},
|
||||||
|
@ -206,23 +207,21 @@ async fn ping(ctx: &Context, message: &Message) -> CommandResult {
|
||||||
// I have no idea if this works but its 5æm and I need to sleep help
|
// I have no idea if this works but its 5æm and I need to sleep help
|
||||||
let data = ctx.data.read().await;
|
let data = ctx.data.read().await;
|
||||||
|
|
||||||
let shard_manager = match data.get::<ShardManagerContainer>() {
|
let shard_manager = data
|
||||||
Some(v) => v,
|
.get::<ShardManagerContainer>()
|
||||||
None => return Err("There was a problem getting the shard manager!".into()),
|
.ok_or_else(|| CommandError::from("There was a problem getting the shard manager!"))?;
|
||||||
};
|
|
||||||
|
|
||||||
let manager = shard_manager.lock().await;
|
let manager = shard_manager.lock().await;
|
||||||
let runners = manager.runners.lock().await;
|
let runners = manager.runners.lock().await;
|
||||||
|
|
||||||
let runner = match runners.get(&ShardId(ctx.shard_id)) {
|
let runner = runners
|
||||||
Some(v) => v,
|
.get(&ShardId(ctx.shard_id))
|
||||||
None => return Err("No shard found!".into()),
|
.ok_or_else(|| CommandError::from("No shard found!"))?;
|
||||||
};
|
|
||||||
|
|
||||||
let ping = match runner.latency {
|
let ping = runner
|
||||||
Some(v) => v.as_millis(),
|
.latency
|
||||||
None => return Err("Could not get latency!".into()),
|
.ok_or_else(|| CommandError::from("Could not get latency!"))?
|
||||||
};
|
.as_millis();
|
||||||
|
|
||||||
let _ = message
|
let _ = message
|
||||||
.channel_id
|
.channel_id
|
||||||
|
@ -344,14 +343,12 @@ async fn bottom_rng(ctx: &Context, message: &Message, mut args: Args) -> Command
|
||||||
|
|
||||||
// get N last messages, otherwise 10
|
// get N last messages, otherwise 10
|
||||||
let num = args.single::<u64>().unwrap_or(10);
|
let num = args.single::<u64>().unwrap_or(10);
|
||||||
let messages = message
|
let mut messages = message
|
||||||
.channel_id
|
.channel_id
|
||||||
.messages(&ctx.http, |get| get.before(message.id).limit(num))
|
.messages(&ctx.http, |get| get.before(message.id).limit(num))
|
||||||
.await;
|
.await
|
||||||
if let Err(e) = messages {
|
.map_err(|e| CommandError::from(format!("Error: {}", e)))?;
|
||||||
return Err(format!("Error: {}", e).into());
|
|
||||||
} else {
|
|
||||||
let mut messages = messages?;
|
|
||||||
// remove all messages by other users
|
// remove all messages by other users
|
||||||
messages.retain(|v| v.author != message.mentions[0]);
|
messages.retain(|v| v.author != message.mentions[0]);
|
||||||
let mut input = String::new();
|
let mut input = String::new();
|
||||||
|
@ -369,7 +366,6 @@ async fn bottom_rng(ctx: &Context, message: &Message, mut args: Args) -> Command
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -389,7 +385,7 @@ async fn headpat(ctx: &Context, message: &Message, args: Args) -> CommandResult
|
||||||
_ => message.mentions[0].name.as_str(),
|
_ => message.mentions[0].name.as_str(),
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Err(e) = message
|
message
|
||||||
.channel_id
|
.channel_id
|
||||||
.send_message(&ctx.http, |m| {
|
.send_message(&ctx.http, |m| {
|
||||||
m.embed(|e| {
|
m.embed(|e| {
|
||||||
|
@ -400,10 +396,7 @@ async fn headpat(ctx: &Context, message: &Message, args: Args) -> CommandResult
|
||||||
.description("[Source](https://www.pinterest.com/pin/377809856242075277/)")
|
.description("[Source](https://www.pinterest.com/pin/377809856242075277/)")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.await
|
.await?;
|
||||||
{
|
|
||||||
let _ = message.channel_id.say(&ctx.http, format!("{:?}", e)).await;
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -530,20 +523,18 @@ async fn pfp(ctx: &Context, message: &Message) -> CommandResult {
|
||||||
async fn owo(ctx: &Context, message: &Message, args: Args) -> CommandResult {
|
async fn owo(ctx: &Context, message: &Message, args: Args) -> CommandResult {
|
||||||
use owoify::OwOifiable;
|
use owoify::OwOifiable;
|
||||||
|
|
||||||
let lastmsg = match message
|
let messages = message
|
||||||
.channel_id
|
.channel_id
|
||||||
.messages(&ctx.http, |get| get.before(message.id).limit(1))
|
.messages(&ctx.http, |get| get.before(message.id).limit(1))
|
||||||
.await
|
.await
|
||||||
{
|
.map_err(|_| CommandError::from("Could not get last message!"))?;
|
||||||
Ok(v) => v,
|
|
||||||
Err(_) => return Err("Could not get last message!".into()),
|
|
||||||
};
|
|
||||||
|
|
||||||
let lastmsg = &lastmsg[0].content;
|
let lastmsg = &messages[0].content;
|
||||||
|
|
||||||
let input: String = match args.is_empty() {
|
let input: String = if args.is_empty() {
|
||||||
true => s!(lastmsg),
|
s!(lastmsg)
|
||||||
false => args.rest().trim().to_string(),
|
} else {
|
||||||
|
args.rest().trim().to_string()
|
||||||
};
|
};
|
||||||
let _ = message.channel_id.say(&ctx.http, input.owoify()).await;
|
let _ = message.channel_id.say(&ctx.http, input.owoify()).await;
|
||||||
|
|
||||||
|
@ -555,23 +546,17 @@ async fn owo(ctx: &Context, message: &Message, args: Args) -> CommandResult {
|
||||||
#[only_in(guilds)]
|
#[only_in(guilds)]
|
||||||
#[aliases("description", "topic")]
|
#[aliases("description", "topic")]
|
||||||
async fn desc(ctx: &Context, message: &Message) -> CommandResult {
|
async fn desc(ctx: &Context, message: &Message) -> CommandResult {
|
||||||
let channel = match message.channel(&ctx).await {
|
let channel = message
|
||||||
Some(ch) => ch,
|
.channel(&ctx)
|
||||||
None => {
|
.await
|
||||||
return Err("Could not get channel!".into());
|
.ok_or_else(|| CommandError::from("Could not get channel!"))?;
|
||||||
}
|
let channel = channel
|
||||||
};
|
.guild()
|
||||||
let channel = match channel.guild() {
|
.ok_or_else(|| CommandError::from("Could not get guild channel!"))?;
|
||||||
Some(g) => g,
|
|
||||||
None => {
|
|
||||||
return Err("Could not get guild channel!".into());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let topic = if channel.topic.clone().unwrap() != "" {
|
let topic = match channel.topic.as_deref() {
|
||||||
channel.topic.clone().unwrap()
|
Some("") | None => String::from("No channel topic found"),
|
||||||
} else {
|
Some(topic) => topic.to_string(),
|
||||||
String::from("No channel topic found")
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let _ = message
|
let _ = message
|
||||||
|
|
Loading…
Reference in New Issue