Skip to content

Commit

Permalink
Enhance APOD module
Browse files Browse the repository at this point in the history
  • Loading branch information
monambike committed Feb 12, 2024
1 parent 19bf21d commit 6ad4261
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions src/Models/Nasa.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using DSharpPlus.Entities;
using KWiJisho.APIs;
using KWiJisho.Utils;
using System;
using System.Threading.Tasks;
using static KWiJisho.APIs.NasaApi.Apod;
Expand All @@ -20,7 +21,7 @@ internal static DiscordEmbedBuilder BuildEnglishApodMessageAsync(ApodResponse ap
TitleField = "IMAGE OF THE DAY",
TitleContent = apodResponse.Title,
// Explanation
ExplanationField = "Read the following history according to the image",
ExplanationField = "Read the following history related to the image",
ExplanationContent = apodResponse.Explanation,
// Image
ImageUrlContent = apodResponse.Url,
Expand Down Expand Up @@ -51,10 +52,11 @@ internal static async Task<DiscordEmbedBuilder> BuildPortugueseApodMessageAsync(
// Translate the summarized explanation to Portuguese.
var translatedExplanation = await ChatGPT.GetPromptTranslateToPortugueseAsync(summarizedExplanation);
// Format the translated explanation by adding new lines after each sentence.
var formattedExplanation = translatedExplanation.Replace(". ", "." + Environment.NewLine);
var formattedExplanation = translatedExplanation;
// The final formatted explanation ready for use.
var explanation = formattedExplanation;


// Building the portuguese APOD message
var portugueseApodBuilder = new ApodBuilder
{
Expand Down Expand Up @@ -144,18 +146,30 @@ internal class ApodBuilder
internal DiscordEmbedBuilder GetDiscordEmbedBuilder()
{
// Creating copyright message.
var copyright = string.IsNullOrEmpty(CopyrightContent) ? NullCopyrightField : CopyrightContent;
var copyright = string.IsNullOrEmpty(CopyrightContent) ? NullCopyrightField : CopyrightContent.Replace("\n", "");

// Formatting explanation content, where's a full stop makes a new paragraph
var explanationContent = ExplanationContent.Replace(". ", "." + Environment.NewLine + Environment.NewLine);

DiscordEmbedBuilder discordEmbedBuilder = new();
// Creating embed builder.
var discordEmbedBuilder = new DiscordEmbedBuilder
try
{
Title = $"({TitleField}) {TitleContent.ToUpper()}",
Color = Data.ConfigJson.DefaultColor.DiscordColor,
Footer = new DiscordEmbedBuilder.EmbedFooter
discordEmbedBuilder = new DiscordEmbedBuilder
{
Text = $"Copyright: {copyright.Replace("\n", "")}{DateField}: {DateContent.Date.ToString(DateFormat)}",
}
}.WithImageUrl(ImageUrlContent).AddField($"👇🏻 {ExplanationField}", $"{Environment.NewLine}{ExplanationContent}");
Title = $"({TitleField}) {TitleContent.ToUpper()}",
Description = $"👇🏻 {ExplanationField.ToDiscordBold().ToUpper()}{Environment.NewLine + Environment.NewLine}{explanationContent}",
Color = Data.ConfigJson.DefaultColor.DiscordColor,
Footer = new DiscordEmbedBuilder.EmbedFooter
{
Text = $"Copyright: {copyright}{DateField}: {DateContent.Date.ToString(DateFormat)}",
}
}.WithImageUrl(ImageUrlContent);
}
catch (Exception ex)
{

}

// Returning the formatted discord embed builder
return discordEmbedBuilder;
Expand Down

0 comments on commit 6ad4261

Please sign in to comment.