Skip to content

Commit 7340307

Browse files
author
Chris Gårdenberg
committed
chore: Test with link on page as well
1 parent 7a2685a commit 7340307

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

CFDiscordBot/Commands/ProjectLookup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ int projectId
184184
}
185185

186186
// If the game is Minecraft Bedrock, we do an additional check if MCPEDL has the mod available through a slug lookup.
187-
if (mod.GameId == 78022)
187+
if (mod.GameId == 78022 && mod.AllowModDistribution.HasValue && mod.AllowModDistribution.Value)
188188
{
189189
var client = httpClientFactory.CreateClient();
190190
client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "CFLookup Discord Bot/1.0; (+cflookup@itssimple.se)");

CFLookup/Pages/Index.cshtml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
@using Microsoft.AspNetCore.Html
44
@using Microsoft.AspNetCore.Http.Extensions
55
@using Newtonsoft.Json
6+
@inject IHttpClientFactory httpClientFactory
67
@model IndexModel
78
@{
89
ViewData["Title"] = "What?";
@@ -37,6 +38,21 @@
3738
{
3839
foundLinks.Add("Source", Model.FoundMod.Links.SourceUrl);
3940
}
41+
42+
// If the game is Minecraft Bedrock, we do an additional check if MCPEDL has the mod available through a slug lookup.
43+
if (Model.FoundMod.GameId == 78022 && Model.FoundMod.AllowModDistribution.HasValue && Model.FoundMod.AllowModDistribution.Value)
44+
{
45+
var client = httpClientFactory.CreateClient();
46+
client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "CFLookup Discord Bot/1.0; (+cflookup@itssimple.se)");
47+
client.BaseAddress = new Uri("https://mcpedl.com/");
48+
49+
var res = await client.GetAsync(Model.FoundMod.Slug);
50+
51+
if (res != null && res.IsSuccessStatusCode && !res.RequestMessage!.RequestUri!.ToString().Contains("notfound"))
52+
{
53+
foundLinks.Add("MCPEDL", $"https://mcpedl.com/{Model.FoundMod.Slug}");
54+
}
55+
}
4056
}
4157
}
4258

0 commit comments

Comments
 (0)