better error display

This commit is contained in:
Gabriel Fontes
2022-01-28 13:55:52 -03:00
parent 2d364eb6c0
commit 660bb1ae17
4 changed files with 15 additions and 5 deletions

2
Cargo.lock generated
View File

@@ -486,7 +486,7 @@ dependencies = [
[[package]]
name = "disconic"
version = "0.1.0"
version = "0.1.1"
dependencies = [
"anyhow",
"dotenv",

View File

@@ -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"

View File

@@ -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()

View File

@@ -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