diff --git a/src/discord/fren_coin.rs b/src/discord/fren_coin.rs index 36e7cba..e9f6ff9 100644 --- a/src/discord/fren_coin.rs +++ b/src/discord/fren_coin.rs @@ -3,6 +3,7 @@ use crate::error::Error; use crate::user::{User, UserError}; use crate::{command, group}; use rand::{thread_rng, Rng}; +use serenity::all::parse_user_mention; use serenity::client::Context; use serenity::framework::standard::{Args, CommandResult}; 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 global_data = data.get_mut::().unwrap(); - let user = args.parse::().unwrap_or(msg.author.id); + let user = if args.is_empty() { + msg.author.id + } else { + let mention = args.parse::().unwrap(); + parse_user_mention(&mention).unwrap() + }; 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!")] #[usage("@fren 25")] async fn gift(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult { - let target = match args.parse::() { - Ok(t) => t, - Err(_) => { - msg.reply(&ctx.http, "Sorry I don't know who that is!") - .await?; + let target = args.parse::().unwrap(); + 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(()); } + Some(t) => t, }; args.advance(); @@ -67,12 +77,24 @@ async fn gift(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult { let global_data = data.get_mut::().unwrap(); if let Err(e) = User::transfer_funds(&global_data.db, msg.author.id, target, amount) { - if let Error::UserError(UserError::NotEnoughFunds) = e { - msg.reply( - &ctx.http, - "Sorry pal, I can't give credit. Come back when you're a bit mmmm richer.", - ) - .await?; + if let Error::UserError(err) = e { + match err { + UserError::NotEnoughFunds => { + msg.reply( + &ctx.http, + "Sorry pal, I can't give credit. Come back when you're a bit mmmm richer.", + ) + .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 { msg.reply( diff --git a/src/discord/shop.rs b/src/discord/shop.rs index ee21dec..2653209 100644 --- a/src/discord/shop.rs +++ b/src/discord/shop.rs @@ -141,7 +141,9 @@ async fn blockable_item( }; 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() { @@ -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?; } ItemType::KillGun => { - let (outcome, target) = blockable_item( + let (outcome, target) = match blockable_item( ctx, global_data, msg.guild_id.unwrap(), @@ -290,7 +292,14 @@ async fn use_item(ctx: &Context, msg: &Message, args: Args) -> CommandResult { "kill gun ", ItemType::Helmet, ) - .await?; + .await + { + Ok(ret) => ret, + Err(err) => { + msg.reply(&ctx.http, err.to_string()).await?; + return Ok(()); + } + }; 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?; @@ -299,7 +308,7 @@ async fn use_item(ctx: &Context, msg: &Message, args: Args) -> CommandResult { } } ItemType::CancelRay => { - let (outcome, target) = blockable_item( + let (outcome, target) = match blockable_item( ctx, global_data, msg.guild_id.unwrap(), @@ -308,7 +317,14 @@ async fn use_item(ctx: &Context, msg: &Message, args: Args) -> CommandResult { "cancel ray ", ItemType::CancelInsurance, ) - .await?; + .await + { + Ok(ret) => ret, + Err(err) => { + msg.reply(&ctx.http, err.to_string()).await?; + return Ok(()); + } + }; 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?;