resync rooms every 5 minutes
This commit is contained in:
@@ -45,6 +45,7 @@ func (m *Manager) GetBot() Bot {
|
|||||||
}
|
}
|
||||||
if config == nil {
|
if config == nil {
|
||||||
config = make(Bot, 0)
|
config = make(Bot, 0)
|
||||||
|
return config
|
||||||
}
|
}
|
||||||
m.ble = config.BanlistEnabled()
|
m.ble = config.BanlistEnabled()
|
||||||
|
|
||||||
@@ -86,6 +87,7 @@ func (m *Manager) GetBanlist() List {
|
|||||||
}
|
}
|
||||||
if config == nil {
|
if config == nil {
|
||||||
config = make(List, 0)
|
config = make(List, 0)
|
||||||
|
return config
|
||||||
}
|
}
|
||||||
m.bl = config
|
m.bl = config
|
||||||
return config
|
return config
|
||||||
@@ -115,6 +117,7 @@ func (m *Manager) GetGreylist() List {
|
|||||||
}
|
}
|
||||||
if config == nil {
|
if config == nil {
|
||||||
config = make(List, 0)
|
config = make(List, 0)
|
||||||
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
|||||||
12
bot/data.go
12
bot/data.go
@@ -38,9 +38,11 @@ func (b *Bot) migrate() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bot) syncRooms() error {
|
func (b *Bot) syncRooms() error {
|
||||||
|
adminRooms := []id.RoomID{}
|
||||||
|
|
||||||
adminRoom := b.cfg.GetBot().AdminRoom()
|
adminRoom := b.cfg.GetBot().AdminRoom()
|
||||||
if adminRoom != "" {
|
if adminRoom != "" {
|
||||||
b.adminRooms = append(b.adminRooms, adminRoom)
|
adminRooms = append(adminRooms, adminRoom)
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := b.lp.GetClient().JoinedRooms()
|
resp, err := b.lp.GetClient().JoinedRooms()
|
||||||
@@ -60,9 +62,10 @@ func (b *Bot) syncRooms() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if cfg.Owner() != "" && b.allowAdmin(id.UserID(cfg.Owner()), "") {
|
if cfg.Owner() != "" && b.allowAdmin(id.UserID(cfg.Owner()), "") {
|
||||||
b.adminRooms = append(b.adminRooms, roomID)
|
adminRooms = append(adminRooms, roomID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
b.adminRooms = adminRooms
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -101,3 +104,8 @@ func (b *Bot) initBotUsers() ([]string, error) {
|
|||||||
cfg.Set(config.BotUsers, "@*:"+homeserver)
|
cfg.Set(config.BotUsers, "@*:"+homeserver)
|
||||||
return cfg.Users(), b.cfg.SetBot(cfg)
|
return cfg.Users(), b.cfg.SetBot(cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SyncRooms and mailboxes
|
||||||
|
func (b *Bot) SyncRooms() {
|
||||||
|
b.syncRooms() //nolint:errcheck // nothing can be done here
|
||||||
|
}
|
||||||
|
|||||||
@@ -153,6 +153,11 @@ func initCron() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("cannot start queue processing cronjob: %v", err)
|
log.Error("cannot start queue processing cronjob: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = cron.AddJob("*/5 * * * *", mxb.SyncRooms)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("cannot start sync rooms cronjob: %v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func initShutdown(quit chan struct{}) {
|
func initShutdown(quit chan struct{}) {
|
||||||
|
|||||||
Reference in New Issue
Block a user