Run rustfmt

This commit is contained in:
Yash Karandikar 2021-12-29 14:25:49 -06:00
parent 2499f6bb40
commit 6e5cbc4ad9
Signed by untrusted user: karx
GPG key ID: A794DA2529474BA5
4 changed files with 26 additions and 16 deletions

View file

@ -6,7 +6,6 @@ macro_rules! hashmap {
}}
}
pub fn mock(target: &str) -> String {
let mut builder = String::with_capacity(target.len());
@ -44,4 +43,4 @@ pub fn leetify(target: &str) -> String {
}
builder
}
}

View file

@ -1,3 +1,3 @@
pub mod leek;
pub mod title;
pub mod weeb;
pub mod leek;

View file

@ -1,8 +1,8 @@
use arrayvec::{ArrayString, CapacityError};
use rand::Rng;
use serde_json::Value;
use tracing::debug;
use std::result::Result;
use tracing::debug;
pub async fn get_waifu_pic(category: &str) -> anyhow::Result<Option<String>> {
let api_resp = reqwest::get(format!("https://api.waifu.pics/sfw/{}", category))
@ -24,19 +24,22 @@ impl<T> From<CapacityError<T>> for OwoCapacityError {
}
}
pub fn owoify_out_of_place(input: &str, output: &mut ArrayString<512>) -> Result<(), OwoCapacityError> {
pub fn owoify_out_of_place(
input: &str,
output: &mut ArrayString<512>,
) -> Result<(), OwoCapacityError> {
let input: ArrayString<512> = ArrayString::from(input)?;
let mut rng = rand::thread_rng();
let mut last_char = '\0';
for byte in input.bytes() {
let mut ch = char::from(byte);
if !ch.is_ascii() {
continue
continue;
}
// owoify character
ch = match ch.to_ascii_lowercase() {
'r' | 'l' => 'w',
_ => ch
_ => ch,
};
// stutter (e.g. "o-ohayou gozaimasu!")
if last_char == ' ' && rng.gen_bool(0.2) {
@ -47,7 +50,7 @@ pub fn owoify_out_of_place(input: &str, output: &mut ArrayString<512>) -> Result
// nya-ify
'a' | 'e' | 'i' | 'o' | 'u' if last_char == 'n' => {
output.try_push('y')?;
},
}
// textmoji
'.' => {
output.try_push_str(match rng.gen_range(0..6) {

View file

@ -169,31 +169,39 @@ async fn handle_privmsg(
let user = match remainder {
Some(u) => match u {
"" => &nick,
_ => u
_ => u,
},
None => &nick
}.trim();
None => &nick,
}
.trim();
if let Some(prev_msg) = state.last_msgs.get(user) {
let resp = bots::leek::mock(prev_msg);
state.client.privmsg(&channel, &resp).await?;
} else {
state.client.privmsg(&channel, "No previous messages to mock!").await?;
state
.client
.privmsg(&channel, "No previous messages to mock!")
.await?;
}
}
"leet" => {
let user = match remainder {
Some(u) => match u {
"" => &nick,
_ => u
_ => u,
},
None => &nick
}.trim();
None => &nick,
}
.trim();
tracing::info!(user);
if let Some(prev_msg) = state.last_msgs.get(user) {
let resp = bots::leek::leetify(prev_msg);
state.client.privmsg(&channel, &resp).await?;
} else {
state.client.privmsg(&channel, "No previous messages to leetify!").await?;
state
.client
.privmsg(&channel, "No previous messages to leetify!")
.await?;
}
}
_ => {