Swap the my anime list wrapper for the !anime and !manga commands
This commit is contained in:
parent
216188f61f
commit
7ef0b6a319
6 changed files with 47 additions and 150 deletions
|
@ -24,8 +24,8 @@
|
|||
<PackageReference Include="CommandLineParser" Version="2.8.0" />
|
||||
<PackageReference Include="Google.Apis.YouTube.v3" Version="1.45.0.1929" />
|
||||
<PackageReference Include="HtmlAgilityPack" Version="1.11.24" />
|
||||
<PackageReference Include="JikanDotNet" Version="1.5.1" />
|
||||
<PackageReference Include="MtgApiManager.Lib" Version="1.2.2" />
|
||||
<PackageReference Include="MyAnimeListSharp" Version="1.3.4" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
<PackageReference Include="PokeApi.NET" Version="1.1.2" />
|
||||
<PackageReference Include="SharpRaven" Version="2.4.0" />
|
||||
|
|
|
@ -1,23 +1,23 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using System.Xml;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Geekbot.Core.ErrorHandling;
|
||||
using Geekbot.Core.Extensions;
|
||||
using Geekbot.Core.MalClient;
|
||||
using JikanDotNet;
|
||||
|
||||
namespace Geekbot.Bot.Commands.Integrations
|
||||
{
|
||||
public class Mal : ModuleBase
|
||||
{
|
||||
private readonly IErrorHandler _errorHandler;
|
||||
private readonly IMalClient _malClient;
|
||||
private readonly IJikan _client;
|
||||
|
||||
public Mal(IMalClient malClient, IErrorHandler errorHandler)
|
||||
public Mal(IErrorHandler errorHandler)
|
||||
{
|
||||
_malClient = malClient;
|
||||
_client = new Jikan();
|
||||
_errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
|
@ -27,46 +27,34 @@ namespace Geekbot.Bot.Commands.Integrations
|
|||
{
|
||||
try
|
||||
{
|
||||
if (_malClient.IsLoggedIn())
|
||||
var results = await _client.SearchAnime(animeName);
|
||||
var anime = results.Results.FirstOrDefault();
|
||||
if (anime != null)
|
||||
{
|
||||
var anime = await _malClient.GetAnime(animeName);
|
||||
if (anime != null)
|
||||
{
|
||||
var eb = new EmbedBuilder();
|
||||
var eb = new EmbedBuilder();
|
||||
|
||||
var description = HttpUtility.HtmlDecode(anime.Synopsis)
|
||||
.Replace("<br />", "")
|
||||
.Replace("[i]", "*")
|
||||
.Replace("[/i]", "*");
|
||||
var description = HttpUtility.HtmlDecode(anime.Description)
|
||||
.Replace("<br />", "")
|
||||
.Replace("[i]", "*")
|
||||
.Replace("[/i]", "*");
|
||||
|
||||
eb.Title = anime.Title;
|
||||
eb.Description = description;
|
||||
eb.ImageUrl = anime.Image;
|
||||
eb.AddInlineField("Premiered", $"{anime.StartDate}");
|
||||
eb.AddInlineField("Ended", anime.EndDate == "0000-00-00" ? "???" : anime.EndDate);
|
||||
eb.AddInlineField("Status", anime.Status);
|
||||
eb.AddInlineField("Episodes", anime.Episodes);
|
||||
eb.AddInlineField("MAL Score", anime.Score);
|
||||
eb.AddInlineField("Type", anime.Type);
|
||||
eb.AddField("MAL Link", $"https://myanimelist.net/anime/{anime.Id}");
|
||||
eb.Title = anime.Title;
|
||||
eb.Description = description;
|
||||
eb.ImageUrl = anime.ImageURL;
|
||||
eb.AddInlineField("Premiered", $"{anime.StartDate.Value.ToShortDateString()}");
|
||||
eb.AddInlineField("Ended", anime.Airing ? "Present" : anime.EndDate.Value.ToShortDateString());
|
||||
eb.AddInlineField("Episodes", anime.Episodes);
|
||||
eb.AddInlineField("MAL Score", anime.Score);
|
||||
eb.AddInlineField("Type", anime.Type);
|
||||
eb.AddField("MAL Link", $"https://myanimelist.net/anime/{anime.MalId}");
|
||||
|
||||
await ReplyAsync("", false, eb.Build());
|
||||
}
|
||||
else
|
||||
{
|
||||
await ReplyAsync("No anime found with that name...");
|
||||
}
|
||||
await ReplyAsync("", false, eb.Build());
|
||||
}
|
||||
else
|
||||
{
|
||||
await ReplyAsync(
|
||||
"Unfortunally i'm not connected to MyAnimeList.net, please tell my senpai to connect me");
|
||||
await ReplyAsync("No anime found with that name...");
|
||||
}
|
||||
}
|
||||
catch (XmlException e)
|
||||
{
|
||||
await _errorHandler.HandleCommandException(e, Context, "The MyAnimeList.net API refused to answer");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
|
@ -79,46 +67,34 @@ namespace Geekbot.Bot.Commands.Integrations
|
|||
{
|
||||
try
|
||||
{
|
||||
if (_malClient.IsLoggedIn())
|
||||
var results = await _client.SearchManga(mangaName);
|
||||
var manga = results.Results.FirstOrDefault();
|
||||
if (manga != null)
|
||||
{
|
||||
var manga = await _malClient.GetManga(mangaName);
|
||||
if (manga != null)
|
||||
{
|
||||
var eb = new EmbedBuilder();
|
||||
var eb = new EmbedBuilder();
|
||||
|
||||
var description = HttpUtility.HtmlDecode(manga.Synopsis)
|
||||
.Replace("<br />", "")
|
||||
.Replace("[i]", "*")
|
||||
.Replace("[/i]", "*");
|
||||
var description = HttpUtility.HtmlDecode(manga.Description)
|
||||
.Replace("<br />", "")
|
||||
.Replace("[i]", "*")
|
||||
.Replace("[/i]", "*");
|
||||
|
||||
eb.Title = manga.Title;
|
||||
eb.Description = description;
|
||||
eb.ImageUrl = manga.Image;
|
||||
eb.AddInlineField("Premiered", $"{manga.StartDate}");
|
||||
eb.AddInlineField("Ended", manga.EndDate == "0000-00-00" ? "???" : manga.EndDate);
|
||||
eb.AddInlineField("Status", manga.Status);
|
||||
eb.AddInlineField("Volumes", manga.Volumes);
|
||||
eb.AddInlineField("Chapters", manga.Chapters);
|
||||
eb.AddInlineField("MAL Score", manga.Score);
|
||||
eb.AddField("MAL Link", $"https://myanimelist.net/manga/{manga.Id}");
|
||||
eb.Title = manga.Title;
|
||||
eb.Description = description;
|
||||
eb.ImageUrl = manga.ImageURL;
|
||||
eb.AddInlineField("Premiered", $"{manga.StartDate.Value.ToShortDateString()}");
|
||||
eb.AddInlineField("Ended", manga.Publishing ? "Present" : manga.EndDate.Value.ToShortDateString());
|
||||
eb.AddInlineField("Volumes", manga.Volumes);
|
||||
eb.AddInlineField("Chapters", manga.Chapters);
|
||||
eb.AddInlineField("MAL Score", manga.Score);
|
||||
eb.AddField("MAL Link", $"https://myanimelist.net/manga/{manga.MalId}");
|
||||
|
||||
await ReplyAsync("", false, eb.Build());
|
||||
}
|
||||
else
|
||||
{
|
||||
await ReplyAsync("No manga found with that name...");
|
||||
}
|
||||
await ReplyAsync("", false, eb.Build());
|
||||
}
|
||||
else
|
||||
{
|
||||
await ReplyAsync(
|
||||
"Unfortunally i'm not connected to MyAnimeList.net, please tell my senpai to connect me");
|
||||
await ReplyAsync("No manga found with that name...");
|
||||
}
|
||||
}
|
||||
catch (XmlException e)
|
||||
{
|
||||
await _errorHandler.HandleCommandException(e, Context, "The MyAnimeList.net API refused to answer");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
|
|
|
@ -18,7 +18,6 @@ using Geekbot.Core.Highscores;
|
|||
using Geekbot.Core.KvInMemoryStore;
|
||||
using Geekbot.Core.Levels;
|
||||
using Geekbot.Core.Logger;
|
||||
using Geekbot.Core.MalClient;
|
||||
using Geekbot.Core.Media;
|
||||
using Geekbot.Core.RandomNumberGenerator;
|
||||
using Geekbot.Core.ReactionListener;
|
||||
|
@ -159,7 +158,6 @@ namespace Geekbot.Bot
|
|||
_reactionListener = new ReactionListener(_databaseInitializer.Initialize());
|
||||
_guildSettingsManager = new GuildSettingsManager(_databaseInitializer.Initialize());
|
||||
var fortunes = new FortunesProvider(_logger);
|
||||
var malClient = new MalClient(_globalSettings, _logger);
|
||||
var levelCalc = new LevelCalc();
|
||||
var emojiConverter = new EmojiConverter();
|
||||
var mtgManaConverter = new MtgManaConverter();
|
||||
|
@ -176,7 +174,6 @@ namespace Geekbot.Bot
|
|||
services.AddSingleton<IEmojiConverter>(emojiConverter);
|
||||
services.AddSingleton<IFortunesProvider>(fortunes);
|
||||
services.AddSingleton<IMediaProvider>(mediaProvider);
|
||||
services.AddSingleton<IMalClient>(malClient);
|
||||
services.AddSingleton<IMtgManaConverter>(mtgManaConverter);
|
||||
services.AddSingleton<IWikipediaClient>(wikipediaClient);
|
||||
services.AddSingleton<IRandomNumberGenerator>(randomNumberGenerator);
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0-rc.1.*" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0-rc.1.*" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options" Version="5.0.0-rc.1.*" />
|
||||
<PackageReference Include="MyAnimeListSharp" Version="1.3.4" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
<PackageReference Include="NLog" Version="4.7.2" />
|
||||
<PackageReference Include="NLog.Config" Version="4.7.2" />
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
using System.Threading.Tasks;
|
||||
using MyAnimeListSharp.Core;
|
||||
|
||||
namespace Geekbot.Core.MalClient
|
||||
{
|
||||
public interface IMalClient
|
||||
{
|
||||
bool IsLoggedIn();
|
||||
Task<AnimeEntry> GetAnime(string query);
|
||||
Task<MangaEntry> GetManga(string query);
|
||||
}
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
using System.Threading.Tasks;
|
||||
using Geekbot.Core.GlobalSettings;
|
||||
using Geekbot.Core.Logger;
|
||||
using MyAnimeListSharp.Auth;
|
||||
using MyAnimeListSharp.Core;
|
||||
using MyAnimeListSharp.Facade.Async;
|
||||
|
||||
namespace Geekbot.Core.MalClient
|
||||
{
|
||||
public class MalClient : IMalClient
|
||||
{
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
private readonly IGeekbotLogger _logger;
|
||||
private ICredentialContext _credentials;
|
||||
private AnimeSearchMethodsAsync _animeSearch;
|
||||
private MangaSearchMethodsAsync _mangaSearch;
|
||||
|
||||
public MalClient(IGlobalSettings globalSettings, IGeekbotLogger logger)
|
||||
{
|
||||
_globalSettings = globalSettings;
|
||||
_logger = logger;
|
||||
ReloadClient();
|
||||
}
|
||||
|
||||
private bool ReloadClient()
|
||||
{
|
||||
var malCredentials = _globalSettings.GetKey("MalCredentials");
|
||||
if (!string.IsNullOrEmpty(malCredentials))
|
||||
{
|
||||
var credSplit = malCredentials.Split('|');
|
||||
_credentials = new CredentialContext()
|
||||
{
|
||||
UserName = credSplit[0],
|
||||
Password = credSplit[1]
|
||||
};
|
||||
_animeSearch = new AnimeSearchMethodsAsync(_credentials);
|
||||
_mangaSearch = new MangaSearchMethodsAsync(_credentials);
|
||||
_logger.Debug(LogSource.Geekbot, "Logged in to MAL");
|
||||
return true;
|
||||
}
|
||||
_logger.Debug(LogSource.Geekbot, "No MAL Credentials Set!");
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
public bool IsLoggedIn()
|
||||
{
|
||||
return _credentials != null;
|
||||
}
|
||||
|
||||
public async Task<AnimeEntry> GetAnime(string query)
|
||||
{
|
||||
var response = await _animeSearch.SearchDeserializedAsync(query);
|
||||
return response.Entries.Count == 0 ? null : response.Entries[0];
|
||||
}
|
||||
|
||||
public async Task<MangaEntry> GetManga(string query)
|
||||
{
|
||||
var response = await _mangaSearch.SearchDeserializedAsync(query);
|
||||
return response.Entries.Count == 0 ? null : response.Entries[0];
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue