Ejemplo n.º 1
0
        public static string Trades(string userOrItemName, out string matchedName, out bool isItem, out StoreOfferList groupedBuyOffers, out StoreOfferList groupedSellOffers)
        {
            var plugin = DiscordLink.Obj;

            matchedName       = string.Empty;
            groupedBuyOffers  = null;
            groupedSellOffers = null;
            isItem            = false;

            if (string.IsNullOrEmpty(userOrItemName))
            {
                return("Please provide the name of an item or player to search for.");
            }

            List <string> entries = new List <string>();
            var           match   = TradeUtil.MatchItemOrUser(userOrItemName);

            if (match.Is <Item>())
            {
                var matchItem = match.Get <Item>();
                matchedName = matchItem.DisplayName;

                Func <StoreComponent, TradeOffer, bool> filter = (store, offer) => offer.Stack.Item == matchItem;
                var sellOffers = TradeUtil.SellOffers(filter);
                groupedSellOffers = sellOffers.GroupBy(t => TradeUtil.StoreCurrencyName(t.Item1)).OrderBy(g => g.Key);
                var buyOffers = TradeUtil.BuyOffers(filter);
                groupedBuyOffers = buyOffers.GroupBy(t => TradeUtil.StoreCurrencyName(t.Item1)).OrderBy(g => g.Key);

                isItem = true;
            }
            else if (match.Is <User>())
            {
                var matchUser = match.Get <User>();
                matchedName = matchUser.Name;

                Func <StoreComponent, TradeOffer, bool> filter = (store, offer) => store.Parent.Owners == matchUser;
                var sellOffers = TradeUtil.SellOffers(filter);
                groupedSellOffers = sellOffers.GroupBy(t => TradeUtil.StoreCurrencyName(t.Item1)).OrderBy(g => g.Key);
                var buyOffers = TradeUtil.BuyOffers(filter);
                groupedBuyOffers = buyOffers.GroupBy(t => TradeUtil.StoreCurrencyName(t.Item1)).OrderBy(g => g.Key);
            }
            else
            {
                return($"No player or item with the name \"{userOrItemName}\" could be found.");
            }

            return(string.Empty);
        }
Ejemplo n.º 2
0
        private PagedEnumerator <Tuple <string, string> > TradeOffersBuySell(DiscordEmbedBuilder embed, Func <StoreComponent, TradeOffer, bool> filter, Func <Tuple <StoreComponent, TradeOffer>, string> context)
        {
            var sellOffers        = TradeUtil.SellOffers(filter);
            var groupedSellOffers = sellOffers.GroupBy(t => TradeUtil.StoreCurrencyName(t.Item1)).OrderBy(g => g.Key);

            var buyOffers        = TradeUtil.BuyOffers(filter);
            var groupedBuyOffers = buyOffers.GroupBy(t => TradeUtil.StoreCurrencyName(t.Item1)).OrderBy(g => g.Key);

            var fieldEnumerator = OffersToFields(groupedBuyOffers, groupedSellOffers, context).GetEnumerator();

            var pagedFieldEnumerator = new PagedEnumerator <Tuple <string, string> >(fieldEnumerator, DiscordUtil.EMBED_CONTENT_CHARACTER_LIMIT, field => field.Item1.Length + field.Item2.Length);

            pagedFieldEnumerator.ForEachInPage(field => { embed.AddField(field.Item1, field.Item2, true); });

            return(pagedFieldEnumerator);
        }