add more types of text generator
This commit is contained in:
parent
1ff66780c7
commit
86b02a7533
184
Cargo.lock
generated
184
Cargo.lock
generated
|
@ -185,6 +185,12 @@ version = "0.4.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "134951f4028bdadb9b84baf4232681efbf277da25144b9b0ad65df75946c422b"
|
checksum = "134951f4028bdadb9b84baf4232681efbf277da25144b9b0ad65df75946c422b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "either"
|
||||||
|
version = "1.5.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "encoding_rs"
|
name = "encoding_rs"
|
||||||
version = "0.8.23"
|
version = "0.8.23"
|
||||||
|
@ -200,6 +206,12 @@ version = "0.1.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed"
|
checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fixedbitset"
|
||||||
|
version = "0.1.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "86d4de0081402f5e88cdac65c8dcdcc73118c1a7a465e2a05f0da05843a8ea33"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "flate2"
|
name = "flate2"
|
||||||
version = "1.0.14"
|
version = "1.0.14"
|
||||||
|
@ -218,6 +230,12 @@ version = "1.0.7"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
|
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fuchsia-cprng"
|
||||||
|
version = "0.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fuchsia-zircon"
|
name = "fuchsia-zircon"
|
||||||
version = "0.3.3"
|
version = "0.3.3"
|
||||||
|
@ -342,6 +360,18 @@ dependencies = [
|
||||||
"winapi 0.3.8",
|
"winapi 0.3.8",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "generator-bot"
|
||||||
|
version = "0.2.0"
|
||||||
|
dependencies = [
|
||||||
|
"markov",
|
||||||
|
"purrchance",
|
||||||
|
"serde",
|
||||||
|
"serenity",
|
||||||
|
"tokio",
|
||||||
|
"toml",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "generic-array"
|
name = "generic-array"
|
||||||
version = "0.12.3"
|
version = "0.12.3"
|
||||||
|
@ -351,6 +381,15 @@ dependencies = [
|
||||||
"typenum",
|
"typenum",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "getopts"
|
||||||
|
version = "0.2.21"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5"
|
||||||
|
dependencies = [
|
||||||
|
"unicode-width",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "getrandom"
|
name = "getrandom"
|
||||||
version = "0.1.14"
|
version = "0.1.14"
|
||||||
|
@ -362,17 +401,6 @@ dependencies = [
|
||||||
"wasi",
|
"wasi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "grammar-bot"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"purrchance",
|
|
||||||
"serde",
|
|
||||||
"serenity",
|
|
||||||
"tokio",
|
|
||||||
"toml",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "h2"
|
name = "h2"
|
||||||
version = "0.2.5"
|
version = "0.2.5"
|
||||||
|
@ -497,6 +525,15 @@ dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "itertools"
|
||||||
|
version = "0.7.11"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0d47946d458e94a1b7bcabbf6521ea7c037062c81f534615abcad76e84d4970d"
|
||||||
|
dependencies = [
|
||||||
|
"either",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "itoa"
|
name = "itoa"
|
||||||
version = "0.4.6"
|
version = "0.4.6"
|
||||||
|
@ -547,6 +584,12 @@ version = "0.2.71"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9457b06509d27052635f90d6466700c65095fdf75409b3fbdd903e988b886f49"
|
checksum = "9457b06509d27052635f90d6466700c65095fdf75409b3fbdd903e988b886f49"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "linked-hash-map"
|
||||||
|
version = "0.5.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8dd5a6d5999d9907cda8ed67bbd137d3af8085216c2ac62de5be860bd41f304a"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "log"
|
name = "log"
|
||||||
version = "0.4.8"
|
version = "0.4.8"
|
||||||
|
@ -567,6 +610,21 @@ dependencies = [
|
||||||
"scoped-tls",
|
"scoped-tls",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "markov"
|
||||||
|
version = "1.0.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3eb8fec2128b3f71ba0fcc136f18b1f20568eb18aa3a08e80b5d65c9fbf33d08"
|
||||||
|
dependencies = [
|
||||||
|
"getopts",
|
||||||
|
"itertools",
|
||||||
|
"petgraph",
|
||||||
|
"rand 0.3.23",
|
||||||
|
"serde",
|
||||||
|
"serde_derive",
|
||||||
|
"serde_yaml",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "matches"
|
name = "matches"
|
||||||
version = "0.1.8"
|
version = "0.1.8"
|
||||||
|
@ -721,12 +779,28 @@ version = "0.2.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c"
|
checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ordermap"
|
||||||
|
version = "0.3.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a86ed3f5f244b372d6b1a00b72ef7f8876d0bc6a78a4c9985c53614041512063"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "percent-encoding"
|
name = "percent-encoding"
|
||||||
version = "2.1.0"
|
version = "2.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e"
|
checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "petgraph"
|
||||||
|
version = "0.4.13"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9c3659d1ee90221741f65dd128d9998311b0e40c5d3c23a62445938214abce4f"
|
||||||
|
dependencies = [
|
||||||
|
"fixedbitset",
|
||||||
|
"ordermap",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pin-project"
|
name = "pin-project"
|
||||||
version = "0.4.22"
|
version = "0.4.22"
|
||||||
|
@ -788,12 +862,12 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "purrchance"
|
name = "purrchance"
|
||||||
version = "0.4.0"
|
version = "0.4.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "865ca962cfe1c073586b84b6b5cfd8247ea95e74273907b184b2354d7a3de31b"
|
checksum = "1b314e5ee146272547b6f106f36aa7ff3c1756f7858e5cd91488b527cd48888b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"nom",
|
"nom",
|
||||||
"rand",
|
"rand 0.7.3",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -805,6 +879,29 @@ dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand"
|
||||||
|
version = "0.3.23"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "64ac302d8f83c0c1974bf758f6b041c6c8ada916fbb44a609158ca8b064cc76c"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"rand 0.4.6",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand"
|
||||||
|
version = "0.4.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293"
|
||||||
|
dependencies = [
|
||||||
|
"fuchsia-cprng",
|
||||||
|
"libc",
|
||||||
|
"rand_core 0.3.1",
|
||||||
|
"rdrand",
|
||||||
|
"winapi 0.3.8",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rand"
|
name = "rand"
|
||||||
version = "0.7.3"
|
version = "0.7.3"
|
||||||
|
@ -814,7 +911,7 @@ dependencies = [
|
||||||
"getrandom",
|
"getrandom",
|
||||||
"libc",
|
"libc",
|
||||||
"rand_chacha",
|
"rand_chacha",
|
||||||
"rand_core",
|
"rand_core 0.5.1",
|
||||||
"rand_hc",
|
"rand_hc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -825,9 +922,24 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402"
|
checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ppv-lite86",
|
"ppv-lite86",
|
||||||
"rand_core",
|
"rand_core 0.5.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand_core"
|
||||||
|
version = "0.3.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b"
|
||||||
|
dependencies = [
|
||||||
|
"rand_core 0.4.2",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand_core"
|
||||||
|
version = "0.4.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rand_core"
|
name = "rand_core"
|
||||||
version = "0.5.1"
|
version = "0.5.1"
|
||||||
|
@ -843,7 +955,16 @@ version = "0.2.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
|
checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"rand_core",
|
"rand_core 0.5.1",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rdrand"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2"
|
||||||
|
dependencies = [
|
||||||
|
"rand_core 0.3.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1018,6 +1139,18 @@ dependencies = [
|
||||||
"url",
|
"url",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_yaml"
|
||||||
|
version = "0.7.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ef8099d3df28273c99a1728190c7a9f19d444c941044f64adf986bee7ec53051"
|
||||||
|
dependencies = [
|
||||||
|
"dtoa",
|
||||||
|
"linked-hash-map",
|
||||||
|
"serde",
|
||||||
|
"yaml-rust",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serenity"
|
name = "serenity"
|
||||||
version = "0.8.6"
|
version = "0.8.6"
|
||||||
|
@ -1216,7 +1349,7 @@ dependencies = [
|
||||||
"httparse",
|
"httparse",
|
||||||
"input_buffer",
|
"input_buffer",
|
||||||
"log",
|
"log",
|
||||||
"rand",
|
"rand 0.7.3",
|
||||||
"sha-1",
|
"sha-1",
|
||||||
"url",
|
"url",
|
||||||
"utf-8",
|
"utf-8",
|
||||||
|
@ -1255,6 +1388,12 @@ dependencies = [
|
||||||
"tinyvec",
|
"tinyvec",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-width"
|
||||||
|
version = "0.1.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "caaa9d531767d1ff2150b9332433f32a24622147e5ebb1f26409d5da67afd479"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-xid"
|
name = "unicode-xid"
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
|
@ -1464,3 +1603,12 @@ dependencies = [
|
||||||
"winapi 0.2.8",
|
"winapi 0.2.8",
|
||||||
"winapi-build",
|
"winapi-build",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "yaml-rust"
|
||||||
|
version = "0.4.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "39f0c922f1a334134dc2f7a8b67dc5d25f0735263feec974345ff706bcf20b0d"
|
||||||
|
dependencies = [
|
||||||
|
"linked-hash-map",
|
||||||
|
]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "grammar-bot"
|
name = "generator-bot"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
authors = ["xenofem <xenofem@xeno.science>"]
|
authors = ["xenofem <xenofem@xeno.science>"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
@ -8,9 +8,11 @@ edition = "2018"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
markov = "1.0.3"
|
||||||
purrchance = "0.4.1"
|
purrchance = "0.4.1"
|
||||||
serde = "1.0.112"
|
serde = "1.0.112"
|
||||||
toml = "0.5.6"
|
toml = "0.5.6"
|
||||||
|
# tracery = "0.1.0"
|
||||||
|
|
||||||
[dependencies.serenity]
|
[dependencies.serenity]
|
||||||
git = "https://github.com/Lakelezz/serenity/"
|
git = "https://github.com/Lakelezz/serenity/"
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
grammar_path = "grammar"
|
|
||||||
grammar_type = "perchance"
|
|
||||||
grammar_symbol = "output"
|
|
||||||
token = "t0k3n"
|
token = "t0k3n"
|
||||||
channel_id = 0000000000000000
|
channel_id = 0000000000000000
|
||||||
interval = 7200
|
interval = 7200
|
||||||
|
|
||||||
|
[generator]
|
||||||
|
type = "perchance"
|
||||||
|
path = "grammar"
|
||||||
|
symbol = "output"
|
||||||
|
|
97
src/main.rs
97
src/main.rs
|
@ -1,10 +1,12 @@
|
||||||
|
extern crate markov;
|
||||||
extern crate purrchance;
|
extern crate purrchance;
|
||||||
extern crate serde;
|
extern crate serde;
|
||||||
extern crate serenity;
|
extern crate serenity;
|
||||||
extern crate tokio;
|
extern crate tokio;
|
||||||
extern crate toml;
|
extern crate toml;
|
||||||
|
// extern crate tracery;
|
||||||
|
|
||||||
use purrchance::{Grammar, Purrchance, Symbol, parser::load_grammar};
|
use purrchance::Purrchance;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serenity::{
|
use serenity::{
|
||||||
async_trait,
|
async_trait,
|
||||||
|
@ -15,32 +17,64 @@ use std::fs::read_to_string;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
|
enum TextGenerator {
|
||||||
|
Perchance { grammar: purrchance::Grammar, symbol: purrchance::Symbol },
|
||||||
|
// Tracery(tracery::Grammar),
|
||||||
|
Markov(markov::Chain<String>),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TextGenerator {
|
||||||
|
fn generate(&self) -> String {
|
||||||
|
match self {
|
||||||
|
TextGenerator::Perchance { grammar, symbol } => symbol.eval(&grammar).unwrap(),
|
||||||
|
// TextGenerator::Tracery(grammar) => grammar.flatten(),
|
||||||
|
TextGenerator::Markov(chain) => chain.generate_str(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
#[serde(rename_all = "lowercase")]
|
#[serde(tag = "type", rename_all = "lowercase")]
|
||||||
enum GrammarType {
|
enum GeneratorSpec {
|
||||||
Perchance,
|
Perchance { path: String, symbol: String },
|
||||||
|
// Tracery { path: String, rule: String },
|
||||||
|
Markov { path: String, order: usize },
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GeneratorSpec {
|
||||||
|
fn load(&self) -> TextGenerator {
|
||||||
|
match self {
|
||||||
|
GeneratorSpec::Perchance { path: p, symbol: s } => {
|
||||||
|
let grammar = purrchance::parser::load_grammar(&read_to_string(p).unwrap()).unwrap();
|
||||||
|
let symbol = purrchance::Symbol::NonTerminal(String::from(s));
|
||||||
|
TextGenerator::Perchance { grammar, symbol }
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
GeneratorSpec::Tracery { path, rule } => {
|
||||||
|
let mut grammar = tracery::from_json(read_to_string(path).unwrap()).unwrap();
|
||||||
|
grammar.default_rule(rule);
|
||||||
|
TextGenerator::Tracery(grammar)
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
GeneratorSpec::Markov { path, order } => {
|
||||||
|
let mut chain = markov::Chain::of_order(*order);
|
||||||
|
for line in read_to_string(path).unwrap().lines() {
|
||||||
|
chain.feed_str(line);
|
||||||
|
}
|
||||||
|
TextGenerator::Markov(chain)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct Config {
|
struct Config {
|
||||||
grammar_path: String,
|
generator: GeneratorSpec,
|
||||||
grammar_type: GrammarType,
|
|
||||||
grammar_symbol: String,
|
|
||||||
token: String,
|
token: String,
|
||||||
channel_id: ChannelId,
|
channel_id: ChannelId,
|
||||||
interval: u64,
|
interval: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct TextGenerator {
|
|
||||||
grammar: Grammar,
|
|
||||||
symbol: Symbol,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TextGenerator {
|
|
||||||
pub fn generate(&self) -> String {
|
|
||||||
self.symbol.eval(&self.grammar).unwrap()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TypeMapKey for TextGenerator {
|
impl TypeMapKey for TextGenerator {
|
||||||
type Value = TextGenerator;
|
type Value = TextGenerator;
|
||||||
|
@ -118,24 +152,19 @@ impl EventHandler for Handler {
|
||||||
async fn main() {
|
async fn main() {
|
||||||
let config: Config = toml::from_str(&read_to_string("config.toml").unwrap()).unwrap();
|
let config: Config = toml::from_str(&read_to_string("config.toml").unwrap()).unwrap();
|
||||||
|
|
||||||
match config.grammar_type {
|
let generator = config.generator.load();
|
||||||
GrammarType::Perchance => {
|
|
||||||
let grammar = load_grammar(&read_to_string(config.grammar_path).unwrap()).unwrap();
|
|
||||||
let symbol = Symbol::NonTerminal(config.grammar_symbol);
|
|
||||||
|
|
||||||
let mut client = Client::new(&config.token)
|
let mut client = Client::new(&config.token)
|
||||||
.event_handler(Handler)
|
.event_handler(Handler)
|
||||||
.await
|
.await
|
||||||
.expect("err creating client");
|
.expect("err creating client");
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut data = client.data.write().await;
|
let mut data = client.data.write().await;
|
||||||
data.insert::<TextGenerator>(TextGenerator { grammar, symbol });
|
data.insert::<TextGenerator>(generator);
|
||||||
data.insert::<Interval>(config.interval);
|
data.insert::<Interval>(config.interval);
|
||||||
data.insert::<ChanId>(config.channel_id);
|
data.insert::<ChanId>(config.channel_id);
|
||||||
data.insert::<LoopStatus>(false);
|
data.insert::<LoopStatus>(false);
|
||||||
}
|
|
||||||
client.start().await.unwrap();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
client.start().await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue