Added buddy commands and horny license

+ clippy + fmt
This commit is contained in:
2023-07-07 19:47:03 -06:00
parent 2c2634925d
commit d076318e4a
9 changed files with 530 additions and 1 deletions
+35 -1
View File
@@ -1,5 +1,6 @@
use crate::config::BotConfig;
use crate::models::api_key::Apikey;
use crate::models::lil_fren::{AliveState, LilFren};
use crate::{command, group, GlobalData};
use json::JsonValue;
use serenity::client::Context;
@@ -9,7 +10,7 @@ use serenity::model::prelude::UserId;
use std::borrow::Cow;
#[group]
#[commands(reload, dump_db, load_db, add_key)]
#[commands(reload, dump_db, load_db, add_key, debug_buddy)]
pub struct ADMIN;
pub fn is_admin(user_id: &UserId, cfg: &BotConfig) -> bool {
@@ -127,3 +128,36 @@ async fn add_key(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
Ok(())
}
#[command]
#[description("Check little buddy stats")]
async fn debug_buddy(ctx: &Context, msg: &Message, _args: Args) -> CommandResult {
let mut data = ctx.data.write().await;
let global_data = data.get_mut::<GlobalData>().unwrap();
let lil_fren = LilFren::get_lil_fren(&global_data.db)?;
if let Some(lil_fren) = lil_fren {
if lil_fren.is_alive() == AliveState::Alive {
msg.reply(
&ctx.http,
format!(
"Hunger: {} Thirst: {} Entertainment: {} Smarts: {} Metabolism: {} State: {:?}",
lil_fren.hunger,
lil_fren.thirst,
lil_fren.entertainment,
lil_fren.smarts,
lil_fren.metabolism,
lil_fren.state
),
)
.await?;
} else {
msg.reply(&ctx.http, "Lil buddy is dead!").await?;
}
} else {
msg.reply(&ctx.http, "Sorry no little buddy found!").await?;
}
Ok(())
}
+208
View File
@@ -0,0 +1,208 @@
use crate::config::GlobalData;
use crate::models::lil_fren;
use crate::models::lil_fren::{AliveState, LilFren, LilFrenState};
use crate::{command, group};
use rand::prelude::SliceRandom;
use rand::{thread_rng, Rng};
use serenity::client::Context;
use serenity::framework::standard::{Args, CommandResult};
use serenity::model::channel::Message;
use serenity::model::misc::EmojiIdentifier;
use serenity::utils::MessageBuilder;
#[group]
#[commands(adopt, checkup, feed, give_water, play)]
pub struct Buddy;
#[command]
#[description("Adopt a new lil buddy")]
#[only_in(guilds)]
async fn adopt(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
let mut data = ctx.data.write().await;
let global_data = data.get_mut::<GlobalData>().unwrap();
if let Ok(emoji) = args.parse::<EmojiIdentifier>() {
if let Some(lil_fren) = LilFren::get_lil_fren(&global_data.db)? {
if lil_fren.is_alive() == AliveState::Alive {
msg.reply(
&ctx.http,
"Your buddy is still alive, please take care of him :)",
)
.await?;
return Ok(());
}
}
LilFren::create_new_lil_fren(&global_data.db, emoji.id)?;
let guild = msg.guild_id.unwrap();
let emoji = guild.emoji(&ctx.http, emoji.id).await?;
let mut msg_builder = MessageBuilder::new();
msg_builder.push("Congrats on adopting ");
msg_builder.emoji(&emoji);
msg_builder.push("!");
msg.reply(&ctx.http, msg_builder.build()).await?;
} else {
msg.reply(&ctx.http, "Sorry whatever that is not adoptable.")
.await?;
}
Ok(())
}
#[command]
#[only_in(guilds)]
#[description("Checkup on your lil buddy")]
async fn checkup(ctx: &Context, msg: &Message, _args: Args) -> CommandResult {
let mut data = ctx.data.write().await;
let global_data = data.get_mut::<GlobalData>().unwrap();
let lil_fren = LilFren::get_lil_fren(&global_data.db)?;
if let Some(lil_fren) = lil_fren {
let guild = msg.guild_id.unwrap();
let alive_state = lil_fren.is_alive();
if alive_state == AliveState::Alive {
let state_msg = match lil_fren.state {
LilFrenState::Standing => "Little buddy is standing.",
LilFrenState::TaxFraud => "Your buddy is comiting tax fraud",
LilFrenState::Sick => "Oh no! Buddy is sick!",
LilFrenState::Dancing => "Buddy got some moves!",
LilFrenState::Sleep => "Shhh, buddy is asleep",
};
msg.reply(&ctx.http, state_msg).await?;
msg.reply(&ctx.http, lil_fren.draw(ctx, &guild).await)
.await?;
} else {
let resp = match alive_state {
AliveState::Alive => "",
AliveState::DiedOfBoredom => "Your little buddy died of boredom RIP",
AliveState::DiedOfHunger => "Your little buddy died of hunger RIP",
AliveState::DiedOfThirst => "Your little buddy died of thirst",
};
msg.reply(&ctx.http, resp).await?;
}
} else {
msg.reply(
&ctx.http,
"Sorry you have no little buddy right now. Please adopt!",
)
.await?;
}
Ok(())
}
#[command]
#[description("Feed lil buddy")]
async fn feed(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
let mut data = ctx.data.write().await;
let global_data = data.get_mut::<GlobalData>().unwrap();
if let Ok(food_emoji) = args.parse::<String>() {
let lil_fren = LilFren::get_lil_fren(&global_data.db)?;
if let Some(mut lil_fren) = lil_fren {
if lil_fren.is_alive() == AliveState::Alive {
let feed: f32 = thread_rng().gen_range(-0.1..=1.0);
lil_fren.hunger = (lil_fren.hunger + feed).clamp(-1.0, 1.0);
let guild = msg.guild_id.unwrap();
let lil_fren_emoji = guild.emoji(&ctx.http, lil_fren.emoji).await?;
if feed > 0.0 {
msg.reply(&ctx.http, "Lil buddy seemed to like that!")
.await?;
} else {
msg.reply(&ctx.http, "Lil buddy DID not like that!").await?;
}
msg.reply(&ctx.http, lil_fren::draw_feed(&lil_fren_emoji, &food_emoji))
.await?;
global_data.db.insert(lil_fren)?;
} else {
msg.reply(&ctx.http, "You may want to check on your buddy...")
.await?;
}
} else {
msg.reply(&ctx.http, "Sorry no little buddy found!").await?;
}
} else {
msg.reply(&ctx.http, "Please provide something to feed lil buddy")
.await?;
}
Ok(())
}
#[command]
#[description("Give lil buddy some water")]
async fn give_water(ctx: &Context, msg: &Message, _args: Args) -> CommandResult {
let mut data = ctx.data.write().await;
let global_data = data.get_mut::<GlobalData>().unwrap();
let lil_fren = LilFren::get_lil_fren(&global_data.db)?;
if let Some(mut lil_fren) = lil_fren {
if lil_fren.is_alive() == AliveState::Alive {
lil_fren.thirst = (lil_fren.thirst + 0.5).clamp(-1.0, 1.0);
let guild = msg.guild_id.unwrap();
let lil_fren_emoji = guild.emoji(&ctx.http, lil_fren.emoji).await?;
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:"),
)
.await?;
} else {
msg.reply(&ctx.http, "You may want to check on your buddy...")
.await?;
}
} else {
msg.reply(&ctx.http, "Sorry no little buddy found!").await?;
}
Ok(())
}
#[command]
#[description("Play with buddy")]
async fn play(ctx: &Context, msg: &Message, _args: Args) -> CommandResult {
let mut data = ctx.data.write().await;
let global_data = data.get_mut::<GlobalData>().unwrap();
let lil_fren = LilFren::get_lil_fren(&global_data.db)?;
if let Some(mut lil_fren) = lil_fren {
if lil_fren.is_alive() == AliveState::Alive {
lil_fren.entertainment =
(lil_fren.entertainment + thread_rng().gen_range(-0.10..1.0)).clamp(-1.0, 1.0);
let guild = msg.guild_id.unwrap();
let lil_fren_emoji = guild.emoji(&ctx.http, lil_fren.emoji).await?;
global_data.db.insert(lil_fren)?;
let toy = global_data.cfg.toys.choose(&mut thread_rng()).unwrap();
msg.reply(&ctx.http, lil_fren::draw_feed(&lil_fren_emoji, toy))
.await?;
} else {
msg.reply(&ctx.http, "You may want to check on your buddy...")
.await?;
}
} else {
msg.reply(&ctx.http, "Sorry no little buddy found!").await?;
}
Ok(())
}
+9
View File
@@ -6,6 +6,7 @@ pub mod color;
pub mod emoji_race;
pub mod fren_coin;
pub mod joke;
pub mod little_fren;
pub mod motivate;
pub mod shop;
pub mod story;
@@ -17,6 +18,7 @@ use crate::discord::joke::random;
use crate::discord::shop::restock_shop;
use crate::models::birthday::BirthdayEntry;
use crate::models::insult_compliment::{RandomResponseTemplate, ResponseType};
use crate::models::lil_fren::lil_fren_task;
use crate::{help, hook, GlobalData};
use chrono::{Days, TimeZone, Timelike, Utc};
use rand::prelude::IteratorRandom;
@@ -42,6 +44,13 @@ static ERROR_MSG: &str =
#[async_trait]
impl EventHandler for Handler {
async fn cache_ready(&self, ctx: Context, _guilds: Vec<GuildId>) {
let ctx1 = ctx.clone();
tokio::spawn(async move {
loop {
lil_fren_task(&ctx1).await;
}
});
tokio::spawn(async move {
let mut next_check = chrono_tz::America::Chicago
.from_utc_datetime(&Utc::now().naive_utc())
+3
View File
@@ -214,6 +214,9 @@ async fn use_item(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
.await?;
}
}
ItemType::LicenseToBeHorny => {
msg.reply(&ctx.http, "https://media.discordapp.net/attachments/840015650286075945/1127022083919069184/Img_2022_10_21_05_08_12.jpg").await?;
}
}
Ok(())