about summary refs log tree commit diff
path: root/ExampleBots/PluralContactBotPoC
diff options
context:
space:
mode:
authorTheArcaneBrony <myrainbowdash949@gmail.com>2023-09-19 00:16:36 +0200
committerTheArcaneBrony <myrainbowdash949@gmail.com>2023-09-19 00:16:36 +0200
commitf5447484512d726f4403f0d7725777d0a95601fb (patch)
tree47fe88a4c021f62ff42663f6d8c5229e71d21813 /ExampleBots/PluralContactBotPoC
parentImprove README (diff)
downloadLibMatrix-f5447484512d726f4403f0d7725777d0a95601fb.tar.xz
Add more stuff, add unit tests
Diffstat (limited to 'ExampleBots/PluralContactBotPoC')
-rw-r--r--ExampleBots/PluralContactBotPoC/Bot/Commands/CreateSystemCommand.cs10
-rw-r--r--ExampleBots/PluralContactBotPoC/Bot/PluralContactBot.cs23
-rw-r--r--ExampleBots/PluralContactBotPoC/Program.cs1
3 files changed, 17 insertions, 17 deletions
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<BotData>("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<PluralC
 
         BotData botData;
 
-        _logRoom = await hs.GetRoom(botConfiguration.LogRoom);
+        _logRoom = hs.GetRoom(botConfiguration.LogRoom);
 
         hs.SyncHelper.InviteReceivedHandlers.Add(async Task (args) => {
             var inviteEvent =
@@ -46,9 +47,9 @@ public class PluralContactBot(AuthenticatedHomeserverGeneric hs, ILogger<PluralC
             try {
                 var accountData = await hs.GetAccountData<SystemData>($"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<PluralC
                 }
             }
             catch (Exception e) {
-                await _logRoom.SendMessageEventAsync("m.room.message",
+                await _logRoom.SendMessageEventAsync(
                     MessageFormatter.FormatException(
                         $"Exception handling event {inviteEvent.EventId} by {inviteEvent.Sender} in {MessageFormatter.HtmlFormatMention(inviteEvent.RoomId)}", e));
             }
 
             if (inviteEvent.Sender.EndsWith(":rory.gay") || inviteEvent.Sender.EndsWith(":conduit.rory.gay")) {
                 try {
-                    var senderProfile = await hs.GetProfile(inviteEvent.Sender);
-                    await (await hs.GetRoom(args.Key)).JoinAsync(reason: $"I was invited by {senderProfile.DisplayName ?? inviteEvent.Sender}!");
+                    var senderProfile = await hs.GetProfileAsync(inviteEvent.Sender);
+                    await (hs.GetRoom(args.Key)).JoinAsync(reason: $"I was invited by {senderProfile.DisplayName ?? inviteEvent.Sender}!");
                 }
                 catch (Exception e) {
                     logger.LogError("{}", e.ToString());
-                    await (await hs.GetRoom(args.Key)).LeaveAsync(reason: "I was unable to join the room: " + e);
+                    await (hs.GetRoom(args.Key)).LeaveAsync(reason: "I was unable to join the room: " + e);
                 }
             }
         });
 
         hs.SyncHelper.TimelineEventHandlers.Add(async @event => {
-            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<PluralC
             }
             catch (Exception e) {
                 logger.LogError("{}", e.ToString());
-                await _logRoom.SendMessageEventAsync("m.room.message",
+                await _logRoom.SendMessageEventAsync(
                     MessageFormatter.FormatException($"Exception handling event {@event.EventId} by {@event.Sender} in {MessageFormatter.HtmlFormatMention(room.RoomId)}", e));
                 await using var stream = new MemoryStream(Encoding.UTF8.GetBytes(e.ToString()));
                 await _logRoom.SendFileAsync("m.file", "error.log.cs", stream);
diff --git a/ExampleBots/PluralContactBotPoC/Program.cs b/ExampleBots/PluralContactBotPoC/Program.cs
index b2e041e..49c6c68 100644
--- a/ExampleBots/PluralContactBotPoC/Program.cs
+++ b/ExampleBots/PluralContactBotPoC/Program.cs
@@ -5,7 +5,6 @@ using System.Text.Json.Serialization;
 using ArcaneLibs.Extensions;

 using LibMatrix.Services;

 using LibMatrix.Utilities.Bot;

-using MediaModeratorPoC.Bot;

 using Microsoft.Extensions.DependencyInjection;

 using Microsoft.Extensions.Hosting;

 using PluralContactBotPoC;