about summary refs log tree commit diff
path: root/MatrixRoomUtils.Bot/Bot/MRUBot.cs
diff options
context:
space:
mode:
authorTheArcaneBrony <myrainbowdash949@gmail.com>2023-07-02 01:01:09 +0200
committerTheArcaneBrony <myrainbowdash949@gmail.com>2023-07-02 01:01:09 +0200
commitdef33cc092ae2c6defcc218b108b7c99cbfb8581 (patch)
treeba992ff8c30b7d4e8af0a78350e157e095455a18 /MatrixRoomUtils.Bot/Bot/MRUBot.cs
parentDeduplicate some api calls (diff)
downloadMatrixUtils-def33cc092ae2c6defcc218b108b7c99cbfb8581.tar.xz
Prefetch room info
Diffstat (limited to 'MatrixRoomUtils.Bot/Bot/MRUBot.cs')
-rw-r--r--MatrixRoomUtils.Bot/Bot/MRUBot.cs57
1 files changed, 28 insertions, 29 deletions
diff --git a/MatrixRoomUtils.Bot/Bot/MRUBot.cs b/MatrixRoomUtils.Bot/Bot/MRUBot.cs
index 134019a..adf825d 100644
--- a/MatrixRoomUtils.Bot/Bot/MRUBot.cs
+++ b/MatrixRoomUtils.Bot/Bot/MRUBot.cs
@@ -1,16 +1,15 @@
-using System.Diagnostics;
 using System.Diagnostics.CodeAnalysis;
-using MatrixRoomUtils.Bot;
-using MatrixRoomUtils.Bot.Interfaces;
+using MatrixRoomUtils.Bot.Bot.Interfaces;
 using MatrixRoomUtils.Core;
 using MatrixRoomUtils.Core.Extensions;
-using MatrixRoomUtils.Core.Helpers;
 using MatrixRoomUtils.Core.Services;
-using MatrixRoomUtils.Core.StateEventTypes;
+using MatrixRoomUtils.Core.StateEventTypes.Spec;
 using Microsoft.Extensions.DependencyInjection;
 using Microsoft.Extensions.Hosting;
 using Microsoft.Extensions.Logging;
 
+namespace MatrixRoomUtils.Bot.Bot; 
+
 public class MRUBot : IHostedService {
     private readonly HomeserverProviderService _homeserverProviderService;
     private readonly ILogger<MRUBot> _logger;
@@ -75,32 +74,32 @@ public class MRUBot : IHostedService {
 
             var room = await hs.GetRoom(@event.RoomId);
             // _logger.LogInformation(eventResponse.ToJson(indent: false));
-            if (@event is { Type: "m.room.message", TypedContent: MessageEventData message }) {
+            if (@event is { Type: "m.room.message", TypedContent: RoomMessageEventData message }) {
                 if (message is { MessageType: "m.text" } && message.Body.StartsWith(_configuration.Prefix)) {
                     
-                        var command = _commands.FirstOrDefault(x => x.Name == message.Body.Split(' ')[0][_configuration.Prefix.Length..]);
-                        if (command == null) {
-                            await room.SendMessageEventAsync("m.room.message",
-                                new MessageEventData() {
-                                    MessageType = "m.text",
-                                    Body = "Command not found!"
-                                });
-                            return;
-                        }
-                        var ctx = new CommandContext() {
-                            Room = room,
-                            MessageEvent = @event
-                        };
-                        if (await command.CanInvoke(ctx)) {
-                            await command.Invoke(ctx);
-                        }
-                        else {
-                            await room.SendMessageEventAsync("m.room.message",
-                                new MessageEventData() {
-                                    MessageType = "m.text",
-                                    Body = "You do not have permission to run this command!"
-                                });
-                        }
+                    var command = _commands.FirstOrDefault(x => x.Name == message.Body.Split(' ')[0][_configuration.Prefix.Length..]);
+                    if (command == null) {
+                        await room.SendMessageEventAsync("m.room.message",
+                            new RoomMessageEventData() {
+                                MessageType = "m.text",
+                                Body = "Command not found!"
+                            });
+                        return;
+                    }
+                    var ctx = new CommandContext() {
+                        Room = room,
+                        MessageEvent = @event
+                    };
+                    if (await command.CanInvoke(ctx)) {
+                        await command.Invoke(ctx);
+                    }
+                    else {
+                        await room.SendMessageEventAsync("m.room.message",
+                            new RoomMessageEventData() {
+                                MessageType = "m.text",
+                                Body = "You do not have permission to run this command!"
+                            });
+                    }
                 }
             }
         });