mirror of
https://github.com/ethanrusz/echbot.git
synced 2024-11-21 19:57:46 -05:00
Update quotes to read from file
This commit is contained in:
parent
57ec109290
commit
c20d585a63
3 changed files with 14 additions and 3 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -277,6 +277,7 @@ name = "echbot"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"poise",
|
||||
"rand",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
15
src/main.rs
15
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"))
|
||||
|
|
Loading…
Reference in a new issue