Added more states

+ clippy + fmt
This commit is contained in:
Joey Hines 2023-07-16 10:13:37 -06:00
parent d25a907ae6
commit 295f2704bc
Signed by: joeyahines
GPG Key ID: 995E531F7A569DDB
3 changed files with 150 additions and 24 deletions

View File

@ -1,16 +1,20 @@
use crate::config::BotConfig;
use crate::models::api_key::Apikey;
use crate::models::lil_fren::{AliveState, LilFren};
use crate::models::lil_fren::{
draw_dancing, draw_frankenstein, draw_gone, draw_magic, draw_mining, draw_resonance_cascade,
draw_sick, draw_sleep, draw_standing, draw_tax_fraud, AliveState, LilFren,
};
use crate::{command, group, GlobalData};
use json::JsonValue;
use serenity::client::Context;
use serenity::framework::standard::{Args, CommandResult};
use serenity::model::channel::{AttachmentType, Message};
use serenity::model::misc::EmojiIdentifier;
use serenity::model::prelude::UserId;
use std::borrow::Cow;
#[group]
#[commands(reload, dump_db, load_db, add_key, debug_buddy)]
#[commands(reload, dump_db, load_db, add_key, debug_buddy, draw_buddy_states)]
pub struct ADMIN;
pub fn is_admin(user_id: &UserId, cfg: &BotConfig) -> bool {
@ -161,3 +165,24 @@ async fn debug_buddy(ctx: &Context, msg: &Message, _args: Args) -> CommandResult
Ok(())
}
#[command]
#[description("Check little buddy stats")]
async fn draw_buddy_states(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
let emoji = args.parse::<EmojiIdentifier>()?;
let emoji = msg.guild_id.unwrap().emoji(&ctx.http, emoji.id).await?;
msg.reply(&ctx.http, draw_standing(&emoji)).await?;
msg.reply(&ctx.http, draw_dancing(&emoji)).await?;
msg.reply(&ctx.http, draw_frankenstein(&emoji)).await?;
msg.reply(&ctx.http, draw_sick(&emoji)).await?;
msg.reply(&ctx.http, draw_magic(&emoji)).await?;
msg.reply(&ctx.http, draw_resonance_cascade(&emoji)).await?;
msg.reply(&ctx.http, draw_tax_fraud(&emoji)).await?;
msg.reply(&ctx.http, draw_sleep(&emoji)).await?;
msg.reply(&ctx.http, draw_mining(&emoji)).await?;
msg.reply(&ctx.http, draw_gone()).await?;
Ok(())
}

View File

@ -72,6 +72,17 @@ async fn checkup(ctx: &Context, msg: &Message, _args: Args) -> CommandResult {
LilFrenState::Sick => "Oh no! Buddy is sick!",
LilFrenState::Dancing => "Buddy got some moves!",
LilFrenState::Sleep => "Shhh, buddy is asleep",
LilFrenState::Magic => "Wizard Buddy loves casting spells",
LilFrenState::AttemptingToCircumventDeath => {
"Buddy appears to be researching how to be come immortal"
}
LilFrenState::AttemptingToNotCauseAResonanceCascade => {
"Lil buddy is trying to prevent a resonance cascade"
}
LilFrenState::Mining => "Lil buddy found some diamonds!",
LilFrenState::PhasedIntoYourReality => {
"Lil Buddy has phased into your reality, they will be back soon"
}
};
msg.reply(&ctx.http, state_msg).await?;
@ -159,10 +170,13 @@ async fn give_water(ctx: &Context, msg: &Message, _args: Args) -> CommandResult
msg.reply(&ctx.http, "Lil buddy be drinking!").await?;
global_data.db.insert(lil_fren)?;
msg.reply(
&ctx.http,
lil_fren::draw_feed(&lil_fren_emoji, ":cup_with_straw:"),
)
let drink = if thread_rng().gen_bool(0.20) {
":beer:"
} else {
":cup_with_straw:"
};
msg.reply(&ctx.http, lil_fren::draw_feed(&lil_fren_emoji, drink))
.await?;
} else {
msg.reply(&ctx.http, "You may want to check on your buddy...")

View File

@ -2,8 +2,7 @@ use crate::config::GlobalData;
use crate::error::Error;
use j_db::database::Database;
use j_db::model::JdbModel;
use rand::distributions::Standard;
use rand::prelude::Distribution;
use rand::distributions::{Distribution, Standard};
use rand::{thread_rng, Rng};
use serde::{Deserialize, Serialize};
use serenity::model::guild::Emoji;
@ -40,15 +39,15 @@ pub fn draw_dancing(emoji: &Emoji) -> String {
msg.build()
}
pub fn draw_tax_fraud(emoji: &Emoji) -> String {
pub fn draw_frankenstein(emoji: &Emoji) -> String {
let mut msg = MessageBuilder::new();
msg.push_line(":blue_square::blue_square::blue_square::blue_square::blue_square:");
msg.push_line(":blue_square::blue_square::blue_square::blue_square::blue_square:");
msg.push_line(":blue_square::blue_square::blue_square::blue_square::blue_square:");
msg.push(":blue_square::page_with_curl:");
msg.push(":blue_square::alembic:");
msg.emoji(emoji);
msg.push_line(":blue_square::blue_square:");
msg.push_line(":microscope::test_tube:");
msg.push_line(":green_square::green_square::green_square::green_square::green_square:");
msg.build()
@ -68,6 +67,48 @@ pub fn draw_sick(emoji: &Emoji) -> String {
msg.build()
}
pub fn draw_magic(emoji: &Emoji) -> String {
let mut msg = MessageBuilder::new();
msg.push_line(":blue_square::blue_square::blue_square::blue_square::blue_square:");
msg.push_line(":blue_square::blue_square::blue_square::blue_square::blue_square:");
msg.push_line(":blue_square::blue_square::blue_square::blue_square::blue_square:");
msg.push(":blue_square::tophat:");
msg.emoji(emoji);
msg.push_line(":magic_wand::rabbit2:");
msg.push_line(":green_square::green_square::green_square::green_square::green_square:");
msg.build()
}
pub fn draw_resonance_cascade(emoji: &Emoji) -> String {
let mut msg = MessageBuilder::new();
msg.push_line(":blue_square::blue_square::orange_square::blue_square::blue_square:");
msg.push_line(":yellow_circle::zap::black_large_square::zap::yellow_circle:");
msg.push_line(":blue_square::blue_square::zap::blue_square::blue_square:");
msg.push(":blue_square::gun:");
msg.emoji(emoji);
msg.push_line(":gem::blue_square:");
msg.push_line(":green_square::green_square::green_square::green_square::green_square:");
msg.build()
}
pub fn draw_tax_fraud(emoji: &Emoji) -> String {
let mut msg = MessageBuilder::new();
msg.push_line(":blue_square::blue_square::blue_square::blue_square::blue_square:");
msg.push_line(":blue_square::blue_square::blue_square::blue_square::blue_square:");
msg.push_line(":blue_square::blue_square::blue_square::blue_square::blue_square:");
msg.push(":blue_square::page_with_curl:");
msg.emoji(emoji);
msg.push_line(":blue_square::blue_square:");
msg.push_line(":green_square::green_square::green_square::green_square::green_square:");
msg.build()
}
pub fn draw_sleep(emoji: &Emoji) -> String {
let mut msg = MessageBuilder::new();
@ -82,6 +123,32 @@ pub fn draw_sleep(emoji: &Emoji) -> String {
msg.build()
}
pub fn draw_mining(emoji: &Emoji) -> String {
let mut msg = MessageBuilder::new();
msg.push_line(":black_medium_square::black_medium_square::black_medium_square::black_medium_square::black_medium_square:");
msg.push_line(":black_medium_square::black_medium_square::black_medium_square::black_medium_square::black_medium_square:");
msg.push_line(":black_medium_square::black_medium_square::black_medium_square::black_medium_square::black_medium_square:");
msg.push(":black_medium_square::pick:");
msg.emoji(emoji);
msg.push_line(":gem::black_medium_square:");
msg.push_line(":brown_square::brown_square::brown_square::brown_square::brown_square:");
msg.build()
}
pub fn draw_gone() -> String {
let mut msg = MessageBuilder::new();
msg.push_line(":blue_square::blue_square::blue_square::blue_square::blue_square:");
msg.push_line(":blue_square::blue_square::blue_square::blue_square::blue_square:");
msg.push_line(":blue_square::blue_square::blue_square::blue_square::blue_square:");
msg.push_line(":blue_square::blue_square::blue_square::blue_square::blue_square:");
msg.push_line(":green_square::green_square::green_square::green_square::green_square:");
msg.build()
}
pub fn draw_dead() -> String {
let mut msg = MessageBuilder::new();
@ -116,6 +183,28 @@ pub enum LilFrenState {
Sick,
Dancing,
Sleep,
Magic,
AttemptingToCircumventDeath,
AttemptingToNotCauseAResonanceCascade,
Mining,
PhasedIntoYourReality,
}
impl Distribution<LilFrenState> for Standard {
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> LilFrenState {
match rng.gen_range(0..10) {
0 => LilFrenState::Standing,
1 => LilFrenState::TaxFraud,
2 => LilFrenState::Sick,
3 => LilFrenState::Dancing,
4 => LilFrenState::Sleep,
5 => LilFrenState::Magic,
6 => LilFrenState::AttemptingToCircumventDeath,
7 => LilFrenState::AttemptingToNotCauseAResonanceCascade,
8 => LilFrenState::Mining,
_ => LilFrenState::PhasedIntoYourReality,
}
}
}
#[derive(Debug, Clone, PartialOrd, PartialEq)]
@ -126,18 +215,6 @@ pub enum AliveState {
DiedOfThirst,
}
impl Distribution<LilFrenState> for Standard {
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> LilFrenState {
match rng.gen_range(0..100) {
0..=30 => LilFrenState::Standing,
31..=40 => LilFrenState::TaxFraud,
41..=50 => LilFrenState::Sick,
51..=70 => LilFrenState::Dancing,
_ => LilFrenState::Sleep,
}
}
}
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct LilFren {
id: Option<u64>,
@ -207,6 +284,11 @@ impl LilFren {
LilFrenState::Sick => (-0.005, -0.005, -0.001),
LilFrenState::Dancing => (-0.005, -0.008, 0.01),
LilFrenState::Sleep => (-0.001, -0.002, 0.00),
LilFrenState::Magic => (-0.002, -0.002, 0.001),
LilFrenState::AttemptingToCircumventDeath => (-0.002, -0.002, 0.001),
LilFrenState::AttemptingToNotCauseAResonanceCascade => (-0.004, -0.004, 0.004),
LilFrenState::Mining => (-0.006, -0.006, 0.001),
LilFrenState::PhasedIntoYourReality => (0.0, 0.0, 0.0),
};
lil_fren.hunger = (lil_fren.hunger + hunger_diff * self.metabolism).clamp(-1.0, 1.0);
@ -244,6 +326,11 @@ impl LilFren {
LilFrenState::Sick => draw_sick(emoji),
LilFrenState::Dancing => draw_dancing(emoji),
LilFrenState::Sleep => draw_sleep(emoji),
LilFrenState::Magic => draw_magic(emoji),
LilFrenState::AttemptingToCircumventDeath => draw_frankenstein(emoji),
LilFrenState::AttemptingToNotCauseAResonanceCascade => draw_resonance_cascade(emoji),
LilFrenState::Mining => draw_mining(emoji),
LilFrenState::PhasedIntoYourReality => draw_gone(),
}
}