remove migrations
This commit is contained in:
@@ -37,7 +37,6 @@ func New(
|
||||
log *logger.Logger,
|
||||
prefix string,
|
||||
domain string,
|
||||
envUsers []string,
|
||||
admins []string,
|
||||
) (*Bot, error) {
|
||||
b := &Bot{
|
||||
@@ -50,7 +49,7 @@ func New(
|
||||
lp: lp,
|
||||
mu: map[id.RoomID]*sync.Mutex{},
|
||||
}
|
||||
users, err := b.initBotUsers(envUsers)
|
||||
users, err := b.initBotUsers()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -66,7 +65,7 @@ func New(
|
||||
}
|
||||
b.allowedAdmins = allowedAdmins
|
||||
|
||||
b.commands = b.buildCommandList()
|
||||
b.commands = b.initCommands()
|
||||
|
||||
return b, nil
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ func (c commandList) get(key string) *command {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *Bot) buildCommandList() commandList {
|
||||
func (b *Bot) initCommands() commandList {
|
||||
return commandList{
|
||||
// special commands
|
||||
{
|
||||
|
||||
@@ -37,7 +37,6 @@ func (b *Bot) syncRooms() error {
|
||||
return err
|
||||
}
|
||||
for _, roomID := range resp.JoinedRooms {
|
||||
b.migrateSettings(roomID)
|
||||
cfg, serr := b.getRoomSettings(roomID)
|
||||
if serr != nil {
|
||||
b.log.Warn("cannot get %s settings: %v", roomID, err)
|
||||
|
||||
@@ -40,25 +40,18 @@ func (s botSettings) Users() []string {
|
||||
return []string{value}
|
||||
}
|
||||
|
||||
func (b *Bot) initBotUsers(envUsers []string) ([]string, error) {
|
||||
func (b *Bot) initBotUsers() ([]string, error) {
|
||||
config := b.getBotSettings()
|
||||
cfgUsers := config.Users()
|
||||
if len(cfgUsers) > 0 {
|
||||
// already migrated
|
||||
return cfgUsers, nil
|
||||
}
|
||||
if len(envUsers) == 0 {
|
||||
_, homeserver, err := b.lp.GetClient().UserID.Parse()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
config.Set(botOptionUsers, "@*:"+homeserver)
|
||||
} else {
|
||||
// Initialize from environment variable
|
||||
// TODO: remove this migration later and always initialize to `"@*:"+homeserver`
|
||||
config.Set(botOptionUsers, strings.Join(envUsers, " "))
|
||||
}
|
||||
|
||||
_, homeserver, err := b.lp.GetClient().UserID.Parse()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
config.Set(botOptionUsers, "@*:"+homeserver)
|
||||
return config.Users(), b.setBotSettings(config)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package bot
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"maunium.net/go/mautrix/id"
|
||||
@@ -25,13 +24,6 @@ const (
|
||||
|
||||
type roomSettings map[string]string
|
||||
|
||||
// settingsOld of a room
|
||||
type settingsOld struct {
|
||||
Mailbox string
|
||||
Owner id.UserID
|
||||
NoSender bool
|
||||
}
|
||||
|
||||
// Get option
|
||||
func (s roomSettings) Get(key string) string {
|
||||
return s[strings.ToLower(strings.TrimSpace(key))]
|
||||
@@ -70,29 +62,6 @@ func (s roomSettings) NoFiles() bool {
|
||||
return utils.Bool(s.Get(roomOptionNoFiles))
|
||||
}
|
||||
|
||||
// TODO: remove after migration
|
||||
func (b *Bot) migrateSettings(roomID id.RoomID) {
|
||||
var config settingsOld
|
||||
err := b.lp.GetClient().GetRoomAccountData(roomID, acRoomSettingsKey, &config)
|
||||
if err != nil {
|
||||
// any error = no need to migrate
|
||||
return
|
||||
}
|
||||
|
||||
if config.Mailbox == "" {
|
||||
return
|
||||
}
|
||||
cfg := roomSettings{}
|
||||
cfg.Set(roomOptionMailbox, config.Mailbox)
|
||||
cfg.Set(roomOptionOwner, config.Owner.String())
|
||||
cfg.Set(roomOptionNoSender, strconv.FormatBool(config.NoSender))
|
||||
|
||||
err = b.setRoomSettings(roomID, cfg)
|
||||
if err != nil {
|
||||
b.log.Error("cannot migrate settings: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (b *Bot) getRoomSettings(roomID id.RoomID) (roomSettings, error) {
|
||||
cfg := b.cfg.Get(roomID.String())
|
||||
if cfg != nil {
|
||||
|
||||
Reference in New Issue
Block a user