Working on .novel and .waifutransfer
This commit is contained in:
		@@ -16,6 +16,32 @@ namespace NadekoBot.Modules.Searches
 | 
			
		||||
        [Group]
 | 
			
		||||
        public class AnimeSearchCommands : NadekoSubmodule<AnimeSearchService>
 | 
			
		||||
        {
 | 
			
		||||
            [NadekoCommand, Usage, Description, Aliases]
 | 
			
		||||
            public async Task Novel([Remainder] string query)
 | 
			
		||||
            {
 | 
			
		||||
                if (string.IsNullOrWhiteSpace(query))
 | 
			
		||||
                    return;
 | 
			
		||||
 | 
			
		||||
                var novelData = await _service.GetNovelData(query).ConfigureAwait(false);
 | 
			
		||||
 | 
			
		||||
                if (novelData == null)
 | 
			
		||||
                {
 | 
			
		||||
                    await ReplyErrorLocalized("failed_finding_novel").ConfigureAwait(false);
 | 
			
		||||
                    return;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                var embed = new EmbedBuilder().WithColor(NadekoBot.OkColor)
 | 
			
		||||
                    .WithDescription(novelData.Description.Replace("<br>", Environment.NewLine))
 | 
			
		||||
                    .WithTitle(novelData.Title)
 | 
			
		||||
                    .WithUrl(novelData.Link)
 | 
			
		||||
                    .WithImageUrl(novelData.ImageUrl)
 | 
			
		||||
                    .AddField(efb => efb.WithName(GetText("authors")).WithValue(String.Join("\n", novelData.Authors)).WithIsInline(true))
 | 
			
		||||
                    .AddField(efb => efb.WithName(GetText("status")).WithValue(novelData.Status).WithIsInline(true))
 | 
			
		||||
                    .AddField(efb => efb.WithName(GetText("genres")).WithValue(string.Join(",\n", novelData.Genres.Any() ? novelData.Genres : new[] { "none" })).WithIsInline(true))
 | 
			
		||||
                    .WithFooter(efb => efb.WithText(GetText("score") + " " + novelData.Score));
 | 
			
		||||
                await Context.Channel.EmbedAsync(embed).ConfigureAwait(false);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            [NadekoCommand, Usage, Description, Aliases]
 | 
			
		||||
            [Priority(0)]
 | 
			
		||||
            public async Task Mal([Remainder] string name)
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										20
									
								
								NadekoBot.Core/Modules/Searches/Common/NovelData.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								NadekoBot.Core/Modules/Searches/Common/NovelData.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,20 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
 | 
			
		||||
namespace NadekoBot.Modules.Searches.Common
 | 
			
		||||
{
 | 
			
		||||
    public class NovelData
 | 
			
		||||
    {
 | 
			
		||||
        public string Description { get; set; }
 | 
			
		||||
        public string Title { get; set; }
 | 
			
		||||
        public string Link { get; set; }
 | 
			
		||||
        public string ImageUrl { get; set; }
 | 
			
		||||
        public string[] Authors { get; set; }
 | 
			
		||||
        public string Status { get; set; }
 | 
			
		||||
        public string[] Genres { get; set; }
 | 
			
		||||
        public string Score { get; set; }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -46,6 +46,33 @@ namespace NadekoBot.Modules.Searches.Services
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public async Task<NovelData> GetNovelData(string query)
 | 
			
		||||
        {
 | 
			
		||||
            if (string.IsNullOrWhiteSpace(query))
 | 
			
		||||
                throw new ArgumentNullException(nameof(query));
 | 
			
		||||
 | 
			
		||||
            query = query.Replace(" ", "-");
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
 | 
			
		||||
                var link = "http://www.novelupdates.com/series/" + Uri.EscapeDataString(query.Replace("/", " "));
 | 
			
		||||
                link = link.ToLowerInvariant();
 | 
			
		||||
                var (ok, data) = await _cache.TryGetAnimeDataAsync(link).ConfigureAwait(false);
 | 
			
		||||
                if (!ok)
 | 
			
		||||
                {
 | 
			
		||||
                    data = await _http.GetStringAsync(link).ConfigureAwait(false);
 | 
			
		||||
                    await _cache.SetAnimeDataAsync(link, data).ConfigureAwait(false);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
                return JsonConvert.DeserializeObject<MangaResult>(data);
 | 
			
		||||
            }
 | 
			
		||||
            catch
 | 
			
		||||
            {
 | 
			
		||||
                return null;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public async Task<MangaResult> GetMangaData(string query)
 | 
			
		||||
        {
 | 
			
		||||
            if (string.IsNullOrWhiteSpace(query))
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user