about summary refs log tree commit diff
path: root/OsuFederatedBeatmapApi/Services/FederatedBeatmapApiBot.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OsuFederatedBeatmapApi/Services/FederatedBeatmapApiBot.cs')
-rw-r--r--OsuFederatedBeatmapApi/Services/FederatedBeatmapApiBot.cs23
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);