mirror of
https://gitlab.com/xonotic/xonotic
synced 2025-03-04 02:17:35 +00:00
Allow naming rooms in the json config.
The name isn't used for anything yet, but makes it easier to update.
This commit is contained in:
parent
4a048096c2
commit
9690957ce2
@ -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()
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user