better error display
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -486,7 +486,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "disconic"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"dotenv",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "disconic"
|
||||
description = "Discord bot for interacting with subsonic music libraries"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
authors = [ "Gabriel Fontes <eu@misterio.me>" ]
|
||||
edition = "2018"
|
||||
homepage = "https://misterio.me"
|
||||
|
||||
@@ -7,7 +7,7 @@ use sunk::Client as SubsonicClient;
|
||||
|
||||
use std::{env, fs, io};
|
||||
|
||||
use crate::discord::{Handler, GENERAL_GROUP};
|
||||
use crate::discord::{Handler, GENERAL_GROUP, after_hook};
|
||||
|
||||
pub struct Client {
|
||||
ss_url: String,
|
||||
@@ -50,7 +50,8 @@ impl Client {
|
||||
.framework(
|
||||
StandardFramework::new()
|
||||
.configure(|c| c.prefix("~"))
|
||||
.group(&GENERAL_GROUP),
|
||||
.group(&GENERAL_GROUP)
|
||||
.after(after_hook)
|
||||
)
|
||||
.type_map_insert::<MusicClient>(ss)
|
||||
.register_songbird()
|
||||
|
||||
@@ -3,7 +3,7 @@ use serenity::{
|
||||
async_trait,
|
||||
client::{Context, EventHandler},
|
||||
framework::standard::{
|
||||
macros::{command, group},
|
||||
macros::{command, group, hook},
|
||||
Args, CommandResult,
|
||||
},
|
||||
model::channel::Message,
|
||||
@@ -28,6 +28,15 @@ pub struct Handler;
|
||||
#[async_trait]
|
||||
impl EventHandler for Handler {}
|
||||
|
||||
#[hook]
|
||||
pub async fn after_hook(ctx: &Context, msg: &Message, cmd_name: &str, error: CommandResult) {
|
||||
if let Err(why) = error {
|
||||
let text = format!("Error running {}: {:?}", cmd_name, why);
|
||||
msg.reply(&ctx.http, &text).await.ok();
|
||||
eprintln!("{}", &text);
|
||||
}
|
||||
}
|
||||
|
||||
#[command]
|
||||
#[aliases(s, p, play)]
|
||||
/// Play a named song
|
||||
|
||||
Reference in New Issue
Block a user