Exemple #1
0
    public async Task SendItemInfo([Remainder] string item)
    {
        sw.Start();


        //Stops people spamming characters as to lag the bot
        if (item.Length > 100)
        {
            await ReplyAsync("Please use a shorter item name."); return;
        }
        if (item.Length < 2)
        {
            await ReplyAsync("Please use a longer item name."); return;
        }

        if (AliasManager.GetItemName(item) != null)
        {
            item = AliasManager.GetItemName(item);
        }

        //Grabbing item info
        var itemInfo = await Utilities.SearchForItem(item);

        if (itemInfo == null || itemInfo.Count == 0)
        {
            await ReplyAsync($"Item `{item}` not found."); return;
        }
        else
        {
            if (itemInfo.Count > 1)
            {
                StringBuilder si    = new StringBuilder();
                int           count = 0;

                foreach (SearchItem s in itemInfo)
                {
                    count++;
                    si.Append($"{count}. {s.ItemName}\n");
                }

                si.Append("\n**Please type the number of the item you are looking for.**");
                sw.Stop();

                await ReplyAsync("", false, Utilities.GetEmbedMessage("Search Results", "Multiple Results", si.ToString(), Context.Message.Author));


                var response = await NextMessageAsync();

                sw.Start();

                if (response != null)
                {
                    Item i;

                    if (Utilities.itemCache.ContainsKey(itemInfo[Convert.ToInt32(response.Content) - 1].ItemName))
                    {
                        i = Utilities.itemCache[itemInfo[Convert.ToInt32(response.Content) - 1].ItemName];
                    }
                    else
                    {
                        i = await Utilities.GetItemInfo(itemInfo[Convert.ToInt32(response.Content) - 1]);
                    }

                    await ReplyAsync("", false, GenMessage(i));
                }
            }
            else
            {
                Item i;

                if (Utilities.itemCache.ContainsKey(itemInfo[0].ItemName))
                {
                    i = Utilities.itemCache[itemInfo[0].ItemName];
                }
                else
                {
                    i = await Utilities.GetItemInfo(itemInfo[0]);
                }

                await ReplyAsync("", false, GenMessage(i));
            }
        }
    }
    public async Task SendBreakInfo([Remainder] string placeable)
    {
        sw.Start();


        SearchBreakable sb;

        if (AliasManager.GetItemName(placeable) != null)
        {
            placeable = AliasManager.GetItemName(placeable);
        }

        //-----------------------Structure Type------------------------
        sw.Stop();
        var sInfoMsg = await ReplyAsync("", false, Utilities.GetEmbedMessage("Break Info", "Structure Type", Language.BreakInfo_Structure_Type, Context.Message.Author));

        var response = await NextMessageAsync();

        sw.Start();
        //If structure
        if (response.Content == "1")
        {
            sb = await Utilities.SearchForBreakable("block", placeable.ToLower());
        }
        //If placeable
        else if (response.Content == "2")
        {
            sb = await Utilities.SearchForBreakable("placeable", placeable.ToLower());
        }
        //If anything else
        else
        {
            await ReplyAsync("Please type the number of the structure type. Run the command again."); return;
        }

        sw.Stop();

        //-----------------------Attack Type------------------------
        var aInfoMsg = await ReplyAsync("", false, Utilities.GetEmbedMessage("Break Info", "Attack Type", Language.BreakInfo_Attack_Type, Context.Message.Author));

        var attackType = await NextMessageAsync();

        sw.Start();

        string attack;

        if (attackType.Content == "1")
        {
            attack = "explosive";
        }
        else if (attackType.Content == "2")
        {
            attack = "melee";
        }
        else if (attackType.Content == "3")
        {
            attack = "guns";
        }
        else if (attackType.Content == "4")
        {
            attack = "throw";
        }
        else
        {
            await ReplyAsync("Please type the number of the attack type. Run the command again."); return;
        }

        //-----------------------Side Type------------------------
        string side = null;

        if (response.Content == "1")
        {
            var sideMessage = await ReplyAsync("", false, Utilities.GetEmbedMessage("Break Info", "Block Side", Language.BreakInfo_Block_Side, Context.Message.Author));

            var sideType = await NextMessageAsync();

            sw.Start();

            if (attackType.Content == "1")
            {
                side = "hard";
            }
            else if (attackType.Content == "2")
            {
                side = "soft";
            }
            else
            {
                await ReplyAsync("Please type the number of the block side. Run the command again."); return;
            }
        }

        BreakableInfo bi;

        //If item is not found, reply with an error message and return
        if (sb == null)
        {
            await ReplyAsync("Structure/Placeable not found."); return;
        }

        //If the item is in the cache, don't search for it.
        if (Utilities.breakCache.ContainsKey(sb.ItemName))
        {
            bi = Utilities.breakCache[sb.ItemName];
        }
        else
        {
            bi = await Utilities.GetBreakableInfo(sb, attack, side);
        }

        //If item isn't placeable
        if (bi == null)
        {
            await ReplyAsync("Structure/Placeable not found."); return;
        }

        //Removes the attack info message
        await aInfoMsg.DeleteAsync();

        //Removes the structure info message
        await sInfoMsg.DeleteAsync();

        try
        {
            await ReplyAsync("", false, GetEmbed(bi));
        }
        catch (Exception)
        {
            await ReplyAsync("", false, Utilities.GetEmbedMessage("Break Info", "Error", $"There are too many results to fit into a Discord Embed, please click [here]({bi.URL}) to see your results.", Context.Message.Author));
        }
    }
    public async Task SendCraftingInfo(Int64 number, [Remainder] string item)
    {
        sw.Start();
        

        //Stops people spamming characters as to lag the bot
        if (item.Length > 100) { await ReplyAsync("Please use a shorter item name."); return; }
        if (item.Length < 2) { await ReplyAsync("Please use a longer item name."); return; }
        if (number < 0) { await ReplyAsync("Input must be larger than 0."); return; }

        if (AliasManager.GetItemName(item) != null) { item = AliasManager.GetItemName(item); }

        //Grabbing item info
        var itemInfo = await Utilities.SearchForItem(item);

        //If item not found
        if (itemInfo == null) { await ReplyAsync($"Item `{item}` not found."); return; }
        //If item found
        else
        {
            //If there's more than one item found
            if (itemInfo.Count > 1)
            {
                StringBuilder si = new StringBuilder();
                int count = 0;

                foreach (SearchItem s in itemInfo)
                {
                    count++;
                    si.Append($"{count}. {s.ItemName}\n");
                }

                si.Append("\n**Please type the number of the item you are looking for.**");

                sw.Stop();
                await ReplyAsync("", false, Utilities.GetEmbedMessage("Search Results", "Multiple Results", si.ToString(), Context.Message.Author));


                var response = await NextMessageAsync();
                sw.Start();

                if (response != null)
                {
                    Item i = await Utilities.GetItemInfo(itemInfo[Convert.ToInt32(response.Content) - 1]);

                    //If the item isn't craftable, send an error message and return
                    if (i.Ingredients.Count < 1) { await ReplyAsync("", false, Utilities.GetEmbedMessage($"{i.ItemName}", "Not Craftable", Language.Crafting_Cannot_Craft, Context.Message.Author)); return; }

                    await ReplyAsync("", false, GenMessage(i, number));
                }

            }
            //If one item found
            else
            {
                sw.Start();
                Item i = await Utilities.GetItemInfo(itemInfo[0]);

                //If the item isn't craftable, send an error message and return
                if (i.Ingredients.Count < 1) { await ReplyAsync("", false, Utilities.GetEmbedMessage($"{i.ItemName}", "Not Craftable", Language.Crafting_Cannot_Craft, Context.Message.Author)); return; }

                await ReplyAsync("", false, GenMessage(i, number));
            }
        }

    }