diff options
author | Rory& <root@rory.gay> | 2024-05-30 08:22:50 +0000 |
---|---|---|
committer | Rory& <root@rory.gay> | 2024-05-30 08:22:50 +0000 |
commit | 0fa768556aca00f4346ccd71917fad048def6323 (patch) | |
tree | e6835af94759eac7814aa6d1c718d98d37dfc4a9 /Tests/TestDataGenerator/Bot | |
parent | Log warning if registering a duplicate type (diff) | |
download | LibMatrix-dev/project-cleanup.tar.xz |
Move around some projects, further cleanup pending dev/project-cleanup
Diffstat (limited to 'Tests/TestDataGenerator/Bot')
-rw-r--r-- | Tests/TestDataGenerator/Bot/DataFetcher.cs | 59 | ||||
-rw-r--r-- | Tests/TestDataGenerator/Bot/DataFetcherConfiguration.cs | 9 |
2 files changed, 0 insertions, 68 deletions
diff --git a/Tests/TestDataGenerator/Bot/DataFetcher.cs b/Tests/TestDataGenerator/Bot/DataFetcher.cs deleted file mode 100644 index 66b8a03..0000000 --- a/Tests/TestDataGenerator/Bot/DataFetcher.cs +++ /dev/null @@ -1,59 +0,0 @@ -using ArcaneLibs.Extensions; -using LibMatrix.EventTypes.Spec; -using LibMatrix.Homeservers; -using LibMatrix.RoomTypes; -using LibMatrix.Utilities.Bot; -using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; - -#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously - -namespace TestDataGenerator.Bot; - -public class DataFetcher(AuthenticatedHomeserverGeneric hs, ILogger<DataFetcher> logger, LibMatrixBotConfiguration botConfiguration) : IHostedService { - private Task? _listenerTask; - - private GenericRoom? _logRoom; - - /// <summary>Triggered when the application host is ready to start the service.</summary> - /// <param name="cancellationToken">Indicates that the start process has been aborted.</param> - public async Task StartAsync(CancellationToken cancellationToken) { - _listenerTask = Run(cancellationToken); - logger.LogInformation("Bot started!"); - } - - private async Task Run(CancellationToken cancellationToken) { - Directory.GetFiles("bot_data/cache").ToList().ForEach(File.Delete); - _logRoom = hs.GetRoom(botConfiguration.LogRoom!); - - await _logRoom.SendMessageEventAsync(new RoomMessageEventContent(body: "Test data collector started!")); - await _logRoom.SendMessageEventAsync(new RoomMessageEventContent(body: "Fetching rooms...")); - - var rooms = await hs.GetJoinedRooms(); - await _logRoom.SendMessageEventAsync(new RoomMessageEventContent(body: $"Fetched {rooms.Count} rooms!")); - - await _logRoom.SendMessageEventAsync(new RoomMessageEventContent(body: "Fetching room data...")); - - var roomAliasTasks = rooms.Select(room => room.GetCanonicalAliasAsync()).ToAsyncEnumerable(); - List<Task<(string, string)>> aliasResolutionTasks = new(); - await foreach (var @event in roomAliasTasks) - if (@event?.Alias != null) { - await _logRoom.SendMessageEventAsync(new RoomMessageEventContent(body: $"Fetched room alias {@event.Alias}!")); - aliasResolutionTasks.Add(Task.Run(async () => { - var alias = await hs.ResolveRoomAliasAsync(@event.Alias); - return (@event.Alias, alias.RoomId); - }, cancellationToken)); - } - - var aliasResolutionTaskEnumerator = aliasResolutionTasks.ToAsyncEnumerable(); - await foreach (var result in aliasResolutionTaskEnumerator) - await _logRoom.SendMessageEventAsync(new RoomMessageEventContent(body: $"Resolved room alias {result.Item1} to {result.Item2}!")); - } - - /// <summary>Triggered when the application host is performing a graceful shutdown.</summary> - /// <param name="cancellationToken">Indicates that the shutdown process should no longer be graceful.</param> - public async Task StopAsync(CancellationToken cancellationToken) { - logger.LogInformation("Shutting down bot!"); - _listenerTask?.Dispose(); - } -} \ No newline at end of file diff --git a/Tests/TestDataGenerator/Bot/DataFetcherConfiguration.cs b/Tests/TestDataGenerator/Bot/DataFetcherConfiguration.cs deleted file mode 100644 index 4f53a2a..0000000 --- a/Tests/TestDataGenerator/Bot/DataFetcherConfiguration.cs +++ /dev/null @@ -1,9 +0,0 @@ -using Microsoft.Extensions.Configuration; - -namespace TestDataGenerator.Bot; - -public class DataFetcherConfiguration { - public DataFetcherConfiguration(IConfiguration config) => config.GetRequiredSection("DataFetcher").Bind(this); - - // public string -} \ No newline at end of file |