コード例 #1
0
        public async Task <bool> TryInvokeAsync(IMessage message)
        {
            if (message == null)
            {
                return(false);
            }
            (bool success, string character) = ParseArgs(message.Content);

            if (!success)
            {
                return(false);
            }

            PlayerPoints dkp = await dkpProcessor.GetDkp(character);

            string dkpMessage = $"{character.UppercaseFirst()} has **{dkp.PointsCurrentWithTwink}** available to spend.\n```\nLifetime DKP for {character}: Earned {dkp.PointsEarnedWithTwink} - Spent {dkp.PointsSpentWithTwink} - Adjustments {dkp.PointsAdjustmentWithTwink}.```";

            string memePath = config.MemeDkpPath + character + ".jpg";

            ;

            if (config.EnableMemeDkp && File.Exists(memePath))
            {
                log.LogInformation($"{character} dkp memes!");
                await message.Channel.SendFileAsync(memePath, dkpMessage);
            }
            else
            {
                await message.Channel.SendMessageAsync(dkpMessage);
            }
            return(true);
        }
コード例 #2
0
        public async Task <AuctionBid> AddOrUpdateBid(string item, string character, string rank, int bid, IMessage message)
        {
            // First make sure we can make a valid bid out of it.
            if (!ranks.TryGetValue(rank, out RankConfiguration rankConfig))
            {
                throw new ArgumentException($"Rank {rank} does not exist.");
            }

            if (!state.Auctions.TryGetValue(item, out Auction auction))
            {
                throw new AuctionNotFoundException(item);
            }

            int characterId = await dkpProcessor.GetCharacterId(character);

            PlayerPoints points = await dkpProcessor.GetDkp(characterId);

            int pointsAlreadyBid = state.Auctions.Values.SelectMany(x => x.Bids)
                                   .Where(b => b.CharacterId == characterId && // From This character
                                          b.Auction != auction)                  // Don't count this current auction, because we're replacing it.
                                   .Sum(x => x.BidAmount) * rankConfig.PriceMultiplier;
            decimal availableDkp = (points.PointsCurrentWithTwink - pointsAlreadyBid) / rankConfig.PriceMultiplier;

            if (availableDkp < bid)
            {
                throw new InsufficientDkpException($"{character} only has {availableDkp} left to bid with. Cancel some bids, or bid less!");
            }

            AuctionBid newBid = auction.Bids.AddOrUpdate(new AuctionBid(auction, character, characterId, bid, rankConfig, message.Author));

            log.LogInformation($"Created bid: {newBid}");

            await message.Channel.SendMessageAsync($"Bid accepted for **{newBid.Auction}**\n"
                                                   + $"```\"{auction.Name}\" {newBid}```"
                                                   + $"If you win, you could pay up to **{newBid.BidAmount * newBid.Rank.PriceMultiplier}**.\n"
                                                   + $"If you wish to modify your bid before the auction completes, simply enter a new bid in the next **{auction.MinutesRemaining:##.#}** minutes.\n"
                                                   + "If you wish to cancel your bid use the following syntax:\n"
                                                   + $"```\"{newBid.Auction.Name}\" cancel```");

            return(newBid);
        }