Updated my fork, review plz

This commit is contained in:
famfo 2021-12-29 00:12:09 +01:00
commit 56156333ee
5 changed files with 67 additions and 5 deletions

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
/target
uberbot_*.toml
uberbot.toml
Cargo.lock

8
Cargo.lock generated
View file

@ -26,6 +26,12 @@ version = "1.0.52"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "84450d0b4a8bd1ba4144ce8ce718fbc5d071358b1e5384bace6536b3d1f2d5b3"
[[package]]
name = "arrayvec"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6"
[[package]]
name = "async-circe"
version = "0.1.1"
@ -1343,9 +1349,11 @@ name = "uberbot"
version = "0.1.0"
dependencies = [
"anyhow",
"arrayvec",
"async-circe",
"fancy-regex",
"htmlescape",
"rand",
"reqwest",
"rspotify",
"serde",

View file

@ -15,5 +15,6 @@ rspotify = "0.11"
htmlescape = "0.3"
toml = "0.5"
serde = "1.0"
arrayvec = "0.7"
rand = "0.8"
async-circe = "0.1.1"

View file

@ -1,5 +1,8 @@
use arrayvec::{ArrayString, CapacityError};
use rand::Rng;
use serde_json::Value;
use tracing::debug;
use std::result::Result;
pub async fn get_waifu_pic(category: &str) -> anyhow::Result<Option<String>> {
let api_resp = reqwest::get(format!("https://api.waifu.pics/sfw/{}", category))
@ -13,4 +16,53 @@ pub async fn get_waifu_pic(category: &str) -> anyhow::Result<Option<String>> {
Ok(url)
}
// TODO: add owofier
pub struct OwoCapacityError(CapacityError);
impl<T> From<CapacityError<T>> for OwoCapacityError {
fn from(e: CapacityError<T>) -> Self {
Self { 0: e.simplify() }
}
}
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
}
// owoify character
ch = match ch.to_ascii_lowercase() {
'r' | 'l' => 'w',
_ => ch
};
// stutter (e.g. "o-ohayou gozaimasu!")
if last_char == ' ' && rng.gen_bool(0.2) {
output.try_push(ch)?;
output.try_push('-')?;
}
match ch {
// 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) {
1 => " OwO",
2 => " :3",
3 => " >w<",
4 => " >_<",
5 => " ^•ﻌ•^",
_ => " ^^",
})?;
}
_ => {}
}
output.try_push(ch)?;
last_char = ch;
}
Ok(())
}

View file

@ -61,11 +61,11 @@ async fn main() -> anyhow::Result<()> {
.with_env_filter(EnvFilter::from_env("UBERBOT_LOG"))
.init();
let mut file = File::open("uberbot.toml").unwrap();
let mut file = File::open("uberbot.toml")?;
let mut client_conf = String::new();
file.read_to_string(&mut client_conf).unwrap();
file.read_to_string(&mut client_conf)?;
let client_config: ClientConf = toml::from_str(&client_conf).unwrap();
let client_config: ClientConf = toml::from_str(&client_conf)?;
let spotify_creds = Credentials::new(
&client_config.spotify_client_id,