示例#1
0
            public async Task Spell(CommandContext ctx, params string[] args)
            {
                string spellClass = "";
                int    spellLevel = -1;
                bool   nameSearch = true;

                //Determine if user looked for name or spell class/level
                for (int i = 0; i < args.Length; i++)
                {
                    args[i] = args[i].ToLower();
                    if (args[i].Equals("class"))
                    {
                        spellClass = args[i + 1];
                        spellClass = Char.ToUpper(spellClass[0]) + spellClass.Substring(1);
                        nameSearch = false;
                    }
                    if (args[i].Equals("level"))
                    {
                        if (!Int32.TryParse(args[i + 1], out spellLevel))
                        {
                            await ctx.RespondAsync("Invalid spell level!");

                            return;
                        }
                        nameSearch = false;
                    }
                } // end validation

                // Loads spell database
                CelerityIO           cio            = new CelerityIO();
                List <CeleritySpell> celeritySpells = cio.readSpellList();

                if (nameSearch)
                {
                    // User is searching for spell name
                    string        name  = String.Join(" ", args);
                    bool          found = false;
                    CeleritySpell data  = null;
                    foreach (CeleritySpell cs in celeritySpells)
                    {
                        if (cs.title.ToLower().Equals(name))
                        {
                            found = true;
                            data  = cs;
                            break;
                        }
                    } // end foreach

                    if (!found)
                    {
                        await ctx.RespondAsync("Spell not found: " + name);

                        return;
                    }
                    else
                    {
                        // Found a corresponding spell
                        Console.WriteLine("Spell Found: " + name + "\n");
                        Console.WriteLine(data.ToString());
                        DiscordEmbedBuilder embed = new DiscordEmbedBuilder {
                            Title = data.title, Color = new DiscordColor(1621076), Url = data.link
                        };
                        if (!data.category.Equals("null"))
                        {
                            embed.AddField("Category", data.category);
                        }
                        embed.AddField("Class Level", data.spellLevelsToString());
                        if (!data.components.Equals("null"))
                        {
                            embed.AddField("Components", data.components);
                        }
                        if (!data.castingTime.Equals("null"))
                        {
                            embed.AddField("Casting Time", data.castingTime);
                        }
                        if (!data.range.Equals("null"))
                        {
                            embed.AddField("Range", data.range);
                        }
                        if (!data.target.Equals("null"))
                        {
                            embed.AddField("Target", data.target);
                        }
                        if (!data.duration.Equals("null"))
                        {
                            embed.AddField("Duration", data.duration);
                        }
                        if (!data.effect.Equals("null"))
                        {
                            embed.AddField("Effect", data.effect);
                        }
                        if (!data.savingThrow.Equals("null"))
                        {
                            embed.AddField("Saving Throw", data.savingThrow);
                        }
                        embed.AddField("Description", data.body);

                        await ctx.RespondAsync(embed : embed);

                        return;
                    }
                }
                else
                {
                    List <string> result = new List <string>();
                    int           match  = 0;
                    foreach (CeleritySpell cs in celeritySpells)
                    {
                        foreach (CeleritySpell.SpellLevel sl in cs.spellLevel)
                        {
                            bool found = true;
                            // If spell class is to be found
                            if (!spellClass.Equals(""))
                            {
                                if (!sl.caster.Equals(spellClass))
                                {
                                    found = false;
                                }
                            }
                            // If spell level is to be found
                            if (spellLevel != -1)
                            {
                                if (sl.level != spellLevel)
                                {
                                    found = false;
                                }
                            }
                            if (found)
                            {
                                match++;
                                result.Add(cs.title);
                                break;
                            }
                        }
                    } // end foreach
                    string ret = "";
                    if (result.Count() == 0)
                    {
                        ret = "None";
                    }
                    else
                    {
                        ret = String.Join("\n", result);
                    }
                    Console.WriteLine("Result length: " + ret.Length.ToString());

                    DiscordEmbedBuilder embed = new DiscordEmbedBuilder {
                        Title = "Search Result", Color = new DiscordColor(1621076)
                    };
                    if (ret.Length <= 1024)
                    {
                        embed.AddField(match.ToString() + " results found", ret);
                    }
                    else
                    {
                        embed.AddField(match.ToString() + " results found", ret.Substring(0, 1024));
                        int  counter = 1;
                        bool stop    = false;
                        while (!stop)
                        {
                            int lineLength = 1024;
                            if (ret.Length <= 1024 * (counter + 1))
                            {
                                stop       = true;
                                lineLength = ret.Length - (1024 * counter);
                            }
                            embed.AddField("--", ret.Substring(1024 * counter, lineLength));
                            counter++;
                        }
                    }

                    await ctx.RespondAsync(embed : embed);

                    return;
                }
            }
示例#2
0
 public async Task Test(CommandContext ctx)
 {
     CelerityIO           cio            = new CelerityIO();
     List <CeleritySpell> celeritySpells = cio.readSpellList();
     await ctx.RespondAsync(celeritySpells[0].title);
 }