diff options
Diffstat (limited to 'OsuFederatedBeatmapApi')
7 files changed, 37 insertions, 16 deletions
diff --git a/OsuFederatedBeatmapApi/Controllers/BeatmapRepositoryController.cs b/OsuFederatedBeatmapApi/Controllers/BeatmapRepositoryController.cs index 6c2bd31..6a1149d 100644 --- a/OsuFederatedBeatmapApi/Controllers/BeatmapRepositoryController.cs +++ b/OsuFederatedBeatmapApi/Controllers/BeatmapRepositoryController.cs @@ -1,24 +1,33 @@ using Microsoft.AspNetCore.Mvc; using OsuFederatedBeatmapApi.Events.State; +using OsuFederatedBeatmapApi.Services; namespace OsuFederatedBeatmapApi.Controllers; [ApiController] [Route("/")] -public class BeatmapRepositoryController(ILogger<BeatmapRepositoryController> logger, ) : ControllerBase { - +public class BeatmapRepositoryController(ILogger<BeatmapRepositoryController> logger, FederatedBeatmapApiBotAccountDataService ads) : ControllerBase { [HttpGet("/beatmapset/all/info")] public async IAsyncEnumerable<BeatmapSetInfo> GetAllInfo() { + await ads.LoadAccountDataAsync(); + foreach (var repo in ads.ListedRepositories) { + var states = repo.GetFullStateAsync(); + await foreach (var state in states) { + if (state?.TypedContent is BeatmapSetInfo info) yield return info; + } + } } - [HttpGet("/beatmapset/{id:int}/info")] - public IEnumerable<WeatherForecast> Get(int id) { - return Enumerable.Range(1, 5).Select(index => new WeatherForecast { - Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)), - TemperatureC = Random.Shared.Next(-20, 55), - Summary = Summaries[Random.Shared.Next(Summaries.Length)] - }) - .ToArray(); - } + [HttpGet("/beatmapset/{id:int}/info")] + public async Task<BeatmapSetInfo?> Get(int id) { + await ads.LoadAccountDataAsync(); + + foreach (var repo in ads.ListedRepositories) { + var states = await repo.GetStateAsync<BeatmapSetInfo>("gay.rory.beatmap_api.beatmap_set_info", id.ToString()); + return states as BeatmapSetInfo; + } + + return null; + } } diff --git a/OsuFederatedBeatmapApi/Events/AccountData/BotData.cs b/OsuFederatedBeatmapApi/Events/AccountData/BotData.cs index 0c9744a..1eccf03 100644 --- a/OsuFederatedBeatmapApi/Events/AccountData/BotData.cs +++ b/OsuFederatedBeatmapApi/Events/AccountData/BotData.cs @@ -8,4 +8,7 @@ public class BotData { [JsonPropertyName("log_room")] public string? LogRoom { get; set; } = ""; + + [JsonPropertyName("listed_repositories")] + public List<string> ListedRepositories { get; set; } = new(); } diff --git a/OsuFederatedBeatmapApi/Events/State/BeatmapSetInfo.cs b/OsuFederatedBeatmapApi/Events/State/BeatmapSetInfo.cs index 2c9367e..8cfcf0d 100644 --- a/OsuFederatedBeatmapApi/Events/State/BeatmapSetInfo.cs +++ b/OsuFederatedBeatmapApi/Events/State/BeatmapSetInfo.cs @@ -1,10 +1,11 @@ using LibMatrix; using LibMatrix.EventTypes; +using LibMatrix.Interfaces; namespace OsuFederatedBeatmapApi.Events.State; [MatrixEvent(EventName = "gay.rory.beatmap_api.beatmap_set_info")] -public class BeatmapSetInfo : StateEvent { +public class BeatmapSetInfo : EventContent { diff --git a/OsuFederatedBeatmapApi/Program.cs b/OsuFederatedBeatmapApi/Program.cs index 27175f1..15f9b12 100644 --- a/OsuFederatedBeatmapApi/Program.cs +++ b/OsuFederatedBeatmapApi/Program.cs @@ -21,7 +21,8 @@ builder.Services.AddScoped<TieredStorageService>(x => builder.Services.AddRoryLibMatrixServices(); builder.Services.AddBot(withCommands: true); -builder.Services.AddSingleton<FederatedBeatmapApiBotAccountDataService>(); +builder.Services.AddSingleton<FederatedBeatmapApiBotConfiguration>(); +builder.Services.AddScoped<FederatedBeatmapApiBotAccountDataService>(); builder.Services.AddHostedService<FederatedBeatmapApiBot>(); var app = builder.Build(); diff --git a/OsuFederatedBeatmapApi/Services/FederatedBeatmapApiBot.cs b/OsuFederatedBeatmapApi/Services/FederatedBeatmapApiBot.cs index 2b39d93..04d64ad 100644 --- a/OsuFederatedBeatmapApi/Services/FederatedBeatmapApiBot.cs +++ b/OsuFederatedBeatmapApi/Services/FederatedBeatmapApiBot.cs @@ -45,6 +45,9 @@ public class FederatedBeatmapApiBot(AuthenticatedHomeserverGeneric hs, }, cancellationToken); #pragma warning restore CS4014 + foreach (var inviteTask in admins.Select(x=>accountDataService.ControlRoom.InviteUserAsync(x))) await inviteTask; + foreach (var inviteTask in admins.Select(x=>accountDataService.LogRoom.InviteUserAsync(x))) await inviteTask; + syncHelper.InviteReceivedHandlers.Add(async Task (args) => { var inviteEvent = args.Value.InviteState.Events.FirstOrDefault(x => @@ -69,7 +72,9 @@ public class FederatedBeatmapApiBot(AuthenticatedHomeserverGeneric hs, logger.LogInformation( "Got timeline event in {}: {}", @event.RoomId, @event.ToJson(indent: true, ignoreNull: true)); - if (@event is { Type: "m.room.message", TypedContent: RoomMessageEventContent message }) { } + if (@event is { Type: "m.room.message", TypedContent: RoomMessageEventContent message }) { + + } } catch (Exception e) { logger.LogError("{}", e.ToString()); diff --git a/OsuFederatedBeatmapApi/Services/FederatedBeatmapApiBotAccountDataService.cs b/OsuFederatedBeatmapApi/Services/FederatedBeatmapApiBotAccountDataService.cs index 0f4aa6a..37b0d67 100644 --- a/OsuFederatedBeatmapApi/Services/FederatedBeatmapApiBotAccountDataService.cs +++ b/OsuFederatedBeatmapApi/Services/FederatedBeatmapApiBotAccountDataService.cs @@ -12,9 +12,10 @@ public class FederatedBeatmapApiBotAccountDataService(ILogger<FederatedBeatmapAp public GenericRoom LogRoom; public GenericRoom ControlRoom; + public List<GenericRoom> ListedRepositories; private BotData botData; - public async Task LoadAccountData() { + public async Task LoadAccountDataAsync() { try { botData = await hs.GetAccountDataAsync<BotData>(BotDataKey); } @@ -56,5 +57,6 @@ public class FederatedBeatmapApiBotAccountDataService(ILogger<FederatedBeatmapAp LogRoom = hs.GetRoom(botData.LogRoom ?? botData.ControlRoom); ControlRoom = hs.GetRoom(botData.ControlRoom); + ListedRepositories = botData.ListedRepositories.Select(hs.GetRoom).ToList(); } } diff --git a/OsuFederatedBeatmapApi/appsettings.Development.json b/OsuFederatedBeatmapApi/appsettings.Development.json index 600efc3..0f6f318 100644 --- a/OsuFederatedBeatmapApi/appsettings.Development.json +++ b/OsuFederatedBeatmapApi/appsettings.Development.json @@ -14,7 +14,7 @@ // The command prefix "Prefix": "?" }, - "MediaMod": { + "BeatmapApiBot": { // List of people who should be invited to the control room "Admins": [ "@emma:conduit.rory.gay", |