From a2d7f739603071d2dd0d02c4cf1dfe6e3cea1644 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Sun, 19 Jun 2022 21:40:14 +0200 Subject: [PATCH] improvements --- src/handler.rs | 26 +++++++++++++++----------- src/lawsuit.rs | 14 +++++++------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/handler.rs b/src/handler.rs index c639a1a..106e17e 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -23,19 +23,11 @@ impl Debug for Handler { } } -pub enum Response { - EphemeralStr(&'static str), - Ephemeral(String), - NoPermissions, -} +pub struct Response(pub String); impl Display for Response { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - match self { - Self::EphemeralStr(str) => f.write_str(str), - Self::Ephemeral(str) => f.write_str(str), - Self::NoPermissions => f.write_str("du häsch kei recht für da!"), - } + f.write_str(&self.0) } } @@ -431,5 +423,17 @@ pub async fn listener( } pub async fn error_handler(error: poise::FrameworkError<'_, Handler, Report>) { - error!(?error, "Error during command execution"); + match error { + poise::FrameworkError::MissingUserPermissions { ctx, .. } => { + let _ = ctx.say("du häsch kei recht für da!").await; + } + poise::FrameworkError::GuildOnly { ctx } => { + let _ = ctx + .say("du chasch de command nur uf emene serve nutze!") + .await; + } + err => { + error!(?err, "Error during command execution"); + } + } } diff --git a/src/lawsuit.rs b/src/lawsuit.rs index d7035db..c07f1fc 100644 --- a/src/lawsuit.rs +++ b/src/lawsuit.rs @@ -63,8 +63,8 @@ impl LawsuitCtx { Ok(room) => room, } } - (None, None) => return Ok(Response::EphemeralStr( - "Zuerst eine Kategorie für die Gerichtsräume festlegen mit `/lawsuit set_category`", + (None, None) => return Ok(Response( + "Zuerst eine Kategorie für die Gerichtsräume festlegen mit `/lawsuit set_category`".to_string(), )), }; @@ -86,7 +86,7 @@ impl LawsuitCtx { } }); - Ok(Response::Ephemeral(format!( + Ok(Response(format!( "ha eine ufgmacht im channel <#{}>", channel_id ))) @@ -147,7 +147,7 @@ impl LawsuitCtx { room: CourtRoom, ) -> Result> { if self.lawsuit.judge != user_id.into() && !permission_override { - return Ok(Err(Response::NoPermissions)); + return Ok(Err(Response("du häsch kei recht für da!".to_string()))); } self.lawsuit.verdict = Some(verdict); @@ -313,8 +313,8 @@ impl LawsuitCtx { } None => { // todo: remove the court room from the db - return Ok(Err(Response::EphemeralStr( - "i ha de channel für de prozess nöd gfunde", + return Ok(Err(Response( + "i ha de channel für de prozess nöd gfunde".to_string(), ))); } } @@ -358,7 +358,7 @@ impl LawsuitCtx { let channel_id = match channels.values().find(|c| c.name() == room_name) { Some(channel) => { if channel.parent_id != Some(category_id.into()) { - return Ok(Err(Response::Ephemeral(format!( + return Ok(Err(Response(format!( "de channel {room_name} isch i de falsche kategorie, man eh" )))); }