summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock214
-rw-r--r--Cargo.toml1
-rw-r--r--src/commands/bottom_decode.rs35
-rw-r--r--src/commands/bottom_encode.rs35
-rw-r--r--src/commands/mod.rs2
-rw-r--r--src/main.rs4
-rw-r--r--src/utils.rs22
7 files changed, 304 insertions, 9 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 24f80c4..857545b 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -18,6 +18,21 @@ dependencies = [
]
[[package]]
+name = "ansi_term"
+version = "0.12.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
+dependencies = [
+ "winapi",
+]
+
+[[package]]
+name = "anyhow"
+version = "1.0.70"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7de8ce5e0f9f8d88245311066a578d72b7af3e7088f32783804676302df237e4"
+
+[[package]]
name = "async-trait"
version = "0.1.68"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -45,6 +60,17 @@ dependencies = [
]
[[package]]
+name = "atty"
+version = "0.2.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
+dependencies = [
+ "hermit-abi 0.1.19",
+ "libc",
+ "winapi",
+]
+
+[[package]]
name = "autocfg"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -78,6 +104,18 @@ dependencies = [
]
[[package]]
+name = "bottomify"
+version = "1.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6836f736e3f74b97b1e816f2ab9e1464a24f2fb114151a4c5ee3dce6ce413768"
+dependencies = [
+ "anyhow",
+ "clap",
+ "phf",
+ "phf_codegen",
+]
+
+[[package]]
name = "bumpalo"
version = "3.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -121,6 +159,21 @@ dependencies = [
]
[[package]]
+name = "clap"
+version = "2.34.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c"
+dependencies = [
+ "ansi_term",
+ "atty",
+ "bitflags",
+ "strsim",
+ "textwrap",
+ "unicode-width",
+ "vec_map",
+]
+
+[[package]]
name = "codespan-reporting"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -366,13 +419,24 @@ dependencies = [
[[package]]
name = "getrandom"
+version = "0.1.16"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce"
+dependencies = [
+ "cfg-if",
+ "libc",
+ "wasi 0.9.0+wasi-snapshot-preview1",
+]
+
+[[package]]
+name = "getrandom"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31"
dependencies = [
"cfg-if",
"libc",
- "wasi",
+ "wasi 0.11.0+wasi-snapshot-preview1",
]
[[package]]
@@ -402,6 +466,15 @@ checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
[[package]]
name = "hermit-abi"
+version = "0.1.19"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
+dependencies = [
+ "libc",
+]
+
+[[package]]
+name = "hermit-abi"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7"
@@ -643,7 +716,7 @@ checksum = "5b9d9a46eff5b4ff64b45a9e316a6d1e0bc719ef429cbec4dc630684212bfdf9"
dependencies = [
"libc",
"log",
- "wasi",
+ "wasi 0.11.0+wasi-snapshot-preview1",
"windows-sys",
]
@@ -672,7 +745,7 @@ version = "1.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b"
dependencies = [
- "hermit-abi",
+ "hermit-abi 0.2.6",
"libc",
]
@@ -721,6 +794,44 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e"
[[package]]
+name = "phf"
+version = "0.8.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3dfb61232e34fcb633f43d12c58f83c1df82962dcdfa565a4e866ffc17dafe12"
+dependencies = [
+ "phf_shared",
+]
+
+[[package]]
+name = "phf_codegen"
+version = "0.8.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cbffee61585b0411840d3ece935cce9cb6321f01c45477d30066498cd5e1a815"
+dependencies = [
+ "phf_generator",
+ "phf_shared",
+]
+
+[[package]]
+name = "phf_generator"
+version = "0.8.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "17367f0cc86f2d25802b2c26ee58a7b23faeccf78a396094c13dced0d0182526"
+dependencies = [
+ "phf_shared",
+ "rand 0.7.3",
+]
+
+[[package]]
+name = "phf_shared"
+version = "0.8.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c00cf8b9eafe68dde5e9eaa2cef8ee84a9336a47d566ec55ca16589633b65af7"
+dependencies = [
+ "siphasher",
+]
+
+[[package]]
name = "pin-project-lite"
version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -758,13 +869,37 @@ dependencies = [
[[package]]
name = "rand"
+version = "0.7.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03"
+dependencies = [
+ "getrandom 0.1.16",
+ "libc",
+ "rand_chacha 0.2.2",
+ "rand_core 0.5.1",
+ "rand_hc",
+ "rand_pcg",
+]
+
+[[package]]
+name = "rand"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
- "rand_chacha",
- "rand_core",
+ "rand_chacha 0.3.1",
+ "rand_core 0.6.4",
+]
+
+[[package]]
+name = "rand_chacha"
+version = "0.2.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402"
+dependencies = [
+ "ppv-lite86",
+ "rand_core 0.5.1",
]
[[package]]
@@ -774,7 +909,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
- "rand_core",
+ "rand_core 0.6.4",
+]
+
+[[package]]
+name = "rand_core"
+version = "0.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
+dependencies = [
+ "getrandom 0.1.16",
]
[[package]]
@@ -783,7 +927,25 @@ version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
dependencies = [
- "getrandom",
+ "getrandom 0.2.8",
+]
+
+[[package]]
+name = "rand_hc"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
+dependencies = [
+ "rand_core 0.5.1",
+]
+
+[[package]]
+name = "rand_pcg"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "16abd0c1b639e9eb4d7c50c0b8100b0d0f849be2349829c740fe8e6eb4816429"
+dependencies = [
+ "rand_core 0.5.1",
]
[[package]]
@@ -1001,6 +1163,12 @@ dependencies = [
]
[[package]]
+name = "siphasher"
+version = "0.3.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de"
+
+[[package]]
name = "slab"
version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1038,6 +1206,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]]
+name = "strsim"
+version = "0.8.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
+
+[[package]]
name = "syn"
version = "1.0.109"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1063,8 +1237,9 @@ dependencies = [
name = "teawiebot"
version = "0.1.0"
dependencies = [
+ "bottomify",
"include_dir",
- "rand",
+ "rand 0.8.5",
"reqwest",
"serde",
"serenity",
@@ -1081,6 +1256,15 @@ dependencies = [
]
[[package]]
+name = "textwrap"
+version = "0.11.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
+dependencies = [
+ "unicode-width",
+]
+
+[[package]]
name = "thiserror"
version = "1.0.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1252,7 +1436,7 @@ dependencies = [
"http",
"httparse",
"log",
- "rand",
+ "rand 0.8.5",
"rustls",
"sha-1",
"thiserror",
@@ -1340,6 +1524,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4bf03e0ca70d626ecc4ba6b0763b934b6f2976e8c744088bb3c1d646fbb1ad0"
[[package]]
+name = "vec_map"
+version = "0.8.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
+
+[[package]]
name = "version_check"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1357,6 +1547,12 @@ dependencies = [
[[package]]
name = "wasi"
+version = "0.9.0+wasi-snapshot-preview1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
+
+[[package]]
+name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
diff --git a/Cargo.toml b/Cargo.toml
index 7b081c3..bb62414 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -6,6 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
+bottomify = "1.2.0"
include_dir = "0.7.3"
rand = "0.8.5"
reqwest = { version = "0.11.16", default-features = false, features = ["rustls-tls", "json"] }
diff --git a/src/commands/bottom_decode.rs b/src/commands/bottom_decode.rs
new file mode 100644
index 0000000..fb91756
--- /dev/null
+++ b/src/commands/bottom_decode.rs
@@ -0,0 +1,35 @@
+use crate::utils;
+use serenity::builder::CreateApplicationCommand;
+use serenity::model::prelude::command::CommandOptionType;
+use serenity::model::prelude::interaction::application_command::{
+ CommandDataOption, CommandDataOptionValue,
+};
+
+pub async fn run(options: &[CommandDataOption]) -> String {
+ let err_msg = "expected a copyasta";
+ let option = options
+ .get(0)
+ .expect(err_msg)
+ .resolved
+ .as_ref()
+ .expect(err_msg);
+
+ if let CommandDataOptionValue::String(msg) = option {
+ return utils::bottom_decode(msg).await;
+ }
+
+ "did you forget to enter a message?".to_string()
+}
+
+pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand {
+ command
+ .name("bottom_decode")
+ .description("teawie will translate something from bottom for you 🥺")
+ .create_option(|option| {
+ option
+ .name("message")
+ .description("what you want teawie to translate")
+ .kind(CommandOptionType::String)
+ .required(true)
+ })
+}
diff --git a/src/commands/bottom_encode.rs b/src/commands/bottom_encode.rs
new file mode 100644
index 0000000..741adc7
--- /dev/null
+++ b/src/commands/bottom_encode.rs
@@ -0,0 +1,35 @@
+use crate::utils;
+use serenity::builder::CreateApplicationCommand;
+use serenity::model::prelude::command::CommandOptionType;
+use serenity::model::prelude::interaction::application_command::{
+ CommandDataOption, CommandDataOptionValue,
+};
+
+pub async fn run(options: &[CommandDataOption]) -> String {
+ let err_msg = "expected a copyasta";
+ let option = options
+ .get(0)
+ .expect(err_msg)
+ .resolved
+ .as_ref()
+ .expect(err_msg);
+
+ if let CommandDataOptionValue::String(msg) = option {
+ return utils::bottom_encode(msg).await;
+ }
+
+ "did you forget to enter a message?".to_string()
+}
+
+pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand {
+ command
+ .name("bottom_encode")
+ .description("teawie will translate something to bottom for you 🥺")
+ .create_option(|option| {
+ option
+ .name("message")
+ .description("what you want teawie to translate")
+ .kind(CommandOptionType::String)
+ .required(true)
+ })
+}
diff --git a/src/commands/mod.rs b/src/commands/mod.rs
index d3ec259..7005ae2 100644
--- a/src/commands/mod.rs
+++ b/src/commands/mod.rs
@@ -1,3 +1,5 @@
pub mod ask;
+pub mod bottom_decode;
+pub mod bottom_encode;
pub mod copypasta;
pub mod random_teawie;
diff --git a/src/main.rs b/src/main.rs
index 89a686c..1d39fa5 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -56,6 +56,8 @@ impl EventHandler for Handler {
println!("Received command interaction: {:#?}", command);
let content = match command.data.name.as_str() {
"ask" => commands::ask::run(&command.data.options).await,
+ "bottom_decode" => commands::bottom_decode::run(&command.data.options).await,
+ "bottom_encode" => commands::bottom_encode::run(&command.data.options).await,
"copypasta" => {
commands::copypasta::run(&command.data.options, command.channel_id, &ctx.http)
.await
@@ -85,6 +87,8 @@ impl EventHandler for Handler {
let commands = GuildId::set_application_commands(&guild_id, &ctx.http, |commands| {
commands
.create_application_command(|command| commands::ask::register(command))
+ .create_application_command(|command| commands::bottom_decode::register(command))
+ .create_application_command(|command| commands::bottom_encode::register(command))
.create_application_command(|command| commands::random_teawie::register(command))
.create_application_command(|command| commands::copypasta::register(command))
})
diff --git a/src/utils.rs b/src/utils.rs
index db5a5c4..4157e3b 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -1,4 +1,5 @@
use crate::consts::*;
+use bottomify::bottom::{decode_string, encode_string};
use include_dir::{include_dir, Dir};
use rand::seq::SliceRandom;
use std::collections::HashMap;
@@ -65,3 +66,24 @@ pub async fn get_copypasta(name: &str) -> Vec<String> {
let err = format!("couldn't find {:?} in files", name);
vec![err]
}
+
+/*
+ * encodes a string into bottom 🥺
+ */
+pub async fn bottom_encode(string: &str) -> String {
+ encode_string(&string)
+}
+
+/*
+ * decodes a bottom string into english 🥸
+ */
+pub async fn bottom_decode(string: &str) -> String {
+ let decoded = decode_string(&string);
+ match decoded {
+ Ok(ret) => ret,
+ Err(why) => {
+ println!("couldn't decode {:?}! ({:?})", string, why);
+ "couldn't decode that! sowwy 🥺".to_string()
+ }
+ }
+}