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 { pub fn mock(target: &str) -> String {
let mut builder = String::with_capacity(target.len()); let mut builder = String::with_capacity(target.len());
@ -44,4 +43,4 @@ pub fn leetify(target: &str) -> String {
} }
builder builder
} }

View file

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

View file

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

View file

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