about summary refs log tree commit diff
path: root/Utilities/LibMatrix.Utilities.Bot
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2024-05-30 09:46:43 +0000
committerRory& <root@rory.gay>2024-05-30 09:46:43 +0000
commit30a0868789466012bab869af4300aef5a9cac108 (patch)
tree12790166e4d2c01a141928143b9b4d96dd08ace8 /Utilities/LibMatrix.Utilities.Bot
parentClarify LegacyEvent types (diff)
downloadLibMatrix-30a0868789466012bab869af4300aef5a9cac108.tar.xz
Rename legacy event types
Diffstat (limited to '')
-rw-r--r--Utilities/LibMatrix.Utilities.Bot/Commands/AliassesCommand.cs2
-rw-r--r--Utilities/LibMatrix.Utilities.Bot/Commands/PingCommand.cs2
-rw-r--r--Utilities/LibMatrix.Utilities.Bot/Interfaces/CommandContext.cs4
-rw-r--r--Utilities/LibMatrix.Utilities.Bot/Services/CommandListenerHostedService.cs16
4 files changed, 12 insertions, 12 deletions
diff --git a/Utilities/LibMatrix.Utilities.Bot/Commands/AliassesCommand.cs b/Utilities/LibMatrix.Utilities.Bot/Commands/AliassesCommand.cs
index 68fc884..aaa61ed 100644
--- a/Utilities/LibMatrix.Utilities.Bot/Commands/AliassesCommand.cs
+++ b/Utilities/LibMatrix.Utilities.Bot/Commands/AliassesCommand.cs
@@ -19,7 +19,7 @@ public class AliassesCommand(IServiceProvider services) : ICommand {
         var commands = services.GetServices<ICommand>().Where(x => !x.Unlisted).ToList();
         foreach (var command in commands) sb.AppendLine($"- {command.Name}: {command.Description}");
 
-        await ctx.Room.SendMessageEventAsync(new RoomMessageEventContent("m.notice", sb.ToString()));
+        await ctx.Room.SendMessageEventAsync(new RoomMessageLegacyEventContent("m.notice", sb.ToString()));
         
         var msb = new MessageBuilder("m.notice");
         msb.WithHtmlTag("table", tb => {
diff --git a/Utilities/LibMatrix.Utilities.Bot/Commands/PingCommand.cs b/Utilities/LibMatrix.Utilities.Bot/Commands/PingCommand.cs
index 04d5124..15a1ea1 100644
--- a/Utilities/LibMatrix.Utilities.Bot/Commands/PingCommand.cs
+++ b/Utilities/LibMatrix.Utilities.Bot/Commands/PingCommand.cs
@@ -9,5 +9,5 @@ public class PingCommand : ICommand {
     public string Description { get; } = "Pong!";
     public bool Unlisted { get; }
 
-    public async Task Invoke(CommandContext ctx) => await ctx.Room.SendMessageEventAsync(new RoomMessageEventContent(body: "pong!"));
+    public async Task Invoke(CommandContext ctx) => await ctx.Room.SendMessageEventAsync(new RoomMessageLegacyEventContent(body: "pong!"));
 }
\ No newline at end of file
diff --git a/Utilities/LibMatrix.Utilities.Bot/Interfaces/CommandContext.cs b/Utilities/LibMatrix.Utilities.Bot/Interfaces/CommandContext.cs
index c171dfe..1b69c89 100644
--- a/Utilities/LibMatrix.Utilities.Bot/Interfaces/CommandContext.cs
+++ b/Utilities/LibMatrix.Utilities.Bot/Interfaces/CommandContext.cs
@@ -9,7 +9,7 @@ public class CommandContext {
     public required LegacyMatrixEventResponse MessageEvent { get; set; }
 
     public string MessageContentWithoutReply =>
-        (MessageEvent.TypedContent as RoomMessageEventContent)!
+        (MessageEvent.TypedContent as RoomMessageLegacyEventContent)!
         .Body.Split('\n')
         .SkipWhile(x => x.StartsWith(">"))
         .Aggregate((x, y) => $"{x}\n{y}");
@@ -18,7 +18,7 @@ public class CommandContext {
     public required string[] Args;
     public required AuthenticatedHomeserverGeneric Homeserver { get; set; }
 
-    public async Task<EventIdResponse> Reply(RoomMessageEventContent content) => await Room.SendMessageEventAsync(content);
+    public async Task<EventIdResponse> Reply(RoomMessageLegacyEventContent content) => await Room.SendMessageEventAsync(content);
 }
 
 public class CommandResult {
diff --git a/Utilities/LibMatrix.Utilities.Bot/Services/CommandListenerHostedService.cs b/Utilities/LibMatrix.Utilities.Bot/Services/CommandListenerHostedService.cs
index feb174b..46638e4 100644
--- a/Utilities/LibMatrix.Utilities.Bot/Services/CommandListenerHostedService.cs
+++ b/Utilities/LibMatrix.Utilities.Bot/Services/CommandListenerHostedService.cs
@@ -61,7 +61,7 @@ public class CommandListenerHostedService : IHostedService {
             try {
                 var room = _hs.GetRoom(@event.RoomId);
                 // _logger.LogInformation(eventResponse.ToJson(indent: false));
-                if (@event is { Type: "m.room.message", TypedContent: RoomMessageEventContent message })
+                if (@event is { Type: "m.room.message", TypedContent: RoomMessageLegacyEventContent message })
                     if (message is { MessageType: "m.text" }) {
                         var usedPrefix = await GetUsedPrefix(@event);
                         if (usedPrefix is null) return;
@@ -89,12 +89,12 @@ public class CommandListenerHostedService : IHostedService {
     }
 
     private async Task<string?> GetUsedPrefix(LegacyMatrixEventResponse evt) {
-        var messageContent = evt.TypedContent as RoomMessageEventContent;
+        var messageContent = evt.TypedContent as RoomMessageLegacyEventContent;
         var message = messageContent!.BodyWithoutReplyFallback;
         var prefix = _config.Prefixes.OrderByDescending(x => x.Length).FirstOrDefault(message.StartsWith);
         if (prefix is null && _config.MentionPrefix) {
             var profile = await _hs.GetProfileAsync(_hs.WhoAmI.UserId);
-            var roomProfile = await _hs.GetRoom(evt.RoomId!).GetStateAsync<RoomMemberEventContent>(RoomMemberEventContent.EventId, _hs.WhoAmI.UserId);
+            var roomProfile = await _hs.GetRoom(evt.RoomId!).GetStateAsync<RoomMemberLegacyEventContent>(RoomMemberLegacyEventContent.EventId, _hs.WhoAmI.UserId);
             if (message.StartsWith(_hs.WhoAmI.UserId + ": ")) prefix = profile.DisplayName + ": ";    // `@bot:server.xyz: `
             else if (message.StartsWith(_hs.WhoAmI.UserId + " ")) prefix = profile.DisplayName + " "; // `@bot:server.xyz `
             else if (!string.IsNullOrWhiteSpace(roomProfile?.DisplayName) && message.StartsWith(roomProfile.DisplayName + ": "))
@@ -109,7 +109,7 @@ public class CommandListenerHostedService : IHostedService {
     }
 
     private async Task<CommandResult> InvokeCommand(LegacyMatrixEventResponse evt, string usedPrefix) {
-        var message = evt.TypedContent as RoomMessageEventContent;
+        var message = evt.TypedContent as RoomMessageLegacyEventContent;
         var room = _hs.GetRoom(evt.RoomId!);
 
         var commandWithoutPrefix = message.BodyWithoutReplyFallback[usedPrefix.Length..].Trim();
@@ -124,7 +124,7 @@ public class CommandListenerHostedService : IHostedService {
             var command = _commands.SingleOrDefault(x => x.Name == commandWithoutPrefix.Split(' ')[0] || x.Aliases?.Contains(commandWithoutPrefix.Split(' ')[0]) == true);
             if (command == null) {
                 await room.SendMessageEventAsync(
-                    new RoomMessageEventContent("m.notice", $"Command \"{ctx.CommandName}\" not found!"));
+                    new RoomMessageLegacyEventContent("m.notice", $"Command \"{ctx.CommandName}\" not found!"));
                 return new() {
                     Success = false,
                     Result = CommandResult.CommandResultType.Failure_InvalidCommand,
@@ -153,7 +153,7 @@ public class CommandListenerHostedService : IHostedService {
                     Success = false
                 };
             // await room.SendMessageEventAsync(
-            // new RoomMessageEventContent("m.notice", "You do not have permission to run this command!"));
+            // new RoomMessageLegacyEventContent("m.notice", "You do not have permission to run this command!"));
 
             return new CommandResult() {
                 Context = ctx,
@@ -176,8 +176,8 @@ public class CommandListenerHostedService : IHostedService {
         var room = res.Context.Room;
         var msg = res.Result switch {
             CommandResult.CommandResultType.Failure_Exception => MessageFormatter.FormatException("An error occurred during the execution of this command", res.Exception!),
-            CommandResult.CommandResultType.Failure_NoPermission => new RoomMessageEventContent("m.notice", "You do not have permission to run this command!"),
-            CommandResult.CommandResultType.Failure_InvalidCommand => new RoomMessageEventContent("m.notice", $"Command \"{res.Context.CommandName}\" not found!"),
+            CommandResult.CommandResultType.Failure_NoPermission => new RoomMessageLegacyEventContent("m.notice", "You do not have permission to run this command!"),
+            CommandResult.CommandResultType.Failure_InvalidCommand => new RoomMessageLegacyEventContent("m.notice", $"Command \"{res.Context.CommandName}\" not found!"),
             _ => throw new ArgumentOutOfRangeException()
         };