Skip to content

Commit

Permalink
Merge pull request #19 from EpicOfficer/FEATURE/Wordle
Browse files Browse the repository at this point in the history
Feature/wordle
  • Loading branch information
EpicOfficer authored Apr 10, 2024
2 parents 5747bc6 + f3ef7b2 commit a12a70e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Blink3.Bot/Modules/WordleModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ await RespondErrorAsync("No game in progress",

using MemoryStream image = new();
await wordleGameService.GenerateImageAsync(guess, image);
FileAttachment attachment = new(image, $"{guess.Word}.png");
using FileAttachment attachment = new(image, $"{guess.Word}.png");

ComponentBuilder? component = new ComponentBuilder().WithButton("Define", $"blink-define-word_{guess.Word}");

Expand Down Expand Up @@ -103,7 +103,8 @@ await RespondErrorAsync(word.ToTitleCase(), "An error occured fetching word defi
{
Name = g.Key.ToTitleCase(),
Value = string.Join("\n",
g.Select(v => $"- {v.Definition.ToSentenceCase()}")),
g.Select(v => $"- {v.Definition.ToSentenceCase()}"))
.TruncateTo(1020),
IsInline = false
};
return builder;
Expand Down
12 changes: 12 additions & 0 deletions Blink3.Core/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,16 @@ public static string ToSentenceCase(this string str)
if (string.IsNullOrWhiteSpace(str)) return str;
return char.ToUpper(str[0]) + str[1..].ToLower();
}

/// <summary>
/// Truncates a string to a specified maximum length.
/// </summary>
/// <param name="input">The input string to truncate.</param>
/// <param name="maxLength">The maximum length of the truncated string.</param>
/// <returns>The truncated string.</returns>
public static string TruncateTo(this string input, int maxLength)
{
if (string.IsNullOrEmpty(input)) return input;
return input.Length <= maxLength ? input : string.Concat(input.AsSpan(0, maxLength - 3), "...");
}
}

0 comments on commit a12a70e

Please sign in to comment.