163 lines
5.2 KiB
Rust
163 lines
5.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("");
|
|
|
|
let improvements = Improvements::get_improvement_config(&ctx.data().db)?;
|
|
|
|
for improvement_type in ImprovementType::iter() {
|
|
msg_builder.push("* ");
|
|
|
|
if let Some(improvement) = improvements.get_improvement(&improvement_type) {
|
|
if improvement.has_at_least_one_level() {
|
|
if improvement_type.has_levels() {
|
|
msg_builder.push(format!(
|
|
"({}/{} FC Level={}) ",
|
|
improvement.funding_amount.separate_with_commas(),
|
|
improvement_type.price().separate_with_commas(),
|
|
improvement.level
|
|
));
|
|
} else {
|
|
msg_builder.push(" (✅) ");
|
|
}
|
|
} else {
|
|
msg_builder.push(format!(
|
|
"({}/{} FC) ",
|
|
improvement.funding_amount.separate_with_commas(),
|
|
improvement_type.price().separate_with_commas(),
|
|
));
|
|
}
|
|
} else {
|
|
msg_builder.push(format!(
|
|
"(0/{} 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<'_>,
|
|
#[min = 0u32]
|
|
#[description = "Amount to contribute"]
|
|
amount: u32,
|
|
#[description = "Improvement to contribute to"]
|
|
#[rest]
|
|
improvement_type: ImprovementType,
|
|
) -> Result<(), Error> {
|
|
if Improvements::check_is_completed(&ctx.data().db, improvement_type)? {
|
|
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,
|
|
)?;
|
|
|
|
let (has_improved, _) =
|
|
Improvements::contribute_to_improvement(&ctx.data().db, improvement_type, amount as u64)?;
|
|
|
|
if has_improved {
|
|
ctx.reply(improvement_type.post_buy_description()).await?;
|
|
} else {
|
|
ctx.reply(format!(
|
|
"Thank you for contributing to {}",
|
|
improvement_type.name()
|
|
))
|
|
.await?;
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
|
|
/// View Friendship Tower and all its glory!!!
|
|
#[poise::command(prefix_command, guild_only, category = "Improvements")]
|
|
pub async fn friendship_tower(ctx: Context<'_>) -> Result<(), Error> {
|
|
let improvements = Improvements::get_improvement_config(&ctx.data().db)?;
|
|
if let Some(tower) = improvements.get_improvement(&ImprovementType::FriendshipTower) {
|
|
let buffer = 2;
|
|
let pic_height = tower.level as usize + buffer + 1;
|
|
let width = 5;
|
|
let pic_width = width + buffer * 2;
|
|
let tower_level = tower.level as usize + buffer;
|
|
|
|
let mut msg_builder = MessageBuilder::new();
|
|
msg_builder.push_line("BEHOLD ALL ITS GLORY. MY FINEST CREATION, THE THING THAT WILL BRING US ALL SALVATION!!!!");
|
|
msg_builder.push_line("");
|
|
|
|
for row in 0..pic_height {
|
|
let line = if row < buffer {
|
|
"🟦".repeat(pic_width)
|
|
} else if row < tower_level {
|
|
"🟦🟦⬛⬛⬛⬛⬛🟦🟦".to_string()
|
|
} else {
|
|
"🟩".repeat(pic_width)
|
|
};
|
|
|
|
msg_builder.push_line(line);
|
|
}
|
|
|
|
ctx.reply(msg_builder.build()).await?;
|
|
} else {
|
|
ctx.reply("This is where I would put my tower, IF I HAD ONE!!!!")
|
|
.await?;
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
|
|
/// See how big Jotchua's college fund is!
|
|
#[poise::command(prefix_command, guild_only, category = "Improvements")]
|
|
pub async fn jotchua_college_fund(ctx: Context<'_>) -> Result<(), Error> {
|
|
let improvements = Improvements::get_improvement_config(&ctx.data().db)?;
|
|
let funds_level =
|
|
if let Some(fund) = improvements.get_improvement(&ImprovementType::JotchuaCollegeFund) {
|
|
fund.level
|
|
} else {
|
|
0
|
|
};
|
|
|
|
let college_savings = funds_level as u64 * ImprovementType::JotchuaCollegeFund.price();
|
|
|
|
let jotch = match college_savings {
|
|
0..30_000 => ":VoidJotch:",
|
|
30_000..120_000 => ":Jotch:",
|
|
120_000.. => ":AscendedJotch:",
|
|
};
|
|
|
|
ctx.reply(format!(
|
|
"{jotch} has {} FC in the bank for his college fund!",
|
|
college_savings
|
|
))
|
|
.await?;
|
|
|
|
Ok(())
|
|
}
|