Updated deps, updated generate_passwords to return an array

This commit is contained in:
2023-05-31 15:26:06 +03:00
parent ee815e5f61
commit 5566397e66
2 changed files with 35 additions and 99 deletions

View File

@@ -29,7 +29,7 @@ fn check_generated_password(password: &[u8]) -> bool {
/// Continuously generates the password until it passes the checks
#[inline]
fn generete_passwords() -> ArrayVec<ArrayString<34>, 10> {
fn generate_passwords() -> [ArrayString<34>; 10] {
let mut passwords = ArrayVec::new_const();
while !passwords.is_full() {
let password: ArrayVec<u8, 32> = (0..32)
@@ -43,13 +43,13 @@ fn generete_passwords() -> ArrayVec<ArrayString<34>, 10> {
passwords.push(string)
}
}
passwords
unsafe { passwords.into_inner_unchecked() }
}
/// Handles /gen_password command by generating 10 copyable passwords and sending them to the user
pub async fn gen_password(bot: Throttle<Bot>, msg: Message) -> crate::Result<()> {
let mut message: ArrayString<{ 10 + 35 * 10 }> = "Passwords:".try_into().unwrap();
let passwords = spawn_blocking(generete_passwords).await?;
let passwords = spawn_blocking(generate_passwords).await?;
for password in passwords {
message.push('\n');
message.push_str(&password)