diff --git a/src/Bot/Commands/Integrations/Mal.cs b/src/Bot/Commands/Integrations/Mal.cs index ab8c021..f44d04e 100644 --- a/src/Bot/Commands/Integrations/Mal.cs +++ b/src/Bot/Commands/Integrations/Mal.cs @@ -1,24 +1,25 @@ using System; using System.Linq; +using System.Threading; using System.Threading.Tasks; using System.Web; using Discord; using Discord.Commands; +using Geekbot.Core; using Geekbot.Core.ErrorHandling; using Geekbot.Core.Extensions; +using Geekbot.Core.GuildSettingsManager; using JikanDotNet; namespace Geekbot.Bot.Commands.Integrations { - public class Mal : ModuleBase + public class Mal : GeekbotCommandBase { - private readonly IErrorHandler _errorHandler; private readonly IJikan _client; - public Mal(IErrorHandler errorHandler) + public Mal(IErrorHandler errorHandler, IGuildSettingsManager guildSettingsManager) : base(errorHandler, guildSettingsManager) { _client = new Jikan(); - _errorHandler = errorHandler; } [Command("anime", RunMode = RunMode.Async)] @@ -41,8 +42,8 @@ namespace Geekbot.Bot.Commands.Integrations 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("Premiered", FormatDate(anime.StartDate)); + eb.AddInlineField("Ended", anime.Airing ? "Present" : FormatDate(anime.EndDate)); eb.AddInlineField("Episodes", anime.Episodes); eb.AddInlineField("MAL Score", anime.Score); eb.AddInlineField("Type", anime.Type); @@ -57,7 +58,7 @@ namespace Geekbot.Bot.Commands.Integrations } catch (Exception e) { - await _errorHandler.HandleCommandException(e, Context); + await ErrorHandler.HandleCommandException(e, Context); } } @@ -81,8 +82,8 @@ namespace Geekbot.Bot.Commands.Integrations 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("Premiered", FormatDate(manga.StartDate)); + eb.AddInlineField("Ended", manga.Publishing ? "Present" : FormatDate(manga.EndDate)); eb.AddInlineField("Volumes", manga.Volumes); eb.AddInlineField("Chapters", manga.Chapters); eb.AddInlineField("MAL Score", manga.Score); @@ -97,8 +98,18 @@ namespace Geekbot.Bot.Commands.Integrations } catch (Exception e) { - await _errorHandler.HandleCommandException(e, Context); + await ErrorHandler.HandleCommandException(e, Context); } } + + private string FormatDate(DateTime? dateTime) + { + if (!dateTime.HasValue) + { + return DateTime.MinValue.ToString("d", Thread.CurrentThread.CurrentUICulture); + } + + return dateTime.Value.ToString("d", Thread.CurrentThread.CurrentUICulture); + } } } \ No newline at end of file