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 --- .../LibMatrix.JsonSerializerContextGenerator/Program.cs | 2 +- .../LibMatrix.Utilities.Bot/Commands/AliassesCommand.cs | 2 +- .../LibMatrix.Utilities.Bot/Commands/PingCommand.cs | 2 +- .../LibMatrix.Utilities.Bot/Interfaces/CommandContext.cs | 4 ++-- .../Services/CommandListenerHostedService.cs | 16 ++++++++-------- 5 files changed, 13 insertions(+), 13 deletions(-) (limited to 'Utilities') diff --git a/Utilities/LibMatrix.JsonSerializerContextGenerator/Program.cs b/Utilities/LibMatrix.JsonSerializerContextGenerator/Program.cs index 6348085..95af553 100644 --- a/Utilities/LibMatrix.JsonSerializerContextGenerator/Program.cs +++ b/Utilities/LibMatrix.JsonSerializerContextGenerator/Program.cs @@ -7,7 +7,7 @@ using LibMatrix.LegacyEvents.EventTypes; // var asm = Assembly.LoadFrom(binary); File.Delete("EventSerializerContexts.g.cs"); var stream = File.OpenWrite("EventSerializerContexts.g.cs"); -var eventContentTypes = new ClassCollector().ResolveFromAllAccessibleAssemblies(); +var eventContentTypes = new ClassCollector().ResolveFromAllAccessibleAssemblies(); stream.WriteString("using System.Text.Json.Serialization;\n"); 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().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 Reply(RoomMessageEventContent content) => await Room.SendMessageEventAsync(content); + public async Task 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 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