diff options
author | Emma [it/its]@Rory& <root@rory.gay> | 2023-10-14 23:19:46 +0200 |
---|---|---|
committer | Emma [it/its]@Rory& <root@rory.gay> | 2023-10-14 23:19:46 +0200 |
commit | 73461bd79f923caa44740f170213a4abb4743660 (patch) | |
tree | 89cbb7403b4bf3f86a505d70a8f255b6463a2c3f /OsuFederatedBeatmapApi/Services/FederatedBeatmapApiBot.cs | |
parent | Maybe fix libmatrix bug with room creation (diff) | |
download | OsuFederatedBeatmapApi-73461bd79f923caa44740f170213a4abb4743660.tar.xz |
Diffstat (limited to 'OsuFederatedBeatmapApi/Services/FederatedBeatmapApiBot.cs')
-rw-r--r-- | OsuFederatedBeatmapApi/Services/FederatedBeatmapApiBot.cs | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/OsuFederatedBeatmapApi/Services/FederatedBeatmapApiBot.cs b/OsuFederatedBeatmapApi/Services/FederatedBeatmapApiBot.cs index b8cc635..2aaf45c 100644 --- a/OsuFederatedBeatmapApi/Services/FederatedBeatmapApiBot.cs +++ b/OsuFederatedBeatmapApi/Services/FederatedBeatmapApiBot.cs @@ -40,7 +40,28 @@ public class FederatedBeatmapApiBot(AuthenticatedHomeserverGeneric hs, var controlRoomMembers = accountDataService.ControlRoom.GetMembersAsync(); await foreach (var member in controlRoomMembers) { if ((member.TypedContent as RoomMemberEventContent)? - .Membership == "join") admins.Add(member.UserId); + .Membership == "join") + admins.Add(member.StateKey); + } + + var pls = await accountDataService.OwnBeatmapRepositoryRoom.GetPowerLevelsAsync(); + var ownPl = pls.GetUserPowerLevel(hs.UserId); + + if (!pls.UserHasPermission(hs.UserId, RoomPowerLevelEventContent.EventId)) { + accountDataService.LogRoom.SendMessageEventAsync( + MessageFormatter.FormatError( + $"I don't have permission to send power level updates in " + + $"{MessageFormatter.HtmlFormatMention(accountDataService.OwnBeatmapRepositoryRoom.RoomId, "my own beatmap repository")}!")); + } + else { + foreach (var admin in admins) { + if (pls.GetUserPowerLevel(admin) < ownPl - 1) { + logger.LogInformation("Raising powerlevel of {} in {} to {}", admin, accountDataService.OwnBeatmapRepositoryRoom.RoomId, ownPl - 1); + pls.SetUserPowerLevel(admin, ownPl - 1); + await accountDataService.OwnBeatmapRepositoryRoom.SendStateEventAsync( + RoomPowerLevelEventContent.EventId, pls); + } + } } await Task.Delay(TimeSpan.FromSeconds(30), cancellationToken); |