예제 #1
0
        public async Task Meaning(params string[] words)
        {
            Base.Utilities.CheckAvailability(Context.Guild, Program.Module.Linguistic);
            await p.DoAction(Context.User, Program.Module.Linguistic);

            var result = await Features.Tools.Linguist.JapaneseTranslate(words);

            switch (result.error)
            {
            case Features.Tools.Error.JapaneseTranslation.Help:
                await ReplyAsync(Sentences.JapaneseHelp(Context.Guild));

                break;

            case Features.Tools.Error.JapaneseTranslation.NotFound:
                await ReplyAsync(Sentences.NoJapaneseTranslation(Context.Guild));

                break;

            case Features.Tools.Error.JapaneseTranslation.None:
                EmbedBuilder embed = new EmbedBuilder()
                {
                    Color = Color.Blue,
                    Title = string.Join(" ", words)
                };
                int i = 0;
                foreach (var answer in result.answer)
                {
                    embed.AddField(string.Join(", ", answer.definition),
                                   string.Join(Environment.NewLine, answer.words.Select((Features.Tools.Response.JapaneseWord word) =>
                                                                                        ((word.word != null) ? (word.word + " - ") : ("")) + ((word.reading != null) ? (word.reading + " (" + word.romaji + ")") : ("")))));
                    if (++i == 5)
                    {
                        break;
                    }
                }
                await ReplyAsync("", false, embed.Build());

                break;

            default:
                throw new NotImplementedException();
            }
        }