forked from sorceress/rustcord
Improve error handling
This commit is contained in:
parent
0b9dc15067
commit
42f2f855c8
25
src/main.rs
25
src/main.rs
|
@ -99,11 +99,19 @@ fn main() {
|
||||||
.say(&ctx.http, &format!("Try again in {} seconds.", seconds));
|
.say(&ctx.http, &format!("Try again in {} seconds.", seconds));
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.after(|_ctx, _msg, cmd_name, error| {
|
.after(|ctx, msg, cmd_name, error| {
|
||||||
if let Err(why) = error {
|
if let Err(why) = error {
|
||||||
|
let _ = msg.channel_id.send_message(&ctx.http, |m| {
|
||||||
|
m.embed(|e| {
|
||||||
|
e.title(format!("Error in **{}**", cmd_name))
|
||||||
|
.description(&why.0)
|
||||||
|
/*.thumbnail("https://i.imgur.com/VzOEz2E.png") oh no */
|
||||||
|
.colour(0xff6961)
|
||||||
|
})
|
||||||
|
});
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"{}",
|
"{}",
|
||||||
format!("Error in {}: {}", cmd_name.purple(), why.0.red().bold())
|
format!("Error in {}: {}", cmd_name.purple(), &why.0.red().bold())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -229,13 +237,12 @@ fn host(ctx: &mut Context, message: &Message) -> CommandResult {
|
||||||
&ctx.http,
|
&ctx.http,
|
||||||
format!(
|
format!(
|
||||||
"OS: {os}; {release}\nHost: {host}\nCPU: {cpu}MHz",
|
"OS: {os}; {release}\nHost: {host}\nCPU: {cpu}MHz",
|
||||||
os = sys_info::os_type().unwrap(),
|
os = sys_info::os_type()?,
|
||||||
host = sys_info::hostname().unwrap(),
|
host = sys_info::hostname()?,
|
||||||
release = sys_info::linux_os_release()
|
release = sys_info::linux_os_release()?
|
||||||
.unwrap()
|
|
||||||
.pretty_name
|
.pretty_name
|
||||||
.unwrap_or_else(|| "Unknown".to_string()),
|
.unwrap_or_else(|| "Unknown".to_string()),
|
||||||
cpu = sys_info::cpu_speed().unwrap()
|
cpu = sys_info::cpu_speed()?
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -349,7 +356,7 @@ fn bottom_rng(ctx: &mut Context, message: &Message, mut args: Args) -> CommandRe
|
||||||
if let Err(e) = messages {
|
if let Err(e) = messages {
|
||||||
let _ = message.channel_id.say(&ctx.http, format!("Error: {}", e));
|
let _ = message.channel_id.say(&ctx.http, format!("Error: {}", e));
|
||||||
} else {
|
} else {
|
||||||
let mut messages = messages.unwrap();
|
let mut messages = messages?;
|
||||||
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();
|
||||||
for msg in messages {
|
for msg in messages {
|
||||||
|
@ -561,7 +568,7 @@ fn info(ctx: &mut Context, message: &Message, args: Args) -> CommandResult {
|
||||||
}
|
}
|
||||||
|
|
||||||
let num = ctx.cache.read().guilds.len();
|
let num = ctx.cache.read().guilds.len();
|
||||||
let aganame = OWNERS.clone()[0].to_user(ctx.http.clone()).unwrap().tag();
|
let aganame = OWNERS.clone()[0].to_user(ctx.http.clone())?.tag();
|
||||||
let _ = message.channel_id.send_message(&ctx.http, |m| m
|
let _ = message.channel_id.send_message(&ctx.http, |m| m
|
||||||
.embed(|e| e
|
.embed(|e| e
|
||||||
.title("Discordinator9000's info:")
|
.title("Discordinator9000's info:")
|
||||||
|
|
Loading…
Reference in New Issue