Example #1
0
        public async Task Source(params string[] args)
        {
            Base.Utilities.CheckAvailability(Context.Guild.Id, Program.Module.AnimeManga);
            await p.DoAction(Context.User, Context.Guild.Id, Program.Module.AnimeManga);

            bool skipBeginning = false;

            if (Context.Message.Attachments.Count > 0)
            {
                args          = new[] { Context.Message.Attachments.ToArray()[0].Url };
                skipBeginning = true;
            }
            var result = await Features.Entertainment.AnimeManga.SearchSource(((ITextChannel)Context.Channel).IsNsfw, skipBeginning, Program.p.websiteUpload, Program.p.websiteUploadToken, args);

            switch (result.error)
            {
            case Error.Source.None:
                Color color;
                float certitude = result.answer.compatibility;
                if (certitude > 80f)
                {
                    color = Color.Green;
                }
                else if (certitude > 50)
                {
                    color = Color.Orange;
                }
                else
                {
                    color = Color.Red;
                }
                await ReplyAsync("", false, new EmbedBuilder
                {
                    Color       = color,
                    Title       = result.answer.name,
                    Description = Sentences.Episode(Context.Guild.Id) + " " + (result.answer.episode == -1 ? Sentences.Unknown(Context.Guild.Id) : result.answer.episode.ToString()) + " " + Base.Sentences.AtStr(Context.Guild.Id) + " " + result.answer.at,
                    ImageUrl    = result.answer.imageUrl,
                    Footer      = new EmbedFooterBuilder
                    {
                        Text = Sentences.Certitude(Context.Guild.Id) + ": " + result.answer.compatibility.ToString("0.00") + "%"
                    }
                }.Build());

                break;

            case Error.Source.Help:
                await ReplyAsync(Sentences.SourceHelp(Context.Guild.Id));

                break;

            case Error.Source.NotFound:
                await ReplyAsync(Tools.Sentences.NotAnImage(Context.Guild.Id));

                break;

            case Error.Source.NotNsfw:
                await ReplyAsync(Base.Sentences.AnswerNsfw(Context.Guild.Id));

                break;

            case Error.Source.NotAnUrl:
                await ReplyAsync(Sentences.NotAnUrl(Context.Guild.Id));

                break;

            default:
                throw new NotImplementedException();
            }
        }