74 lines
2.2 KiB
Rust
74 lines
2.2 KiB
Rust
use crate::discord::Context;
|
|
use crate::error::Error;
|
|
use crate::models::improvements::{ImprovementType, Improvements};
|
|
use crate::user::User;
|
|
use poise::serenity_prelude::MessageBuilder;
|
|
use strum::IntoEnumIterator;
|
|
use thousands::Separable;
|
|
|
|
/// List out all the improvements available for the bot
|
|
#[poise::command(prefix_command, guild_only, category = "Improvements")]
|
|
pub async fn improvements(ctx: Context<'_>) -> Result<(), Error> {
|
|
let mut msg_builder = MessageBuilder::new();
|
|
|
|
msg_builder.push_line("# Fren Bot Improvements");
|
|
msg_builder.push_line("Anything can be improved with enough Fren Coins!");
|
|
msg_builder.push_line("");
|
|
|
|
for improvement_type in ImprovementType::iter() {
|
|
msg_builder.push("* ");
|
|
if let Some(improvement) = Improvements::get_improvement(&ctx.data().db, improvement_type)?
|
|
{
|
|
if improvement_type.has_levels() {
|
|
msg_builder.push(format!(" (✅ Level={}) ", improvement.level));
|
|
} else {
|
|
msg_builder.push(" (✅) ");
|
|
}
|
|
} else {
|
|
msg_builder.push(format!(
|
|
"({} FC) ",
|
|
improvement_type.price().separate_with_commas()
|
|
));
|
|
}
|
|
|
|
msg_builder.push_line(format!(
|
|
"**{}**: {}",
|
|
improvement_type.name(),
|
|
improvement_type.description()
|
|
));
|
|
}
|
|
|
|
ctx.reply(msg_builder.build()).await?;
|
|
|
|
Ok(())
|
|
}
|
|
|
|
/// Buy an improvement for the bot!
|
|
#[poise::command(prefix_command, guild_only, category = "Improvements")]
|
|
pub async fn buy_improvement(
|
|
ctx: Context<'_>,
|
|
#[description = "Improvement to buy"]
|
|
#[rest]
|
|
improvement_type: ImprovementType,
|
|
) -> Result<(), Error> {
|
|
if Improvements::get_improvement(&ctx.data().db, improvement_type)?.is_some()
|
|
&& !improvement_type.has_levels()
|
|
{
|
|
ctx.reply("Sorry, that improvement has already been purchased.")
|
|
.await?;
|
|
return Ok(());
|
|
}
|
|
|
|
User::try_take_funds(
|
|
&ctx.data().db,
|
|
ctx.author().id,
|
|
improvement_type.price() as u32,
|
|
)?;
|
|
|
|
Improvements::increment_improvement(&ctx.data().db, improvement_type)?;
|
|
|
|
ctx.reply(improvement_type.post_buy_description()).await?;
|
|
|
|
Ok(())
|
|
}
|