improvements

This commit is contained in:
nora 2022-06-19 21:40:14 +02:00
parent e851bd7449
commit a2d7f73960
2 changed files with 22 additions and 18 deletions

View file

@ -23,19 +23,11 @@ impl Debug for Handler {
} }
} }
pub enum Response { pub struct Response(pub String);
EphemeralStr(&'static str),
Ephemeral(String),
NoPermissions,
}
impl Display for Response { impl Display for Response {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self { f.write_str(&self.0)
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!"),
}
} }
} }
@ -431,5 +423,17 @@ pub async fn listener(
} }
pub async fn error_handler(error: poise::FrameworkError<'_, Handler, Report>) { 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");
}
}
} }

View file

@ -63,8 +63,8 @@ impl LawsuitCtx {
Ok(room) => room, Ok(room) => room,
} }
} }
(None, None) => return Ok(Response::EphemeralStr( (None, None) => return Ok(Response(
"Zuerst eine Kategorie für die Gerichtsräume festlegen mit `/lawsuit set_category`", "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 <#{}>", "ha eine ufgmacht im channel <#{}>",
channel_id channel_id
))) )))
@ -147,7 +147,7 @@ impl LawsuitCtx {
room: CourtRoom, room: CourtRoom,
) -> Result<Result<(), Response>> { ) -> Result<Result<(), Response>> {
if self.lawsuit.judge != user_id.into() && !permission_override { 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); self.lawsuit.verdict = Some(verdict);
@ -313,8 +313,8 @@ impl LawsuitCtx {
} }
None => { None => {
// todo: remove the court room from the db // todo: remove the court room from the db
return Ok(Err(Response::EphemeralStr( return Ok(Err(Response(
"i ha de channel für de prozess nöd gfunde", "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) { let channel_id = match channels.values().find(|c| c.name() == room_name) {
Some(channel) => { Some(channel) => {
if channel.parent_id != Some(category_id.into()) { 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" "de channel {room_name} isch i de falsche kategorie, man eh"
)))); ))));
} }