Skip to content

Commit

Permalink
fix: Handle missing game
Browse files Browse the repository at this point in the history
  • Loading branch information
itssimple committed Feb 2, 2024
1 parent 076aa54 commit 0edb3ef
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 354 deletions.
25 changes: 17 additions & 8 deletions CFDiscordBot/Commands/GameLookup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,18 @@ public async Task GameIdAsync(
int gameId
)
{
var game = await apiClient.GetGameAsync(gameId);
CurseForge.APIClient.Models.Games.Game gameInfo = null;

Check warning on line 14 in CFDiscordBot/Commands/GameLookup.cs

View workflow job for this annotation

GitHub Actions / generate

Converting null literal or possible null value to non-nullable type.
try
{
var game = await apiClient.GetGameAsync(gameId);
gameInfo = game.Data;
}
catch
{
// Empty because, ugh
}

if (game is null)
if (gameInfo is null)
{
await RespondAsync($"Game with id {gameId} was not found.", ephemeral: true);

Expand All @@ -25,19 +34,19 @@ int gameId
var mods = await apiClient.SearchModsAsync(gameId, pageSize: 1);

var embed = new EmbedBuilder()
.WithTitle(game.Data.Name)
.WithTitle(gameInfo.Name)
.WithDescription($"This game has {mods.Pagination.TotalCount:n0} mods available on CurseForge.")
.WithUrl($"https://www.curseforge.com/{game.Data.Slug}")
.WithUrl($"https://www.curseforge.com/{gameInfo.Slug}")
.WithColor(Color.DarkOrange);

if (!string.IsNullOrWhiteSpace(game.Data.Assets.IconUrl))
if (!string.IsNullOrWhiteSpace(gameInfo.Assets.IconUrl))
{
embed.WithThumbnailUrl(game.Data.Assets.IconUrl);
embed.WithThumbnailUrl(gameInfo.Assets.IconUrl);
}

if (!string.IsNullOrWhiteSpace(game.Data.Assets.CoverUrl))
if (!string.IsNullOrWhiteSpace(gameInfo.Assets.CoverUrl))
{
embed.WithImageUrl(game.Data.Assets.CoverUrl);
embed.WithImageUrl(gameInfo.Assets.CoverUrl);
}

await RespondAsync(embeds: new[] { embed.Build() }, ephemeral: true);
Expand Down
346 changes: 0 additions & 346 deletions CFLookup/DiscordController.cs

This file was deleted.

0 comments on commit 0edb3ef

Please sign in to comment.