using System.Net.Http.Headers; using OsuFederatedBeatmapApi.Events.State; using OsuFederatedBeatmapApi.UtilityClasses; namespace OsuFederatedBeatmapApi.Services; public class BeatmapFetcherService(FederatedBeatmapApiBotAccountDataService ads) { public async Task FetchBeatmapSetInfo(int id) { var hc = new HttpClient(); hc.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("OsuFederatedBeatmapApi", "1.0")); var res = await hc.GetFromJsonAsync($"https://osu.direct/api/s/{id}"); var info = new BeatmapSetInfo { Title = res.Title, Artist = res.Artist, Creator = res.Creator, Beatmaps = res.ChildrenBeatmaps.ToDictionary(b => b.BeatmapID, b => new BeatmapSetInfo.BeatmapInfo { Difficulty = b.DiffName, Mode = b.Mode, DifficultyRating = b.DifficultyRating, TotalLength = b.TotalLength, BPM = b.BPM, MaxCombo = b.MaxCombo }) }; await ads.LoadAccountDataAsync(); await ads.OwnBeatmapRepositoryRoom.SendStateEventAsync(BeatmapSetInfo.EventName, id.ToString(), info); return info; } }