Add basic moderator commands
This commit is contained in:
@@ -22,10 +22,7 @@ use crate::{
|
||||
/// [`Result<User, ArgumentParser>`] - The user from the DB, or an [`ArgumentParsingError`] ready
|
||||
/// to be returned by the parser.
|
||||
async fn get_user_by_id(id: u64, db: &Session) -> Result<User, ArgumentParsingError> {
|
||||
let Some(user) = User::get_by_id(id, db)
|
||||
.await
|
||||
.map_err(|_| ArgumentParsingError::DatabaseFailed)?
|
||||
else {
|
||||
let Some(user) = User::get_by_id(id, db).await? else {
|
||||
return Err(ArgumentParsingError::InvalidArgument);
|
||||
};
|
||||
Ok(user)
|
||||
@@ -49,8 +46,7 @@ async fn user_from_reply_or_command_executor(
|
||||
if referenced.author.bot {
|
||||
if let Some(message) =
|
||||
Message::get_by_propagation_message_id(referenced.id.get(), &ctx.rt.state.db)
|
||||
.await
|
||||
.map_err(|_| ArgumentParsingError::DatabaseFailed)?
|
||||
.await?
|
||||
{
|
||||
return get_user_by_id(message.author_id, &ctx.rt.state.db).await;
|
||||
}
|
||||
@@ -112,10 +108,7 @@ impl FromArguments<State, Extras> for UserArgument {
|
||||
} else {
|
||||
// The argument is (probably) a username.
|
||||
|
||||
let Some(db_user) = User::get_by_name(identifier.0, &ctx.rt.state.db)
|
||||
.await
|
||||
.map_err(|_| ArgumentParsingError::DatabaseFailed)?
|
||||
else {
|
||||
let Some(db_user) = User::get_by_name(identifier.0, &ctx.rt.state.db).await? else {
|
||||
// Check in the message's reply, and if not use the command executor.
|
||||
user = user_from_reply_or_command_executor(ctx).await?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user