Added insults and compliments
+ clippy + fmt
This commit is contained in:
parent
65ea879ffa
commit
7c9cb2a81f
@ -2,6 +2,7 @@ use crate::error::Error;
|
|||||||
use crate::error::Error::NoAlbumFound;
|
use crate::error::Error::NoAlbumFound;
|
||||||
use crate::imgur;
|
use crate::imgur;
|
||||||
use crate::imgur::Image;
|
use crate::imgur::Image;
|
||||||
|
use crate::insult_compliment::InsultComplimentTemplate;
|
||||||
use crate::wallet::WalletManager;
|
use crate::wallet::WalletManager;
|
||||||
use config::{Config, File};
|
use config::{Config, File};
|
||||||
use rand::prelude::SliceRandom;
|
use rand::prelude::SliceRandom;
|
||||||
@ -47,6 +48,10 @@ pub struct BotConfig {
|
|||||||
pub randoms: Vec<RandomConfig>,
|
pub randoms: Vec<RandomConfig>,
|
||||||
|
|
||||||
pub wallet_manager: WalletManager,
|
pub wallet_manager: WalletManager,
|
||||||
|
|
||||||
|
pub insults: Vec<InsultComplimentTemplate>,
|
||||||
|
|
||||||
|
pub compliments: Vec<InsultComplimentTemplate>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BotConfig {
|
impl BotConfig {
|
||||||
|
|||||||
@ -12,7 +12,7 @@ use std::collections::HashMap;
|
|||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
#[group]
|
#[group]
|
||||||
#[commands(dad_joke, roll, bad_apple)]
|
#[commands(dad_joke, roll, bad_apple, insult)]
|
||||||
pub struct Joke;
|
pub struct Joke;
|
||||||
|
|
||||||
#[derive(Clone, Serialize, Deserialize)]
|
#[derive(Clone, Serialize, Deserialize)]
|
||||||
@ -165,3 +165,32 @@ async fn bad_apple(ctx: &Context, msg: &Message, _args: Args) -> CommandResult {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[command]
|
||||||
|
#[aliases("compliment")]
|
||||||
|
#[only_in(guilds)]
|
||||||
|
async fn insult(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
|
||||||
|
let data = ctx.data.read().await;
|
||||||
|
let global = data.get::<GlobalData>().unwrap();
|
||||||
|
|
||||||
|
let selection = if msg.content.as_str().starts_with("!insult") {
|
||||||
|
&global.cfg.insults
|
||||||
|
} else if msg.content.as_str().starts_with("!compliment") {
|
||||||
|
&global.cfg.compliments
|
||||||
|
} else {
|
||||||
|
msg.reply(&ctx, "The h*ck did you just say to me??").await?;
|
||||||
|
return Ok(());
|
||||||
|
};
|
||||||
|
|
||||||
|
let target = args.rest();
|
||||||
|
|
||||||
|
let output = selection
|
||||||
|
.iter()
|
||||||
|
.choose(&mut thread_rng())
|
||||||
|
.unwrap()
|
||||||
|
.render(target)?;
|
||||||
|
|
||||||
|
msg.reply(&ctx.http, output).await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|||||||
@ -34,6 +34,12 @@ impl From<serenity::Error> for Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<tera::Error> for Error {
|
||||||
|
fn from(err: tera::Error) -> Self {
|
||||||
|
Self::TeraError(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Display for Error {
|
impl Display for Error {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
|
|||||||
25
src/insult_compliment.rs
Normal file
25
src/insult_compliment.rs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
use crate::error::Error;
|
||||||
|
use rand::seq::SliceRandom;
|
||||||
|
use rand::thread_rng;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::collections::HashMap;
|
||||||
|
use tera::{Context, Tera};
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize, Serialize, Clone, Default)]
|
||||||
|
pub struct InsultComplimentTemplate {
|
||||||
|
pub template: String,
|
||||||
|
pub word_bank: HashMap<String, Vec<String>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl InsultComplimentTemplate {
|
||||||
|
pub fn render(&self, target: &str) -> Result<String, Error> {
|
||||||
|
let mut context = Context::new();
|
||||||
|
context.insert("target", target);
|
||||||
|
|
||||||
|
for (key, words) in &self.word_bank {
|
||||||
|
context.insert(key, &words.choose(&mut thread_rng()).unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(Tera::one_off(&self.template, &context, false)?)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -2,6 +2,7 @@ mod config;
|
|||||||
mod discord;
|
mod discord;
|
||||||
mod error;
|
mod error;
|
||||||
mod imgur;
|
mod imgur;
|
||||||
|
mod insult_compliment;
|
||||||
mod wallet;
|
mod wallet;
|
||||||
|
|
||||||
use crate::config::{Args, BotConfig, Channel, GlobalData};
|
use crate::config::{Args, BotConfig, Channel, GlobalData};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user