/messages/send now correctyl tells the user they're wrong about sendingmessages to a non-existant channel

This commit is contained in:
shockrah
2020-12-30 01:00:47 -08:00
parent 7c95519402
commit dfe53b323e
2 changed files with 44 additions and 6 deletions

View File

@@ -124,15 +124,32 @@ impl Message {
(time, content, author_id, channel_id)
VALUES (:time, :content, :author, :channel)";
let now = Utc::now().timestamp();
conn.prep_exec(q, params!{
let res = conn.prep_exec(q, params!{
"time" => now,
"content" => content,
"author" => uid,
"channel" => cid
}).await?;
}).await;
if let Err(e) = res {
return match e {
SqlError::Server(err) => {
if err.code == 1452 {
return Ok(Response::RestrictedInput("Channel not found".into()))
}
else {
Ok(Response::Other(sql_err!("db::messages::send")))
}
},
_ => Ok(Response::Other(sql_err!("db::messages::send")))
}
}
// all good response
else {
return Ok(Response::Empty);
}
return Ok(Response::Empty);
}
}