remove migrations
This commit is contained in:
@@ -45,7 +45,6 @@ env vars
|
||||
* **POSTMOOGLE_DB_DIALECT** - database dialect (postgres, sqlite3)
|
||||
* **POSTMOOGLE_MAXSIZE** - max email size (including attachments) in megabytes
|
||||
* **POSTMOOGLE_ADMINS** - a space-separated list of admin users. See `POSTMOOGLE_USERS` for syntax examples
|
||||
* <s>**POSTMOOGLE_USERS**</s> - deprecated and ignored, use `!pm users` instead
|
||||
|
||||
You can find default values in [config/defaults.go](config/defaults.go)
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -83,7 +83,7 @@ func initBot(cfg *config.Config) {
|
||||
log.Fatal("cannot initialize matrix bot: %v", err)
|
||||
}
|
||||
|
||||
mxb, err = bot.New(lp, mxlog, cfg.Prefix, cfg.Domain, cfg.Users, cfg.Admins)
|
||||
mxb, err = bot.New(lp, mxlog, cfg.Prefix, cfg.Domain, cfg.Admins)
|
||||
if err != nil {
|
||||
// nolint // Fatal = panic, not os.Exit()
|
||||
log.Fatal("cannot start matrix bot: %v", err)
|
||||
|
||||
@@ -20,7 +20,6 @@ func New() *Config {
|
||||
NoEncryption: env.Bool("noencryption"),
|
||||
MaxSize: env.Int("maxsize", defaultConfig.MaxSize),
|
||||
StatusMsg: env.String("statusmsg", defaultConfig.StatusMsg),
|
||||
Users: env.Slice("users"),
|
||||
Admins: env.Slice("admins"),
|
||||
Sentry: Sentry{
|
||||
DSN: env.String("sentry.dsn", defaultConfig.Sentry.DSN),
|
||||
|
||||
@@ -22,8 +22,6 @@ type Config struct {
|
||||
MaxSize int
|
||||
// StatusMsg of the bot
|
||||
StatusMsg string
|
||||
// Users DEPRECATED holds list of allowed users (wildcards supported), e.g.: @*:example.com, @bot.*:example.com, @admin:*. Empty = homeserver only
|
||||
Users []string
|
||||
// Admins holds list of admin users (wildcards supported), e.g.: @*:example.com, @bot.*:example.com, @admin:*. Empty = no admins
|
||||
Admins []string
|
||||
|
||||
|
||||
Reference in New Issue
Block a user