Fixed cringe serenity issue

This commit is contained in:
Joey Hines 2024-01-19 18:00:26 -07:00
parent 67ff69aca0
commit 8cd578b10c
Signed by: joeyahines
GPG Key ID: 995E531F7A569DDB
2 changed files with 55 additions and 17 deletions

View File

@ -3,6 +3,7 @@ use crate::error::Error;
use crate::user::{User, UserError}; use crate::user::{User, UserError};
use crate::{command, group}; use crate::{command, group};
use rand::{thread_rng, Rng}; use rand::{thread_rng, Rng};
use serenity::all::parse_user_mention;
use serenity::client::Context; use serenity::client::Context;
use serenity::framework::standard::{Args, CommandResult}; use serenity::framework::standard::{Args, CommandResult};
use serenity::model::channel::Message; use serenity::model::channel::Message;
@ -20,7 +21,12 @@ async fn balance(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
let mut data = ctx.data.write().await; let mut data = ctx.data.write().await;
let global_data = data.get_mut::<GlobalData>().unwrap(); let global_data = data.get_mut::<GlobalData>().unwrap();
let user = args.parse::<UserId>().unwrap_or(msg.author.id); let user = if args.is_empty() {
msg.author.id
} else {
let mention = args.parse::<String>().unwrap();
parse_user_mention(&mention).unwrap()
};
let wallet = User::get_user(&global_data.db, user)?; let wallet = User::get_user(&global_data.db, user)?;
@ -42,14 +48,18 @@ async fn balance(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
#[description("Gift your frens coins!")] #[description("Gift your frens coins!")]
#[usage("@fren 25")] #[usage("@fren 25")]
async fn gift(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult { async fn gift(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
let target = match args.parse::<UserId>() { let target = args.parse::<String>().unwrap();
Ok(t) => t,
Err(_) => {
msg.reply(&ctx.http, "Sorry I don't know who that is!")
.await?;
let target = match parse_user_mention(&target) {
None => {
msg.reply(
&ctx.http,
"Gonna be real honest with you gamer, no clue who that is",
)
.await?;
return Ok(()); return Ok(());
} }
Some(t) => t,
}; };
args.advance(); args.advance();
@ -67,13 +77,25 @@ async fn gift(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
let global_data = data.get_mut::<GlobalData>().unwrap(); let global_data = data.get_mut::<GlobalData>().unwrap();
if let Err(e) = User::transfer_funds(&global_data.db, msg.author.id, target, amount) { if let Err(e) = User::transfer_funds(&global_data.db, msg.author.id, target, amount) {
if let Error::UserError(UserError::NotEnoughFunds) = e { if let Error::UserError(err) = e {
match err {
UserError::NotEnoughFunds => {
msg.reply( msg.reply(
&ctx.http, &ctx.http,
"Sorry pal, I can't give credit. Come back when you're a bit mmmm richer.", "Sorry pal, I can't give credit. Come back when you're a bit mmmm richer.",
) )
.await?; .await?;
} }
UserError::InvalidTarget => {
msg.reply(
&ctx.http,
"Sorry pal, I can't make a friend up for you. Come back when you got friends.",
)
.await?;
}
_ => {}
}
}
} else { } else {
msg.reply( msg.reply(
&ctx.http, &ctx.http,

View File

@ -141,7 +141,9 @@ async fn blockable_item(
}; };
if target_member.user.id == ctx.cache.current_user().id { if target_member.user.id == ctx.cache.current_user().id {
return Err(CommandError::from("You can not harm me in a way that matters.")); return Err(CommandError::from(
"You can not harm me in a way that matters.",
));
} }
if User::try_use_item(&global_data.db, target, block_item, true).is_ok() { if User::try_use_item(&global_data.db, target, block_item, true).is_ok() {
@ -281,7 +283,7 @@ async fn use_item(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
msg.reply(&ctx.http, "https://media.discordapp.net/attachments/840015650286075945/1127022083919069184/Img_2022_10_21_05_08_12.jpg").await?; msg.reply(&ctx.http, "https://media.discordapp.net/attachments/840015650286075945/1127022083919069184/Img_2022_10_21_05_08_12.jpg").await?;
} }
ItemType::KillGun => { ItemType::KillGun => {
let (outcome, target) = blockable_item( let (outcome, target) = match blockable_item(
ctx, ctx,
global_data, global_data,
msg.guild_id.unwrap(), msg.guild_id.unwrap(),
@ -290,7 +292,14 @@ async fn use_item(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
"kill gun ", "kill gun ",
ItemType::Helmet, ItemType::Helmet,
) )
.await?; .await
{
Ok(ret) => ret,
Err(err) => {
msg.reply(&ctx.http, err.to_string()).await?;
return Ok(());
}
};
if outcome { if outcome {
msg.reply(&ctx.http, format!("You draw your trusty kill gun and shoot one kill bullet. It hits it mark between {}'s eyes, killing them instantly. They are now dead.", target.mention())).await?; msg.reply(&ctx.http, format!("You draw your trusty kill gun and shoot one kill bullet. It hits it mark between {}'s eyes, killing them instantly. They are now dead.", target.mention())).await?;
@ -299,7 +308,7 @@ async fn use_item(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
} }
} }
ItemType::CancelRay => { ItemType::CancelRay => {
let (outcome, target) = blockable_item( let (outcome, target) = match blockable_item(
ctx, ctx,
global_data, global_data,
msg.guild_id.unwrap(), msg.guild_id.unwrap(),
@ -308,7 +317,14 @@ async fn use_item(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
"cancel ray ", "cancel ray ",
ItemType::CancelInsurance, ItemType::CancelInsurance,
) )
.await?; .await
{
Ok(ret) => ret,
Err(err) => {
msg.reply(&ctx.http, err.to_string()).await?;
return Ok(());
}
};
if outcome { if outcome {
msg.reply(&ctx.http, format!("You shoot the cancel ray at {}. As the ray impacts them, you can here their phone buzz. They have been cancelled, you hear the liberal media in the distance.", target.mention())).await?; msg.reply(&ctx.http, format!("You shoot the cancel ray at {}. As the ray impacts them, you can here their phone buzz. They have been cancelled, you hear the liberal media in the distance.", target.mention())).await?;