From def33cc092ae2c6defcc218b108b7c99cbfb8581 Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Sun, 2 Jul 2023 01:01:09 +0200 Subject: Prefetch room info --- MatrixRoomUtils.Bot/Bot/MRUBot.cs | 57 +++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 29 deletions(-) (limited to 'MatrixRoomUtils.Bot/Bot/MRUBot.cs') 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 _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!" + }); + } } } }); -- cgit 1.4.1