Use propagation message ID to query instead of materialized view
This commit is contained in:
@@ -26,10 +26,12 @@ 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? else {
|
||||
return Err(ArgumentParsingError::InvalidArgument);
|
||||
};
|
||||
Ok(user)
|
||||
let user = User::get_by_id(id, db).await?;
|
||||
|
||||
match user {
|
||||
Some(user) => Ok(user),
|
||||
None => Err(ArgumentParsingError::InvalidArgument),
|
||||
}
|
||||
}
|
||||
|
||||
/// Fetches the user from the message's reply and falls back to the command executor.
|
||||
@@ -45,20 +47,19 @@ async fn get_user_by_id(id: u64, db: &Session) -> Result<User, ArgumentParsingEr
|
||||
async fn user_from_reply_or_command_executor(
|
||||
ctx: &CommandContext<'_, State, Extras>,
|
||||
) -> Result<User, ArgumentParsingError> {
|
||||
if let Some(referenced) = &ctx.event.referenced_message {
|
||||
if !referenced.author.system.unwrap_or(false) {
|
||||
if referenced.author.bot {
|
||||
if let Some(message) =
|
||||
Message::get_by_propagation_message_id(referenced.id.get(), &ctx.rt.state.db)
|
||||
.await?
|
||||
{
|
||||
return get_user_by_id(message.author_id, &ctx.rt.state.db).await;
|
||||
}
|
||||
}
|
||||
|
||||
// If the replied message's author is not a bot or system user, use them.
|
||||
return get_user_by_id(referenced.author.id.get(), &ctx.rt.state.db).await;
|
||||
if let Some(referenced) = &ctx.event.referenced_message
|
||||
&& !referenced.author.system.unwrap_or(false)
|
||||
{
|
||||
if referenced.author.bot
|
||||
&& let Some(message) =
|
||||
Message::get_by_propagation_message_id(referenced.id.get(), &ctx.rt.state.db)
|
||||
.await?
|
||||
{
|
||||
return get_user_by_id(message.author_id, &ctx.rt.state.db).await;
|
||||
}
|
||||
|
||||
// If the replied message's author is not a bot or system user, use them.
|
||||
return get_user_by_id(referenced.author.id.get(), &ctx.rt.state.db).await;
|
||||
}
|
||||
|
||||
// fallback to command executor
|
||||
|
||||
Reference in New Issue
Block a user