-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Attempt to make !timeleft a bit more accurate
- Loading branch information
Showing
3 changed files
with
79 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
namespace BanchoMultiplayerBot.Utilities; | ||
|
||
public class BeatmapParser | ||
{ | ||
|
||
// Attempt to find the first hit object in seconds, relies on the map being downloaded beforehand | ||
public static async Task<int?> GetBeatmapStartTime(int beatmapId) | ||
{ | ||
const string cacheDir = $"cache"; | ||
var beatmapFilePath = $"{cacheDir}/{beatmapId}.osu"; | ||
|
||
try | ||
{ | ||
if (!File.Exists(beatmapFilePath)) | ||
{ | ||
return null; | ||
} | ||
|
||
var inHitObjectsSection = false; | ||
foreach (var line in await File.ReadAllLinesAsync(beatmapFilePath)) | ||
{ | ||
if (!line.Any()) | ||
{ | ||
continue; | ||
} | ||
|
||
if (line.StartsWith("[HitObjects]")) | ||
{ | ||
inHitObjectsSection = true; | ||
continue; | ||
} | ||
|
||
if (!inHitObjectsSection) | ||
{ | ||
continue; | ||
} | ||
|
||
return int.Parse(line.Split(',')[2]) / 1000; | ||
} | ||
} | ||
catch (Exception) | ||
{ | ||
// ignored | ||
} | ||
|
||
return null; | ||
} | ||
|
||
|
||
} |