Skip to content

Commit e62ffef

Browse files
author
Chris Gårdenberg
committed
feat: Add MCPEDL-button if the project is available there (only Minecraft Bedrock)
fixes #21
1 parent 4f00d47 commit e62ffef

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

CFDiscordBot/CFDiscordBot.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<ItemGroup>
1111
<PackageReference Include="CurseForge.APIClient" Version="4.2.0" />
12-
<PackageReference Include="Discord.Net" Version="3.17.2" />
12+
<PackageReference Include="Discord.Net" Version="3.17.4" />
1313
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.4" />
1414
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="9.0.4" />
1515
</ItemGroup>

CFDiscordBot/Commands/Lookup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
namespace CFDiscordBot.Commands
55
{
66
[Group("lookup", "Does lookups against CurseForge")]
7-
public partial class Lookup(ApiClient apiClient) : InteractionModuleBase<ShardedInteractionContext> { }
7+
public partial class Lookup(ApiClient apiClient, IHttpClientFactory httpClientFactory) : InteractionModuleBase<ShardedInteractionContext> { }
88
}

CFDiscordBot/Commands/ProjectLookup.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,25 @@ int projectId
183183
);
184184
}
185185

186+
// 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)
188+
{
189+
var client = httpClientFactory.CreateClient();
190+
client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "CFLookup Discord Bot/1.0; (+cflookup@itssimple.se)");
191+
client.BaseAddress = new Uri("https://mcpedl.com/");
192+
193+
var res = await client.GetAsync(mod.Slug);
194+
195+
if (res != null && res.IsSuccessStatusCode && !res.RequestMessage!.RequestUri!.ToString().Contains("notfound"))
196+
{
197+
buttons.WithButton(
198+
style: ButtonStyle.Link,
199+
label: "MCPEDL",
200+
url: $"https://mcpedl.com/{mod.Slug}"
201+
);
202+
}
203+
}
204+
186205
await RespondAsync($"Project `{projectId}` is: **[{mod.Name}](https://cflookup.com/{projectId})**\n" +
187206
$"{summaryText}",
188207
embeds: new[] { projectEmbed.Build() },

0 commit comments

Comments
 (0)