diff --git a/Utilities/LibMatrix.HomeserverEmulator/Services/RoomStore.cs b/Utilities/LibMatrix.HomeserverEmulator/Services/RoomStore.cs
index c15fe7d..b6fe7c2 100644
--- a/Utilities/LibMatrix.HomeserverEmulator/Services/RoomStore.cs
+++ b/Utilities/LibMatrix.HomeserverEmulator/Services/RoomStore.cs
@@ -120,7 +120,7 @@ public class RoomStore {
public Room(string roomId) {
if (string.IsNullOrWhiteSpace(roomId)) throw new ArgumentException("Value cannot be null or whitespace.", nameof(roomId));
- if (roomId[0] != '!') throw new ArgumentException("Room ID must start with !", nameof(roomId));
+ if (roomId[0] != '!') throw new ArgumentException($"Room ID must start with '!', provided value: {roomId ?? "null"}", nameof(roomId));
RoomId = roomId;
Timeline = new();
AccountData = new();
diff --git a/Utilities/LibMatrix.Utilities.Bot/BotCommandInstaller.cs b/Utilities/LibMatrix.Utilities.Bot/BotCommandInstaller.cs
index ca6a4d8..8501d41 100644
--- a/Utilities/LibMatrix.Utilities.Bot/BotCommandInstaller.cs
+++ b/Utilities/LibMatrix.Utilities.Bot/BotCommandInstaller.cs
@@ -18,7 +18,7 @@ public class BotInstaller(IServiceCollection services) {
public BotInstaller AddMatrixBot() {
services.AddSingleton<LibMatrixBotConfiguration>();
- services.AddScoped<AuthenticatedHomeserverGeneric>(x => {
+ services.AddSingleton<AuthenticatedHomeserverGeneric>(x => {
var config = x.GetService<LibMatrixBotConfiguration>() ?? throw new Exception("No configuration found!");
var hsProvider = x.GetService<HomeserverProviderService>() ?? throw new Exception("No homeserver provider found!");
diff --git a/Utilities/LibMatrix.Utilities.Bot/Services/CommandListenerHostedService.cs b/Utilities/LibMatrix.Utilities.Bot/Services/CommandListenerHostedService.cs
index b5b5a2b..d07090f 100644
--- a/Utilities/LibMatrix.Utilities.Bot/Services/CommandListenerHostedService.cs
+++ b/Utilities/LibMatrix.Utilities.Bot/Services/CommandListenerHostedService.cs
@@ -1,3 +1,4 @@
+using ArcaneLibs.Extensions;
using LibMatrix.EventTypes.Spec;
using LibMatrix.EventTypes.Spec.State.RoomInfo;
using LibMatrix.Filters;
@@ -57,22 +58,44 @@ public class CommandListenerHostedService : IHostedService {
FilterId = filter
};
- syncHelper.TimelineEventHandlers.Add(async @event => {
- try {
- var room = _hs.GetRoom(@event.RoomId);
- // _logger.LogInformation(eventResponse.ToJson(indent: false));
- if (@event is { Type: "m.room.message", TypedContent: RoomMessageEventContent message })
- if (message is { MessageType: "m.text" }) {
- var usedPrefix = await GetUsedPrefix(@event);
- if (usedPrefix is null) return;
- var res = await InvokeCommand(@event, usedPrefix);
- await (_commandResultHandler?.Invoke(res) ?? HandleResult(res));
+ syncHelper.SyncReceivedHandlers.Add(async sync => {
+ _logger.LogInformation("Sync received!");
+ foreach (var roomResp in sync.Rooms?.Join ?? []) {
+ if (roomResp.Value.Timeline?.Events is null or { Count: > 5 }) continue;
+ foreach (var @event in roomResp.Value.Timeline.Events) {
+ @event.RoomId = roomResp.Key;
+ try {
+ // var room = _hs.GetRoom(@event.RoomId);
+ // _logger.LogInformation(eventResponse.ToJson(indent: false));
+ if (@event is { Type: "m.room.message", TypedContent: RoomMessageEventContent message })
+ if (message is { MessageType: "m.text" }) {
+ var usedPrefix = await GetUsedPrefix(@event);
+ if (usedPrefix is null) return;
+ var res = await InvokeCommand(@event, usedPrefix);
+ await (_commandResultHandler?.Invoke(res) ?? HandleResult(res));
+ }
}
- }
- catch (Exception e) {
- _logger.LogError(e, "Error in command listener!");
+ catch (Exception e) {
+ _logger.LogError(e, "Error in command listener!");
+ Console.WriteLine(@event.ToJson(ignoreNull: false, indent: true));
+ var fakeResult = new CommandResult() {
+ Result = CommandResult.CommandResultType.Failure_Exception,
+ Exception = e,
+ Success = false,
+ Context = new() {
+ Homeserver = _hs,
+ CommandName = "[CommandListener.SyncHandler]",
+ Room = _hs.GetRoom(roomResp.Key),
+ Args = [],
+ MessageEvent = @event
+ }
+ };
+ await (_commandResultHandler?.Invoke(fakeResult) ?? HandleResult(fakeResult));
+ }
+ }
}
});
+
await syncHelper.RunSyncLoopAsync(cancellationToken: cancellationToken);
}
|