Skip to content

Commit

Permalink
- fix donald lambert's name not being autodetected by d#+
Browse files Browse the repository at this point in the history
  • Loading branch information
Pannoniae committed Aug 21, 2023
1 parent 2817a47 commit 7b7c332
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 309 deletions.
2 changes: 1 addition & 1 deletion .idea/.idea.EconomyBot/.idea/dataSources.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

139 changes: 34 additions & 105 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions EconomyBot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,25 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Update="bot.db">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="config.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Launch.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Lavalink.jar">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="application.yml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>


<ItemGroup>
<Folder Include="lua\" />
<Folder Include="py\" />
</ItemGroup>

</Project>
2 changes: 2 additions & 0 deletions Launch.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Start-Process dotnet EconomyBot.dll
Start-Process "java" -ArgumentList "-jar Lavalink.jar"
15 changes: 15 additions & 0 deletions Music/GuildMusicData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,24 @@ public async Task<IEnumerable<LavalinkLoadResult>> getJazz(string searchTerm) {

public async Task<LavalinkLoadResult> getTracksAsync(LavalinkRestClient client, FileInfo file) {
var tracks = await client.GetTracksAsync(file);

// This is a typical example of bad cargo-cult programming. I am leaving it in because it doesn't matter,
// but this is how programs get slow.
// The naive programmer would think that filtering with where is cheap.
// The naive programmer doesn't think about the fact that it traverses the entire array or list.
// Instead of converting it to a proper imperative loop, writing a helper for concatenating the two conditions,
// or using a better language, we just copypaste the loop and hope for the best.
foreach (var track in tracks.Tracks.Where(track => track.Title == "Unknown title")) {
track.GetType().GetProperty("Title")!.SetValue(track, Path.GetFileNameWithoutExtension(file.Name));
}
foreach (var track in tracks.Tracks.Where(track => track.Author == "Unknown artist")) {
// Here's another terrible hack due to .NET's abysmal directory handling.
// This just gets the directory of the file, then misuses GetFileName to return the last part of it (the parent directory's name)
// Not to mention that we are literally reflecting the Track object because the stupid authors thought
// their autodetection was infallible thus they haven't provided a way to properly set the track's name which will be displayed.
// The end-user is probably not very delighted at seeing "unknown author" or "unknown title" so we make a best-effort guess here.
track.GetType().GetProperty("Author")!.SetValue(track, Path.GetFileName(Path.GetDirectoryName(file.Name)));
}

return tracks;
}
Expand Down
Binary file modified bot.db
Binary file not shown.
Loading

0 comments on commit 7b7c332

Please sign in to comment.