From f5447484512d726f4403f0d7725777d0a95601fb Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Tue, 19 Sep 2023 00:16:36 +0200 Subject: Add more stuff, add unit tests --- .../Bot/Commands/CreateSystemCommand.cs | 10 +++++----- .../PluralContactBotPoC/Bot/PluralContactBot.cs | 23 +++++++++++----------- ExampleBots/PluralContactBotPoC/Program.cs | 1 - 3 files changed, 17 insertions(+), 17 deletions(-) (limited to 'ExampleBots/PluralContactBotPoC') diff --git a/ExampleBots/PluralContactBotPoC/Bot/Commands/CreateSystemCommand.cs b/ExampleBots/PluralContactBotPoC/Bot/Commands/CreateSystemCommand.cs index 5da4f5e..55624a8 100644 --- a/ExampleBots/PluralContactBotPoC/Bot/Commands/CreateSystemCommand.cs +++ b/ExampleBots/PluralContactBotPoC/Bot/Commands/CreateSystemCommand.cs @@ -1,8 +1,8 @@ using LibMatrix; +using LibMatrix.EventTypes.Spec.State; using LibMatrix.Helpers; using LibMatrix.Services; -using LibMatrix.StateEventTypes.Spec; -using MediaModeratorPoC.Bot.Interfaces; +using LibMatrix.Utilities.Bot.Interfaces; using PluralContactBotPoC.Bot.AccountData; using PluralContactBotPoC.Bot.StateEventTypes; @@ -18,7 +18,7 @@ public class CreateSystemCommand(IServiceProvider services, HomeserverProviderSe public async Task Invoke(CommandContext ctx) { if (ctx.Args.Length != 1) { - await ctx.Reply("m.notice", MessageFormatter.FormatError("Only one argument is allowed: system name!")); + await ctx.Reply(MessageFormatter.FormatError("Only one argument is allowed: system name!")); return; } @@ -26,7 +26,7 @@ public class CreateSystemCommand(IServiceProvider services, HomeserverProviderSe try { try { await ctx.Homeserver.GetAccountData("gay.rory.plural_contact_bot.system_data"); - await ctx.Reply("m.notice", MessageFormatter.FormatError($"System {sysName} already exists!")); + await ctx.Reply(MessageFormatter.FormatError($"System {sysName} already exists!")); } catch (MatrixException e) { if (e is { ErrorCode: "M_NOT_FOUND" }) { @@ -51,7 +51,7 @@ public class CreateSystemCommand(IServiceProvider services, HomeserverProviderSe } } catch (Exception e) { - await ctx.Reply("m.notice", MessageFormatter.FormatException("Something went wrong!", e)); + await ctx.Reply(MessageFormatter.FormatException("Something went wrong!", e)); } } } diff --git a/ExampleBots/PluralContactBotPoC/Bot/PluralContactBot.cs b/ExampleBots/PluralContactBotPoC/Bot/PluralContactBot.cs index 2136b42..c3cebe2 100644 --- a/ExampleBots/PluralContactBotPoC/Bot/PluralContactBot.cs +++ b/ExampleBots/PluralContactBotPoC/Bot/PluralContactBot.cs @@ -1,12 +1,13 @@ using System.Text; using ArcaneLibs.Extensions; +using LibMatrix.EventTypes.Spec; +using LibMatrix.EventTypes.Spec.State; using LibMatrix.Helpers; using LibMatrix.Homeservers; using LibMatrix.RoomTypes; using LibMatrix.Services; -using LibMatrix.StateEventTypes.Spec; using LibMatrix.Utilities.Bot; -using MediaModeratorPoC.Bot.Interfaces; +using LibMatrix.Utilities.Bot.Interfaces; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using PluralContactBotPoC.Bot.AccountData; @@ -35,7 +36,7 @@ public class PluralContactBot(AuthenticatedHomeserverGeneric hs, ILogger { var inviteEvent = @@ -46,9 +47,9 @@ public class PluralContactBot(AuthenticatedHomeserverGeneric hs, ILogger($"gay.rory.plural_contact_bot.system_data#{inviteEvent.StateKey}"); if (accountData.Members.Contains(inviteEvent.Sender)) { - await (await hs.GetRoom(args.Key)).JoinAsync(reason: "I was invited by a system member!"); + await (hs.GetRoom(args.Key)).JoinAsync(reason: "I was invited by a system member!"); - await _logRoom.SendMessageEventAsync("m.room.message", + await _logRoom.SendMessageEventAsync( MessageFormatter.FormatSuccess( $"I was invited by a system member ({MessageFormatter.HtmlFormatMention(inviteEvent.Sender)}) to {MessageFormatter.HtmlFormatMention(args.Key)}")); @@ -56,25 +57,25 @@ public class PluralContactBot(AuthenticatedHomeserverGeneric hs, ILogger { - var room = await hs.GetRoom(@event.RoomId); + var room = hs.GetRoom(@event.RoomId); try { logger.LogInformation( "Got timeline event in {}: {}", @event.RoomId, @event.ToJson(indent: true, ignoreNull: true)); @@ -83,7 +84,7 @@ public class PluralContactBot(AuthenticatedHomeserverGeneric hs, ILogger