Пример #1
0
        public async Task Trades(CommandContext ctx, [Description("The player name or item name in question.")] string itemNameOrUserName = "")
        {
            try
            {
                var plugin = DiscordLink.Obj;
                if (plugin == null)
                {
                    return;
                }

                if (string.IsNullOrEmpty(itemNameOrUserName))
                {
                    await RespondToCommand(ctx,
                                           "Please provide the name of an item or player to search for. " +
                                           "Usage: trades <item name or player name>");

                    return;
                }

                var embed = new DiscordEmbedBuilder()
                            .WithColor(MessageBuilder.EmbedColor)
                            .WithTitle("Trade Listings");

                var match = TradeUtil.MatchItemOrUser(itemNameOrUserName);

                if (match.Is <Item>())
                {
                    var matchItem = match.Get <Item>();
                    embed.WithAuthor(matchItem.DisplayName);
                    previousQueryEnumerator[ctx.User.UniqueUsername()] = TradeOffersBuySell(embed, (store, offer) => offer.Stack.Item == matchItem, t => t.Item1.Parent.Owners.Name);
                }
                else if (match.Is <User>())
                {
                    var matchUser = match.Get <User>();
                    embed.WithAuthor(matchUser.Name);
                    previousQueryEnumerator[ctx.User.UniqueUsername()] = TradeOffersBuySell(embed, (store, offer) => store.Parent.Owners == matchUser, t => t.Item2.Stack.Item.DisplayName);
                }
                else
                {
                    await RespondToCommand(ctx, "The player or item was not found.");

                    return;
                }

                var pagedEnumerator = previousQueryEnumerator[ctx.User.UniqueUsername()];
                if (pagedEnumerator.HasMorePages)
                {
                    embed.WithFooter("More pages available. Use " + DiscordLink.EchoCommandToken + "nextpage to show.");
                }

                await RespondToCommand(ctx, null, embed);
            }
            catch (Exception e)
            {
                LogCommandException(e);
            }
        }
Пример #2
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);
        }