fix quote error weridness

This commit is contained in:
Tanner Sommers 2024-11-25 18:54:53 -06:00
parent 9ccb11f52f
commit 7e52129bbc
3 changed files with 16 additions and 6 deletions

View File

@ -14,7 +14,7 @@ pub async fn quote_action(
username: message.author.name.clone(),
quote: message.content.clone(),
added_by: ctx.author().id.into(),
added_at: OffsetDateTime::now_utc(),
added_at: Some(OffsetDateTime::now_utc()),
};
if quote.user_id == quote.added_by {
@ -40,7 +40,12 @@ pub async fn random_quote(ctx: Context<'_>) -> Result<(), Error> {
"{}: {}\nQuoted at: <t:{}:f> by <@{}>",
quote.username,
quote.quote,
quote.added_at.unix_timestamp(),
if let Some(added_at) = quote.added_at {
added_at.unix_timestamp()
} else {
// Use now if added_at is None
OffsetDateTime::now_utc().unix_timestamp()
},
quote.added_by
))
.allowed_mentions(CreateAllowedMentions::new().empty_users()),
@ -76,7 +81,12 @@ pub async fn user_quotes(
"{}: {}\nQuoted at: <t:{}:f> by <@{}>\n",
quote.username,
quote.quote,
quote.added_at.unix_timestamp(),
if let Some(added_at) = quote.added_at {
added_at.unix_timestamp()
} else {
// Use now if added_at is None
OffsetDateTime::now_utc().unix_timestamp()
},
quote.added_by
));
}

View File

@ -151,7 +151,7 @@ impl DatabaseController {
username: quote.username,
quote: quote.quote,
added_by: quote.added_by,
added_at: quote.added_at.unwrap(),
added_at: quote.added_at,
})),
None => Ok(None),
}
@ -170,7 +170,7 @@ impl DatabaseController {
username: q.username,
quote: q.quote,
added_by: q.added_by,
added_at: q.added_at.unwrap(),
added_at: q.added_at,
});
}

View File

@ -7,5 +7,5 @@ pub struct Quote {
pub username: String,
pub quote: String,
pub added_by: i64,
pub added_at: OffsetDateTime,
pub added_at: Option<OffsetDateTime>,
}