From e5591eef3850a9796cc87386128651a828b70697 Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Fri, 6 Oct 2023 18:29:15 +0200 Subject: Small refactors --- ExampleBots/PluralContactBotPoC/Bot/AccountData/BotData.cs | 1 + ExampleBots/PluralContactBotPoC/Bot/AccountData/SystemData.cs | 1 + .../PluralContactBotPoC/Bot/Commands/CreateSystemCommand.cs | 2 +- ExampleBots/PluralContactBotPoC/Bot/PluralContactBot.cs | 10 ++++++---- 4 files changed, 9 insertions(+), 5 deletions(-) (limited to 'ExampleBots/PluralContactBotPoC/Bot') diff --git a/ExampleBots/PluralContactBotPoC/Bot/AccountData/BotData.cs b/ExampleBots/PluralContactBotPoC/Bot/AccountData/BotData.cs index 9477488..5d11432 100644 --- a/ExampleBots/PluralContactBotPoC/Bot/AccountData/BotData.cs +++ b/ExampleBots/PluralContactBotPoC/Bot/AccountData/BotData.cs @@ -1,4 +1,5 @@ using System.Text.Json.Serialization; +using LibMatrix.EventTypes; using LibMatrix.Helpers; using LibMatrix.Interfaces; diff --git a/ExampleBots/PluralContactBotPoC/Bot/AccountData/SystemData.cs b/ExampleBots/PluralContactBotPoC/Bot/AccountData/SystemData.cs index 5edfc0e..42edd23 100644 --- a/ExampleBots/PluralContactBotPoC/Bot/AccountData/SystemData.cs +++ b/ExampleBots/PluralContactBotPoC/Bot/AccountData/SystemData.cs @@ -1,4 +1,5 @@ using System.Text.Json.Serialization; +using LibMatrix.EventTypes; using LibMatrix.Helpers; using LibMatrix.Interfaces; diff --git a/ExampleBots/PluralContactBotPoC/Bot/Commands/CreateSystemCommand.cs b/ExampleBots/PluralContactBotPoC/Bot/Commands/CreateSystemCommand.cs index 55624a8..4a7d646 100644 --- a/ExampleBots/PluralContactBotPoC/Bot/Commands/CreateSystemCommand.cs +++ b/ExampleBots/PluralContactBotPoC/Bot/Commands/CreateSystemCommand.cs @@ -25,7 +25,7 @@ public class CreateSystemCommand(IServiceProvider services, HomeserverProviderSe var sysName = ctx.Args[0]; try { try { - await ctx.Homeserver.GetAccountData("gay.rory.plural_contact_bot.system_data"); + await ctx.Homeserver.GetAccountDataAsync("gay.rory.plural_contact_bot.system_data"); await ctx.Reply(MessageFormatter.FormatError($"System {sysName} already exists!")); } catch (MatrixException e) { diff --git a/ExampleBots/PluralContactBotPoC/Bot/PluralContactBot.cs b/ExampleBots/PluralContactBotPoC/Bot/PluralContactBot.cs index 0bd2bbf..231af95 100644 --- a/ExampleBots/PluralContactBotPoC/Bot/PluralContactBot.cs +++ b/ExampleBots/PluralContactBotPoC/Bot/PluralContactBot.cs @@ -38,14 +38,16 @@ public class PluralContactBot(AuthenticatedHomeserverGeneric hs, ILogger { + var syncHelper = new SyncHelper(hs); + + syncHelper.InviteReceivedHandlers.Add(async Task (args) => { var inviteEvent = args.Value.InviteState.Events.FirstOrDefault(x => x.Type == "m.room.member" && x.StateKey == hs.UserId); logger.LogInformation("Got invite to {} by {} with reason: {}", args.Key, inviteEvent.Sender, (inviteEvent.TypedContent as RoomMemberEventContent).Reason); try { - var accountData = await hs.GetAccountData($"gay.rory.plural_contact_bot.system_data#{inviteEvent.StateKey}"); + var accountData = await hs.GetAccountDataAsync($"gay.rory.plural_contact_bot.system_data#{inviteEvent.StateKey}"); if (accountData.Members.Contains(inviteEvent.Sender)) { await (hs.GetRoom(args.Key)).JoinAsync(reason: "I was invited by a system member!"); @@ -74,7 +76,7 @@ public class PluralContactBot(AuthenticatedHomeserverGeneric hs, ILogger { + syncHelper.TimelineEventHandlers.Add(async @event => { var room = hs.GetRoom(@event.RoomId); try { logger.LogInformation( @@ -87,7 +89,7 @@ public class PluralContactBot(AuthenticatedHomeserverGeneric hs, ILogger