diff options
author | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-06-19 02:36:32 +0200 |
---|---|---|
committer | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-06-19 02:36:32 +0200 |
commit | ed2205972a7b7d6fdd4563c3775a83616920597a (patch) | |
tree | 54aec1cfdf861fd8a7739be131fbe79ae24d91e4 /MatrixRoomUtils.Bot/MRUBot.cs | |
parent | Partial refactor (diff) | |
download | MatrixUtils-ed2205972a7b7d6fdd4563c3775a83616920597a.tar.xz |
Working sync
Diffstat (limited to 'MatrixRoomUtils.Bot/MRUBot.cs')
-rw-r--r-- | MatrixRoomUtils.Bot/MRUBot.cs | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/MatrixRoomUtils.Bot/MRUBot.cs b/MatrixRoomUtils.Bot/MRUBot.cs new file mode 100644 index 0000000..9b2a395 --- /dev/null +++ b/MatrixRoomUtils.Bot/MRUBot.cs @@ -0,0 +1,60 @@ +using System.CodeDom.Compiler; +using System.Diagnostics.CodeAnalysis; +using MatrixRoomUtils.Core; +using MatrixRoomUtils.Core.Extensions; +using MatrixRoomUtils.Core.Helpers; +using MatrixRoomUtils.Core.Responses; +using MatrixRoomUtils.Core.Services; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; + +public class MRUBot : IHostedService { + private readonly HomeserverProviderService _homeserverProviderService; + private readonly ILogger<MRUBot> _logger; + + public MRUBot(HomeserverProviderService homeserverProviderService, ILogger<MRUBot> logger) { + Console.WriteLine("MRUBot hosted service instantiated!"); + _homeserverProviderService = homeserverProviderService; + _logger = logger; + } + + /// <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> + [SuppressMessage("ReSharper", "FunctionNeverReturns")] + public async Task StartAsync(CancellationToken cancellationToken) { + var hs = await _homeserverProviderService.GetAuthenticatedWithToken("rory.gay", "syt_bXJ1Y29yZXRlc3Q_XKUmPswDGZBiLAmFfAut_1iO0KD"); + await (await hs.GetRoom("!DoHEdFablOLjddKWIp:rory.gay")).JoinAsync(); + // #pragma warning disable CS4014 + // Task.Run(async Task? () => { + // #pragma warning restore CS4014 + // while (true) { + // var rooms = await hs.GetJoinedRooms(); + // foreach (var room in rooms) { + // var states = await room.GetStateAsync<List<StateEventResponse>>(""); + // foreach (var state in states) { + // // Console.WriteLine( + // // $"{state.RoomId}: {state.Type}::{state.StateKey} = {ObjectExtensions.ToJson(state.Content, indent: false)}"); + // } + // } + // + // await Task.Delay(1000, cancellationToken); + // } + // }, cancellationToken); + #pragma warning disable CS4014 + Task.Run(async Task? () => { + #pragma warning restore CS4014 + SyncResult? sync = null; + while (true) { + sync = await hs.SyncHelper.Sync(sync?.NextBatch); + _logger.LogInformation($"Got sync, next batch: {sync?.NextBatch}!"); + } + }, cancellationToken); + + } + + /// <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) { + Console.WriteLine("Shutting down bot!"); + } +} \ No newline at end of file |