From ad5c1364f2f8c4f50436da21b24d6a0b960da6ab Mon Sep 17 00:00:00 2001 From: "Emma@Rory&" Date: Thu, 27 Jul 2023 18:19:13 +0200 Subject: Add latest code before splitting projects --- MatrixRoomUtils.Bot/Bot/MRUBot.cs | 11 ++++++----- MatrixRoomUtils.Bot/MatrixRoomUtils.Bot.csproj | 2 +- MatrixRoomUtils.Core/Helpers/SyncHelper.cs | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/MatrixRoomUtils.Bot/Bot/MRUBot.cs b/MatrixRoomUtils.Bot/Bot/MRUBot.cs index 1bf5f67..bd24ec7 100644 --- a/MatrixRoomUtils.Bot/Bot/MRUBot.cs +++ b/MatrixRoomUtils.Bot/Bot/MRUBot.cs @@ -8,7 +8,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; -namespace MatrixRoomUtils.Bot.Bot; +namespace MatrixRoomUtils.Bot.Bot; public class MRUBot : IHostedService { private readonly HomeserverProviderService _homeserverProviderService; @@ -58,9 +58,10 @@ public class MRUBot : IHostedService { x.Type == "m.room.member" && x.StateKey == hs.WhoAmI.UserId); _logger.LogInformation( $"Got invite to {args.Key} by {inviteEvent.Sender} with reason: {(inviteEvent.TypedContent as RoomMemberEventData).Reason}"); - if (inviteEvent.Sender == "@emma:rory.gay") { + if (inviteEvent.Sender.EndsWith(":rory.gay") || inviteEvent.Sender == "@mxidupwitch:the-apothecary.club" ) { try { - await (await hs.GetRoom(args.Key)).JoinAsync(reason: "I was invited by Emma (Rory&)!"); + var senderProfile = await hs.GetProfile(inviteEvent.Sender); + await (await hs.GetRoom(args.Key)).JoinAsync(reason: $"I was invited by {senderProfile.DisplayName ?? inviteEvent.Sender}!"); } catch (Exception e) { _logger.LogError(e.ToString()); @@ -76,7 +77,7 @@ public class MRUBot : IHostedService { // _logger.LogInformation(eventResponse.ToJson(indent: false)); if (@event is { Type: "m.room.message", TypedContent: RoomMessageEventData message }) { if (message is { MessageType: "m.text" } && message.Body.StartsWith(_configuration.Prefix)) { - + var command = _commands.FirstOrDefault(x => x.Name == message.Body.Split(' ')[0][_configuration.Prefix.Length..]); if (command == null) { await room.SendMessageEventAsync("m.room.message", @@ -111,4 +112,4 @@ public class MRUBot : IHostedService { public async Task StopAsync(CancellationToken cancellationToken) { _logger.LogInformation("Shutting down bot!"); } -} \ No newline at end of file +} diff --git a/MatrixRoomUtils.Bot/MatrixRoomUtils.Bot.csproj b/MatrixRoomUtils.Bot/MatrixRoomUtils.Bot.csproj index 5eba4fd..d9b2931 100644 --- a/MatrixRoomUtils.Bot/MatrixRoomUtils.Bot.csproj +++ b/MatrixRoomUtils.Bot/MatrixRoomUtils.Bot.csproj @@ -28,7 +28,7 @@ Always - + Always diff --git a/MatrixRoomUtils.Core/Helpers/SyncHelper.cs b/MatrixRoomUtils.Core/Helpers/SyncHelper.cs index ea9317e..e12164c 100644 --- a/MatrixRoomUtils.Core/Helpers/SyncHelper.cs +++ b/MatrixRoomUtils.Core/Helpers/SyncHelper.cs @@ -42,7 +42,7 @@ public class SyncHelper { // var res = await JsonSerializer.DeserializeAsync(await req.Content.ReadAsStreamAsync()); -#if DEBUG +#if DEBUG && false var jsonObj = await req.Content.ReadFromJsonAsync(); try { await _homeServer._httpClient.PostAsJsonAsync( -- cgit 1.4.1