echbot/src/commands/slur.rs

29 lines
912 B
Rust
Raw Normal View History

2023-01-12 14:18:11 -05:00
use crate::serenity;
2023-01-21 19:49:39 -05:00
use crate::{Context, Error};
2023-01-11 16:31:15 -05:00
use rand::seq::IteratorRandom;
use std::{
fs::File,
io::{BufRead, BufReader},
};
/// Basically a ping command
2023-01-27 14:27:17 -05:00
#[poise::command(slash_command, prefix_command)]
2023-01-31 19:25:10 -05:00
pub async fn slur(ctx: Context<'_>) -> Result<(), Error> {
2023-01-21 19:49:39 -05:00
let file = File::open("quotes.txt").unwrap_or_else(|_e| panic!("Quote file missing.")); // Open the quotes file
2023-01-11 16:31:15 -05:00
let file = BufReader::new(file); // Read the quotes file
2023-01-21 19:49:39 -05:00
let quotes = file.lines().map(|res| res.expect("Failed to read line."));
let quote = quotes
.choose(&mut rand::thread_rng())
2023-01-11 16:31:15 -05:00
.expect("No lines in file."); // Pick a random quote
2023-01-21 19:49:39 -05:00
ctx.send(|f| {
f.embed(|f| {
f.title("DMBrandon Sez:")
.description(format!("\"{}\"", quote))
.color(serenity::Colour::GOLD)
})
})
.await?; // Send embed with team picks
2023-01-11 16:31:15 -05:00
Ok(())
}