public async Task <CommandResult> GiftBadge(CommandContext context) { User gifter = context.Message.User; (User recipient, PkmnSpecies species, Optional <PositiveInt> amountOpt) = await context.ParseArgs <AnyOrder <User, PkmnSpecies, Optional <PositiveInt> > >(); int amount = amountOpt.Map(i => i.Number).OrElse(1); if (recipient == gifter) { return new CommandResult { Response = "You cannot gift to yourself" } } ; List <Badge> badges = await _badgeRepo.FindByUserAndSpecies(gifter.Id, species); if (badges.Count < amount) { return new CommandResult { Response = $"You tried to gift {amount} {species} badges, but you only have {badges.Count}." } } ; IImmutableList <Badge> badgesToGift = badges.Take(amount).ToImmutableList(); var data = new Dictionary <string, object?> { ["gifter"] = gifter.Id }; await _badgeRepo.TransferBadges(badgesToGift, recipient.Id, BadgeLogType.TransferGift, data); await _messageSender.SendWhisper(recipient, amount > 1 ?$"You have been gifted {amount} {species} badges from {gifter.Name}!" : $"You have been gifted a {species} badge from {gifter.Name}!"); return(new CommandResult { Response = amount > 1 ? $"has gifted {amount} {species} badges to {recipient.Name}!" : $"has gifted a {species} badge to {recipient.Name}!", ResponseTarget = ResponseTarget.Chat }); } } }
public async Task <CommandResult> TransferBadge(CommandContext context) { (User gifter, (User recipient, PkmnSpecies species, Optional <PositiveInt> amountOpt), ManyOf <string> reasonParts) = await context.ParseArgs <User, AnyOrder <User, PkmnSpecies, Optional <PositiveInt> >, ManyOf <string> >(); string reason = string.Join(' ', reasonParts.Values); int amount = amountOpt.Map(i => i.Number).OrElse(1); if (string.IsNullOrEmpty(reason)) { return new CommandResult { Response = "Must provide a reason" } } ; if (gifter == context.Message.User) { return new CommandResult { Response = "Use the regular gift command if you're the gifter" } } ; if (recipient == gifter) { return new CommandResult { Response = "Gifter cannot be equal to recipient" } } ; List <Badge> badges = await _badgeRepo.FindByUserAndSpecies(gifter.Id, species); if (badges.Count < amount) { return new CommandResult { Response = $"You tried to transfer {amount} {species} badges, but the gifter only has {badges.Count}." } } ; IImmutableList <Badge> badgesToGift = badges.Take(amount).ToImmutableList(); var data = new Dictionary <string, object?> { ["gifter"] = gifter.Id, ["responsible_user"] = context.Message.User.Id, ["reason"] = reason }; await _badgeRepo.TransferBadges(badgesToGift, recipient.Id, BadgeLogType.TransferGiftRemote, data); await _messageSender.SendWhisper(recipient, amount > 1 ?$"{context.Message.User.Name} transferred {amount} {species} badges from {gifter.Name} to you. Reason: {reason}" : $"{context.Message.User.Name} transferred a {species} badge from {gifter.Name} to you. Reason: {reason}"); return(new CommandResult { Response = amount > 1 ? $"transferred {amount} {species} badges from {gifter.Name} to {recipient.Name}. Reason: {reason}" : $"transferred a {species} badge from {gifter.Name} to {recipient.Name}. Reason: {reason}", ResponseTarget = ResponseTarget.Chat }); }