diff options
author | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-10-06 18:29:15 +0200 |
---|---|---|
committer | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-10-06 18:29:15 +0200 |
commit | e5591eef3850a9796cc87386128651a828b70697 (patch) | |
tree | 7e501ec749229a3d96838265289266bb6f6ce208 /ExampleBots/PluralContactBotPoC/Bot/PluralContactBot.cs | |
parent | Unit tests, small refactors (diff) | |
download | LibMatrix-e5591eef3850a9796cc87386128651a828b70697.tar.xz |
Small refactors
Diffstat (limited to 'ExampleBots/PluralContactBotPoC/Bot/PluralContactBot.cs')
-rw-r--r-- | ExampleBots/PluralContactBotPoC/Bot/PluralContactBot.cs | 10 |
1 files changed, 6 insertions, 4 deletions
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<PluralC _logRoom = hs.GetRoom(botConfiguration.LogRoom); - hs.SyncHelper.InviteReceivedHandlers.Add(async Task (args) => { + 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<SystemData>($"gay.rory.plural_contact_bot.system_data#{inviteEvent.StateKey}"); + var accountData = await hs.GetAccountDataAsync<SystemData>($"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<PluralC } }); - hs.SyncHelper.TimelineEventHandlers.Add(async @event => { + syncHelper.TimelineEventHandlers.Add(async @event => { var room = hs.GetRoom(@event.RoomId); try { logger.LogInformation( @@ -87,7 +89,7 @@ public class PluralContactBot(AuthenticatedHomeserverGeneric hs, ILogger<PluralC 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); + await _logRoom.SendFileAsync("error.log.cs", stream); } }); } |