remove migrations
This commit is contained in:
@@ -45,7 +45,6 @@ env vars
|
|||||||
* **POSTMOOGLE_DB_DIALECT** - database dialect (postgres, sqlite3)
|
* **POSTMOOGLE_DB_DIALECT** - database dialect (postgres, sqlite3)
|
||||||
* **POSTMOOGLE_MAXSIZE** - max email size (including attachments) in megabytes
|
* **POSTMOOGLE_MAXSIZE** - max email size (including attachments) in megabytes
|
||||||
* **POSTMOOGLE_ADMINS** - a space-separated list of admin users. See `POSTMOOGLE_USERS` for syntax examples
|
* **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)
|
You can find default values in [config/defaults.go](config/defaults.go)
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ func New(
|
|||||||
log *logger.Logger,
|
log *logger.Logger,
|
||||||
prefix string,
|
prefix string,
|
||||||
domain string,
|
domain string,
|
||||||
envUsers []string,
|
|
||||||
admins []string,
|
admins []string,
|
||||||
) (*Bot, error) {
|
) (*Bot, error) {
|
||||||
b := &Bot{
|
b := &Bot{
|
||||||
@@ -50,7 +49,7 @@ func New(
|
|||||||
lp: lp,
|
lp: lp,
|
||||||
mu: map[id.RoomID]*sync.Mutex{},
|
mu: map[id.RoomID]*sync.Mutex{},
|
||||||
}
|
}
|
||||||
users, err := b.initBotUsers(envUsers)
|
users, err := b.initBotUsers()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -66,7 +65,7 @@ func New(
|
|||||||
}
|
}
|
||||||
b.allowedAdmins = allowedAdmins
|
b.allowedAdmins = allowedAdmins
|
||||||
|
|
||||||
b.commands = b.buildCommandList()
|
b.commands = b.initCommands()
|
||||||
|
|
||||||
return b, nil
|
return b, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ func (c commandList) get(key string) *command {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bot) buildCommandList() commandList {
|
func (b *Bot) initCommands() commandList {
|
||||||
return commandList{
|
return commandList{
|
||||||
// special commands
|
// special commands
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ func (b *Bot) syncRooms() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, roomID := range resp.JoinedRooms {
|
for _, roomID := range resp.JoinedRooms {
|
||||||
b.migrateSettings(roomID)
|
|
||||||
cfg, serr := b.getRoomSettings(roomID)
|
cfg, serr := b.getRoomSettings(roomID)
|
||||||
if serr != nil {
|
if serr != nil {
|
||||||
b.log.Warn("cannot get %s settings: %v", roomID, err)
|
b.log.Warn("cannot get %s settings: %v", roomID, err)
|
||||||
|
|||||||
@@ -40,25 +40,18 @@ func (s botSettings) Users() []string {
|
|||||||
return []string{value}
|
return []string{value}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bot) initBotUsers(envUsers []string) ([]string, error) {
|
func (b *Bot) initBotUsers() ([]string, error) {
|
||||||
config := b.getBotSettings()
|
config := b.getBotSettings()
|
||||||
cfgUsers := config.Users()
|
cfgUsers := config.Users()
|
||||||
if len(cfgUsers) > 0 {
|
if len(cfgUsers) > 0 {
|
||||||
// already migrated
|
|
||||||
return cfgUsers, nil
|
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)
|
return config.Users(), b.setBotSettings(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package bot
|
package bot
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"maunium.net/go/mautrix/id"
|
"maunium.net/go/mautrix/id"
|
||||||
@@ -25,13 +24,6 @@ const (
|
|||||||
|
|
||||||
type roomSettings map[string]string
|
type roomSettings map[string]string
|
||||||
|
|
||||||
// settingsOld of a room
|
|
||||||
type settingsOld struct {
|
|
||||||
Mailbox string
|
|
||||||
Owner id.UserID
|
|
||||||
NoSender bool
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get option
|
// Get option
|
||||||
func (s roomSettings) Get(key string) string {
|
func (s roomSettings) Get(key string) string {
|
||||||
return s[strings.ToLower(strings.TrimSpace(key))]
|
return s[strings.ToLower(strings.TrimSpace(key))]
|
||||||
@@ -70,29 +62,6 @@ func (s roomSettings) NoFiles() bool {
|
|||||||
return utils.Bool(s.Get(roomOptionNoFiles))
|
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) {
|
func (b *Bot) getRoomSettings(roomID id.RoomID) (roomSettings, error) {
|
||||||
cfg := b.cfg.Get(roomID.String())
|
cfg := b.cfg.Get(roomID.String())
|
||||||
if cfg != nil {
|
if cfg != nil {
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ func initBot(cfg *config.Config) {
|
|||||||
log.Fatal("cannot initialize matrix bot: %v", err)
|
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 {
|
if err != nil {
|
||||||
// nolint // Fatal = panic, not os.Exit()
|
// nolint // Fatal = panic, not os.Exit()
|
||||||
log.Fatal("cannot start matrix bot: %v", err)
|
log.Fatal("cannot start matrix bot: %v", err)
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ func New() *Config {
|
|||||||
NoEncryption: env.Bool("noencryption"),
|
NoEncryption: env.Bool("noencryption"),
|
||||||
MaxSize: env.Int("maxsize", defaultConfig.MaxSize),
|
MaxSize: env.Int("maxsize", defaultConfig.MaxSize),
|
||||||
StatusMsg: env.String("statusmsg", defaultConfig.StatusMsg),
|
StatusMsg: env.String("statusmsg", defaultConfig.StatusMsg),
|
||||||
Users: env.Slice("users"),
|
|
||||||
Admins: env.Slice("admins"),
|
Admins: env.Slice("admins"),
|
||||||
Sentry: Sentry{
|
Sentry: Sentry{
|
||||||
DSN: env.String("sentry.dsn", defaultConfig.Sentry.DSN),
|
DSN: env.String("sentry.dsn", defaultConfig.Sentry.DSN),
|
||||||
|
|||||||
@@ -22,8 +22,6 @@ type Config struct {
|
|||||||
MaxSize int
|
MaxSize int
|
||||||
// StatusMsg of the bot
|
// StatusMsg of the bot
|
||||||
StatusMsg string
|
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 holds list of admin users (wildcards supported), e.g.: @*:example.com, @bot.*:example.com, @admin:*. Empty = no admins
|
||||||
Admins []string
|
Admins []string
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user