Updated my fork, review plz
This commit is contained in:
commit
56156333ee
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
||||||
/target
|
/target
|
||||||
uberbot_*.toml
|
uberbot_*.toml
|
||||||
uberbot.toml
|
uberbot.toml
|
||||||
|
Cargo.lock
|
8
Cargo.lock
generated
8
Cargo.lock
generated
|
@ -26,6 +26,12 @@ version = "1.0.52"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "84450d0b4a8bd1ba4144ce8ce718fbc5d071358b1e5384bace6536b3d1f2d5b3"
|
checksum = "84450d0b4a8bd1ba4144ce8ce718fbc5d071358b1e5384bace6536b3d1f2d5b3"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "arrayvec"
|
||||||
|
version = "0.7.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "async-circe"
|
name = "async-circe"
|
||||||
version = "0.1.1"
|
version = "0.1.1"
|
||||||
|
@ -1343,9 +1349,11 @@ name = "uberbot"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
"arrayvec",
|
||||||
"async-circe",
|
"async-circe",
|
||||||
"fancy-regex",
|
"fancy-regex",
|
||||||
"htmlescape",
|
"htmlescape",
|
||||||
|
"rand",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"rspotify",
|
"rspotify",
|
||||||
"serde",
|
"serde",
|
||||||
|
|
|
@ -15,5 +15,6 @@ rspotify = "0.11"
|
||||||
htmlescape = "0.3"
|
htmlescape = "0.3"
|
||||||
toml = "0.5"
|
toml = "0.5"
|
||||||
serde = "1.0"
|
serde = "1.0"
|
||||||
|
arrayvec = "0.7"
|
||||||
|
rand = "0.8"
|
||||||
async-circe = "0.1.1"
|
async-circe = "0.1.1"
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
|
use arrayvec::{ArrayString, CapacityError};
|
||||||
|
use rand::Rng;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
|
use std::result::Result;
|
||||||
|
|
||||||
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))
|
||||||
|
@ -13,4 +16,53 @@ pub async fn get_waifu_pic(category: &str) -> anyhow::Result<Option<String>> {
|
||||||
Ok(url)
|
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(())
|
||||||
|
}
|
||||||
|
|
|
@ -61,11 +61,11 @@ async fn main() -> anyhow::Result<()> {
|
||||||
.with_env_filter(EnvFilter::from_env("UBERBOT_LOG"))
|
.with_env_filter(EnvFilter::from_env("UBERBOT_LOG"))
|
||||||
.init();
|
.init();
|
||||||
|
|
||||||
let mut file = File::open("uberbot.toml").unwrap();
|
let mut file = File::open("uberbot.toml")?;
|
||||||
let mut client_conf = String::new();
|
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(
|
let spotify_creds = Credentials::new(
|
||||||
&client_config.spotify_client_id,
|
&client_config.spotify_client_id,
|
||||||
|
|
Loading…
Reference in a new issue