Skip to content

Commit 81a6ca3

Browse files
committed
feat: Ability to see if the file is installable for World of Warcraft based on looking at modules for .toc-files
1 parent 388b282 commit 81a6ca3

File tree

2 files changed

+60
-17
lines changed

2 files changed

+60
-17
lines changed

CFDiscordBot/Commands/FileLookup.cs

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,17 @@ int fileId
1414
)
1515
{
1616
CurseForge.APIClient.Models.Mods.Mod? mod = null;
17+
CurseForge.APIClient.Models.Files.File? file = null;
1718
var projectId = 0;
1819
try
1920
{
20-
var projectFiles = await apiClient.GetFilesAsync(new CurseForge.APIClient.Models.Files.GetModFilesRequestBody { FileIds = [fileId] });
21+
var projectFiles =
22+
await apiClient.GetFilesAsync(new CurseForge.APIClient.Models.Files.GetModFilesRequestBody
23+
{ FileIds = [fileId] });
2124
if (projectFiles.Data.Count > 0)
2225
{
23-
var project = await apiClient.GetModAsync(projectFiles.Data.First().ModId);
26+
file = projectFiles.Data.First();
27+
var project = await apiClient.GetModAsync(file.ModId);
2428
mod = project.Data;
2529
projectId = project.Data.Id;
2630
}
@@ -68,14 +72,23 @@ int fileId
6872

6973
var categories = string.Join(", ", mod.Categories.Select(c => $"[{c.Name}]({c.Url})"));
7074

71-
var fields = new List<EmbedFieldBuilder> {
72-
new() { Name = "Author", Value = string.Join(", ", mod.Authors.Select(c => $"[{c.Name}]({c.Url})")), IsInline = true },
75+
var fields = new List<EmbedFieldBuilder>
76+
{
77+
new()
78+
{
79+
Name = "Author", Value = string.Join(", ", mod.Authors.Select(c => $"[{c.Name}]({c.Url})")),
80+
IsInline = true
81+
},
7382
new() { Name = "Status", Value = mod.Status.ToString(), IsInline = true },
7483
new() { Name = "Created", Value = $"<t:{mod.DateCreated.ToUnixTimeSeconds()}:F>", IsInline = true },
7584
new() { Name = "Modified", Value = $"<t:{mod.DateModified.ToUnixTimeSeconds()}:F>", IsInline = true },
7685
new() { Name = "Released", Value = $"<t:{mod.DateReleased.ToUnixTimeSeconds()}:F>", IsInline = true },
7786
new() { Name = "Downloads", Value = mod.DownloadCount.ToString("n0"), IsInline = true },
78-
new() { Name = "Mod Distribution", Value = mod.AllowModDistribution ?? true ? "Allowed" : "Not allowed", IsInline = true },
87+
new()
88+
{
89+
Name = "Mod Distribution", Value = mod.AllowModDistribution ?? true ? "Allowed" : "Not allowed",
90+
IsInline = true
91+
},
7992
new() { Name = "Is available", Value = mod.IsAvailable ? "Yes" : "No", IsInline = true }
8093
};
8194

@@ -84,11 +97,24 @@ int fileId
8497
fields.Add(new EmbedFieldBuilder { Name = "Categories", Value = categories, IsInline = false });
8598
}
8699

100+
if (file is { GameId: 1 })
101+
{
102+
fields.Add(new EmbedFieldBuilder
103+
{
104+
Name = "Installable",
105+
Value = file.Modules.Any(m => m.Name.EndsWith(".toc"))
106+
? "No, potentially invalid file structure"
107+
: "Yes",
108+
IsInline = false
109+
});
110+
}
111+
87112
projectEmbed.Fields.AddRange(fields);
88113

89114
projectEmbed.Footer = new EmbedFooterBuilder
90115
{
91-
IconUrl = "https://cdn.discordapp.com/avatars/1199770925025984513/3f52d33635a688cfd24f0d78272aaf00.png?size=256",
116+
IconUrl =
117+
"https://cdn.discordapp.com/avatars/1199770925025984513/3f52d33635a688cfd24f0d78272aaf00.png?size=256",
92118
Text = "CurseForge"
93119
};
94120

@@ -148,26 +174,28 @@ int fileId
148174
if (mod.GameId == 78022 && mod.AllowModDistribution.HasValue && mod.AllowModDistribution.Value)
149175
{
150176
var client = httpClientFactory.CreateClient();
151-
client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "CFLookup Discord Bot/1.0; (+cflookup@itssimple.se)");
177+
client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent",
178+
"CFLookup Discord Bot/1.0; (+cflookup@itssimple.se)");
152179
client.BaseAddress = new Uri("https://mcpedl.com/");
153180

154181
var res = await client.GetAsync(mod.Slug);
155182

156-
if (res != null && res.IsSuccessStatusCode && !res.RequestMessage!.RequestUri!.ToString().Contains("notfound"))
183+
if (res != null && res.IsSuccessStatusCode &&
184+
!res.RequestMessage!.RequestUri!.ToString().Contains("notfound"))
157185
{
158186
buttons.WithButton(
159-
style: ButtonStyle.Link,
160-
label: "MCPEDL",
161-
url: $"https://mcpedl.com/{mod.Slug}"
162-
);
187+
style: ButtonStyle.Link,
188+
label: "MCPEDL",
189+
url: $"https://mcpedl.com/{mod.Slug}"
190+
);
163191
}
164192
}
165193

166194
await RespondAsync($"Project `{projectId}` is: **[{mod.Name}](https://cflookup.com/{projectId})**\n" +
167-
$"{summaryText}",
195+
$"{summaryText}",
168196
embeds: new[] { projectEmbed.Build() },
169197
components: buttons.Build()
170198
);
171199
}
172200
}
173-
}
201+
}

CFLookup/Pages/Index.cshtml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,24 @@
391391
}
392392
<td>@file.GameVersion</td>
393393
<td>
394-
<div class="cf-install-button" title="Install with CurseForge">
395-
<a href="curseforge://install?addonId=@Model.FoundMod.Id&fileId=@file.FileId" target="_blank">Install</a>
396-
</div>
394+
@{
395+
var installable = true;
396+
if (Model.FoundMod.GameId == 1)
397+
{
398+
installable = !modFile.Modules.Any(m => m.Name.EndsWith(".toc"));
399+
}
400+
}
401+
402+
@if(installable)
403+
{
404+
<div class="cf-install-button" title="Install with CurseForge">
405+
<a href="curseforge://install?addonId=@Model.FoundMod.Id&fileId=@file.FileId" target="_blank">Install</a>
406+
</div>
407+
}
408+
else
409+
{
410+
<em>Not installable (problem with file)</em>
411+
}
397412
</td>
398413
</tr>
399414
}

0 commit comments

Comments
 (0)