From 30a0868789466012bab869af4300aef5a9cac108 Mon Sep 17 00:00:00 2001 From: Rory& Date: Thu, 30 May 2024 09:46:43 +0000 Subject: Rename legacy event types --- .../Services/CommandListenerHostedService.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'Utilities/LibMatrix.Utilities.Bot/Services/CommandListenerHostedService.cs') 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 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.EventId, _hs.WhoAmI.UserId); + var roomProfile = await _hs.GetRoom(evt.RoomId!).GetStateAsync(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 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() }; -- cgit 1.4.1