Moved insults and compliments into the db

+ Fmt
This commit is contained in:
2023-01-19 20:19:58 -07:00
parent ac6bd108da
commit f9776218e0
7 changed files with 122 additions and 63 deletions
+13 -13
View File
@@ -1,8 +1,7 @@
use crate::error::Error;
use crate::models::insult_compliment::{RandomResponseTemplate, ResponseType};
use crate::models::random::RandomConfig;
use crate::{command, group, GlobalData, BAD_APPLE};
use rand::prelude::IteratorRandom;
use rand::thread_rng;
use reqwest::Client;
use serde::{Deserialize, Serialize};
use serenity::client::Context;
@@ -170,7 +169,7 @@ pub async fn list_random(ctx: &Context, msg: &Message, args: Args) -> CommandRes
let random = RandomConfig::get_random(&global_data.db, &random_name)?;
let dm_channel = msg.author.id.create_dm_channel(&ctx.http).await?;
let dm_channel = msg.author.id.create_dm_channel(&ctx.http).await?;
if let Some(random) = random {
let mut msg_builder = MessageBuilder::new();
msg_builder.push_line(format!("All possible responses for {}:", random_name));
@@ -187,7 +186,7 @@ pub async fn list_random(ctx: &Context, msg: &Message, args: Args) -> CommandRes
}
if !msg_builder.0.is_empty() {
dm_channel.say(&ctx.http, msg_builder.build()).await?;
dm_channel.say(&ctx.http, msg_builder.build()).await?;
}
} else {
msg.reply(
@@ -264,10 +263,10 @@ 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
let pool = if msg.content.as_str().starts_with("!insult") {
ResponseType::Insult
} else if msg.content.as_str().starts_with("!compliment") {
&global.cfg.compliments
ResponseType::Compliment
} else {
msg.reply(&ctx, "The h*ck did you just say to me??").await?;
return Ok(());
@@ -275,13 +274,14 @@ async fn insult(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
let target = args.rest();
let output = selection
.iter()
.choose(&mut thread_rng())
.unwrap()
.render(target)?;
let output = RandomResponseTemplate::get_random_response(&global.db, pool, target)?;
msg.reply(&ctx.http, output).await?;
if let Some(output) = output {
msg.reply(&ctx.http, output).await?;
} else {
msg.reply(&ctx, format!("No {}s, mr freeman??", msg.content))
.await?;
}
Ok(())
}