Merge pull request 'Port leek' (#3) from karx/uberbot:master into master
Reviewed-on: lemonsh/uberbot#3
This commit is contained in:
commit
b6a32859a1
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,4 +1,4 @@
|
||||||
/target
|
/target
|
||||||
uberbot_*.toml
|
uberbot_*.toml
|
||||||
uberbot.toml
|
uberbot.toml
|
||||||
Cargo.lock
|
/Cargo.lock
|
||||||
|
|
1539
Cargo.lock
generated
1539
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -1 +1,35 @@
|
||||||
// TODO: port leek @karx
|
use arrayvec::ArrayString;
|
||||||
|
|
||||||
|
pub fn mock(target: &str) -> ArrayString<512> {
|
||||||
|
let mut builder = ArrayString::<512>::new();
|
||||||
|
|
||||||
|
for char in target.chars() {
|
||||||
|
if rand::random() {
|
||||||
|
builder.push(char.to_ascii_uppercase());
|
||||||
|
} else {
|
||||||
|
builder.push(char.to_ascii_lowercase());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
builder
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn leetify(target: &str) -> ArrayString<512> {
|
||||||
|
let mut builder = ArrayString::<512>::new();
|
||||||
|
|
||||||
|
for char in target.chars() {
|
||||||
|
builder.push(match char {
|
||||||
|
'a' => '4',
|
||||||
|
'e' => '3',
|
||||||
|
'i' => '1',
|
||||||
|
'o' => '0',
|
||||||
|
'g' => '6',
|
||||||
|
's' => '5',
|
||||||
|
't' => '7',
|
||||||
|
'b' => '8',
|
||||||
|
_ => char,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
builder
|
||||||
|
}
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
|
pub mod leek;
|
||||||
pub mod title;
|
pub mod title;
|
||||||
pub mod weeb;
|
pub mod weeb;
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
38
src/main.rs
38
src/main.rs
|
@ -165,6 +165,44 @@ async fn handle_privmsg(
|
||||||
.unwrap_or("Invalid category. Valid categories: https://waifu.pics/docs");
|
.unwrap_or("Invalid category. Valid categories: https://waifu.pics/docs");
|
||||||
state.client.privmsg(&channel, response).await?;
|
state.client.privmsg(&channel, response).await?;
|
||||||
}
|
}
|
||||||
|
"mock" => {
|
||||||
|
let user = match remainder {
|
||||||
|
Some(u) => match u {
|
||||||
|
"" => &nick,
|
||||||
|
_ => u,
|
||||||
|
},
|
||||||
|
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?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"leet" => {
|
||||||
|
let user = match remainder {
|
||||||
|
Some(u) => match u {
|
||||||
|
"" => &nick,
|
||||||
|
_ => u,
|
||||||
|
},
|
||||||
|
None => &nick,
|
||||||
|
}
|
||||||
|
.trim();
|
||||||
|
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, "Unknown command").await?;
|
state.client.privmsg(&channel, "Unknown command").await?;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue