diff --git a/Cargo.lock b/Cargo.lock index 16ef6ca..59abf2a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -277,6 +277,7 @@ name = "echbot" version = "0.1.0" dependencies = [ "poise", + "rand", "tokio", ] diff --git a/Cargo.toml b/Cargo.toml index 5128d49..a2dcf56 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,3 +8,4 @@ edition = "2021" [dependencies] poise = "0.5.2" tokio = { version = "1.21.2", features = ["macros", "rt-multi-thread"] } +rand = "0.8.5" diff --git a/src/main.rs b/src/main.rs index 18e2d27..1886728 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,9 @@ use poise::serenity_prelude as serenity; +use rand::seq::IteratorRandom; +use std::{ + fs::File, + io::{BufRead, BufReader} +}; struct Data {} @@ -10,8 +15,12 @@ type Context<'a> = poise::Context<'a, Data, Error>; async fn slur( ctx: Context<'_>, ) -> Result<(), Error> { - let response = "If you don't like my content or the way I act, don't watch me."; - ctx.say(response).await?; + let file = File::open("quotes.txt").unwrap_or_else(|_e| panic!("Quote file missing.")); + let file = BufReader::new(file); + let quotes = file.lines().map(|res| res.expect("Failed to read line.")); + let quote = quotes.choose(&mut rand::thread_rng()).expect("No lines in file."); + + ctx.say(quote).await?; Ok(()) } @@ -19,7 +28,7 @@ async fn slur( async fn main() { let framework = poise::Framework::builder() .options(poise::FrameworkOptions { - commands: vec![slur()], // Intellij doesn't like this, but it's fine. + commands: vec![slur()], // IntelliJ doesn't like this, but it's fine. ..Default::default() }) .token(std::env::var("DISCORD_TOKEN").expect("missing DISCORD_TOKEN"))