]> git.rm.cloudns.org Git - xonotic/xonotic.git/commitdiff
Allow naming rooms in the json config.
authorRudolf Polzer <divVerent@gmail.com>
Sat, 30 Sep 2023 11:06:03 +0000 (13:06 +0200)
committerRudolf Polzer <divVerent@gmail.com>
Sat, 30 Sep 2023 11:06:03 +0000 (13:06 +0200)
The name isn't used for anything yet, but makes it easier to update.

misc/infrastructure/powerbot/bot.go
misc/infrastructure/powerbot/powerlevels.go

index 6ea17bc1955fbd0299e77d97a63cc035e7d993f8..451cc030af5bedc01ef2ca9214c0bd2ecf20333b 100644 (file)
@@ -18,13 +18,18 @@ const (
        syncForceFrequency = int(7 * 24 * time.Hour / syncInterval)
 )
 
+type Room struct {
+       ID   id.RoomID
+       Name string
+}
+
 type Config struct {
-       Homeserver  string        `json:"homeserver"`
-       UserID      id.UserID     `json:"user_id"`
-       Password    string        `json:"password,omitempty"`
-       DeviceID    id.DeviceID   `json:"device_id,omitempty"`
-       AccessToken string        `json:"access_token,omitempty"`
-       Rooms       [][]id.RoomID `json:"rooms"`
+       Homeserver  string      `json:"homeserver"`
+       UserID      id.UserID   `json:"user_id"`
+       Password    string      `json:"password,omitempty"`
+       DeviceID    id.DeviceID `json:"device_id,omitempty"`
+       AccessToken string      `json:"access_token,omitempty"`
+       Rooms       [][]Room    `json:"rooms"`
 }
 
 func (c *Config) Load() error {
@@ -178,7 +183,7 @@ func Run() (err error) {
        }
        for _, group := range config.Rooms {
                for _, room := range group {
-                       roomUsers[room] = map[id.UserID]struct{}{}
+                       roomUsers[room.ID] = map[id.UserID]struct{}{}
                }
        }
        client, err := Login(config)
@@ -254,7 +259,7 @@ func Run() (err error) {
                        }
                        for _, group := range config.Rooms {
                                for _, room := range group {
-                                       syncPowerLevels(client, room, group, scoreData, counter%syncForceFrequency == 0)
+                                       syncPowerLevels(client, room.ID, group, scoreData, counter%syncForceFrequency == 0)
                                }
                        }
                        roomUsersMu.RUnlock()
index eb11f79084247e3af152b5e4997aaaef2f5319af..c07855e8d0b51a1a2298f13b70c3292ddab7f4bd 100644 (file)
@@ -77,7 +77,7 @@ func allPowerLevels(roomLevels *event.PowerLevelsEventContent) []int {
        return ret
 }
 
-func syncPowerLevels(client *mautrix.Client, room id.RoomID, roomGroup []id.RoomID, scores map[id.RoomID]map[id.UserID]*Score, force bool) {
+func syncPowerLevels(client *mautrix.Client, room id.RoomID, roomGroup []Room, scores map[id.RoomID]map[id.UserID]*Score, force bool) {
        roomLevels := roomPowerLevels[room]
        if roomLevels == nil {
                log.Printf("trying to ensure power levels for room %v, but did not get power level map yet", room)
@@ -131,10 +131,10 @@ func syncPowerLevels(client *mautrix.Client, room id.RoomID, roomGroup []id.Room
                prevLevel := roomLevels.Users[user]
                level, raw := computePowerLevel(roomLevels.UsersDefault, *score)
                for _, otherRoom := range roomGroup {
-                       if otherRoom == room {
+                       if otherRoom.ID == room {
                                continue
                        }
-                       otherScore := scores[otherRoom][user]
+                       otherScore := scores[otherRoom.ID][user]
                        if otherScore == nil {
                                continue
                        }