about summary refs log tree commit diff
path: root/MatrixRoomUtils.Bot
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
parentDeduplicate some api calls (diff)
downloadMatrixUtils-def33cc092ae2c6defcc218b108b7c99cbfb8581.tar.xz
Prefetch room info
Diffstat (limited to 'MatrixRoomUtils.Bot')
-rw-r--r--MatrixRoomUtils.Bot/Bot/Commands/CmdCommand.cs7
-rw-r--r--MatrixRoomUtils.Bot/Bot/Commands/HelpCommand.cs4
-rw-r--r--MatrixRoomUtils.Bot/Bot/Commands/PingCommand.cs6
-rw-r--r--MatrixRoomUtils.Bot/Bot/FileStorageProvider.cs2
-rw-r--r--MatrixRoomUtils.Bot/Bot/Interfaces/CommandContext.cs9
-rw-r--r--MatrixRoomUtils.Bot/Bot/Interfaces/ICommand.cs2
-rw-r--r--MatrixRoomUtils.Bot/Bot/MRUBot.cs57
-rw-r--r--MatrixRoomUtils.Bot/Bot/MRUBotConfiguration.cs2
-rw-r--r--MatrixRoomUtils.Bot/Program.cs3
9 files changed, 44 insertions, 48 deletions
diff --git a/MatrixRoomUtils.Bot/Bot/Commands/CmdCommand.cs b/MatrixRoomUtils.Bot/Bot/Commands/CmdCommand.cs
index 66f3c4d..79757ae 100644
--- a/MatrixRoomUtils.Bot/Bot/Commands/CmdCommand.cs
+++ b/MatrixRoomUtils.Bot/Bot/Commands/CmdCommand.cs
@@ -1,9 +1,6 @@
-using System.Runtime.InteropServices;
-using System.Text;
-using MatrixRoomUtils.Bot.Interfaces;
-using Microsoft.Extensions.DependencyInjection;
+using MatrixRoomUtils.Bot.Bot.Interfaces;
 
-namespace MatrixRoomUtils.Bot.Commands;
+namespace MatrixRoomUtils.Bot.Bot.Commands;
 
 public class CmdCommand : ICommand {
     public string Name { get; } = "cmd";
diff --git a/MatrixRoomUtils.Bot/Bot/Commands/HelpCommand.cs b/MatrixRoomUtils.Bot/Bot/Commands/HelpCommand.cs
index af41563..6db10ae 100644
--- a/MatrixRoomUtils.Bot/Bot/Commands/HelpCommand.cs
+++ b/MatrixRoomUtils.Bot/Bot/Commands/HelpCommand.cs
@@ -1,8 +1,8 @@
 using System.Text;
-using MatrixRoomUtils.Bot.Interfaces;
+using MatrixRoomUtils.Bot.Bot.Interfaces;
 using Microsoft.Extensions.DependencyInjection;
 
-namespace MatrixRoomUtils.Bot.Commands; 
+namespace MatrixRoomUtils.Bot.Bot.Commands; 
 
 public class HelpCommand : ICommand {
     private readonly IServiceProvider _services;
diff --git a/MatrixRoomUtils.Bot/Bot/Commands/PingCommand.cs b/MatrixRoomUtils.Bot/Bot/Commands/PingCommand.cs
index a00cc8b..061ca53 100644
--- a/MatrixRoomUtils.Bot/Bot/Commands/PingCommand.cs
+++ b/MatrixRoomUtils.Bot/Bot/Commands/PingCommand.cs
@@ -1,8 +1,6 @@
-using System.Text;
-using MatrixRoomUtils.Bot.Interfaces;
-using Microsoft.Extensions.DependencyInjection;
+using MatrixRoomUtils.Bot.Bot.Interfaces;
 
-namespace MatrixRoomUtils.Bot.Commands; 
+namespace MatrixRoomUtils.Bot.Bot.Commands; 
 
 public class PingCommand : ICommand {
     public PingCommand() {
diff --git a/MatrixRoomUtils.Bot/Bot/FileStorageProvider.cs b/MatrixRoomUtils.Bot/Bot/FileStorageProvider.cs
index 8b9e726..c38591d 100644
--- a/MatrixRoomUtils.Bot/Bot/FileStorageProvider.cs
+++ b/MatrixRoomUtils.Bot/Bot/FileStorageProvider.cs
@@ -3,7 +3,7 @@ using MatrixRoomUtils.Core.Extensions;
 using MatrixRoomUtils.Core.Interfaces.Services;
 using Microsoft.Extensions.Logging;
 
-namespace MatrixRoomUtils.Bot; 
+namespace MatrixRoomUtils.Bot.Bot; 
 
 public class FileStorageProvider : IStorageProvider {
     private readonly ILogger<FileStorageProvider> _logger;
diff --git a/MatrixRoomUtils.Bot/Bot/Interfaces/CommandContext.cs b/MatrixRoomUtils.Bot/Bot/Interfaces/CommandContext.cs
index ab29554..94007a5 100644
--- a/MatrixRoomUtils.Bot/Bot/Interfaces/CommandContext.cs
+++ b/MatrixRoomUtils.Bot/Bot/Interfaces/CommandContext.cs
@@ -1,11 +1,12 @@
-using MatrixRoomUtils.Core;
 using MatrixRoomUtils.Core.Responses;
+using MatrixRoomUtils.Core.RoomTypes;
+using MatrixRoomUtils.Core.StateEventTypes.Spec;
 
-namespace MatrixRoomUtils.Bot.Interfaces;
+namespace MatrixRoomUtils.Bot.Bot.Interfaces;
 
 public class CommandContext {
     public GenericRoom Room { get; set; }
     public StateEventResponse MessageEvent { get; set; }
-    public string CommandName => (MessageEvent.TypedContent as MessageEventData).Body.Split(' ')[0][1..];
-    public string[] Args => (MessageEvent.TypedContent as MessageEventData).Body.Split(' ')[1..];
+    public string CommandName => (MessageEvent.TypedContent as RoomMessageEventData).Body.Split(' ')[0][1..];
+    public string[] Args => (MessageEvent.TypedContent as RoomMessageEventData).Body.Split(' ')[1..];
 }
\ No newline at end of file
diff --git a/MatrixRoomUtils.Bot/Bot/Interfaces/ICommand.cs b/MatrixRoomUtils.Bot/Bot/Interfaces/ICommand.cs
index b57d8c9..20805b1 100644
--- a/MatrixRoomUtils.Bot/Bot/Interfaces/ICommand.cs
+++ b/MatrixRoomUtils.Bot/Bot/Interfaces/ICommand.cs
@@ -1,4 +1,4 @@
-namespace MatrixRoomUtils.Bot.Interfaces; 
+namespace MatrixRoomUtils.Bot.Bot.Interfaces; 
 
 public interface ICommand {
     public string Name { get; }
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!"
+                            });
+                    }
                 }
             }
         });
diff --git a/MatrixRoomUtils.Bot/Bot/MRUBotConfiguration.cs b/MatrixRoomUtils.Bot/Bot/MRUBotConfiguration.cs
index c91698a..418eebb 100644
--- a/MatrixRoomUtils.Bot/Bot/MRUBotConfiguration.cs
+++ b/MatrixRoomUtils.Bot/Bot/MRUBotConfiguration.cs
@@ -1,6 +1,6 @@
 using Microsoft.Extensions.Configuration;
 
-namespace MatrixRoomUtils.Bot; 
+namespace MatrixRoomUtils.Bot.Bot; 
 
 public class MRUBotConfiguration {
     public MRUBotConfiguration(IConfiguration config) {
diff --git a/MatrixRoomUtils.Bot/Program.cs b/MatrixRoomUtils.Bot/Program.cs
index 0e27286..5dae843 100644
--- a/MatrixRoomUtils.Bot/Program.cs
+++ b/MatrixRoomUtils.Bot/Program.cs
@@ -1,7 +1,8 @@
 // See https://aka.ms/new-console-template for more information

 

 using MatrixRoomUtils.Bot;

-using MatrixRoomUtils.Bot.Interfaces;

+using MatrixRoomUtils.Bot.Bot;

+using MatrixRoomUtils.Bot.Bot.Interfaces;

 using MatrixRoomUtils.Core.Extensions;

 using MatrixRoomUtils.Core.Services;

 using Microsoft.Extensions.DependencyInjection;