From 0d88de9f77d6843c26909be4a13d778908eb82a7 Mon Sep 17 00:00:00 2001 From: Slavi Pantaleev Date: Sat, 27 Aug 2022 17:46:47 +0300 Subject: [PATCH 1/4] Show option values in help Before: > * **`!pm help`** - Show this help message > * **`!pm stop`** - Disable bridge for the room and clear all configuration > * **`!pm mailbox`** - Get or set mailbox of the room > * **`!pm owner`** - Get or set owner of the room > * **`!pm nosender`** - Get or set `nosender` of the room (`true` - hide email sender; `false` - show email sender) > * **`!pm nosubject`** - Get or set `nosubject` of the room (`true` - hide email subject; `false` - show email subject) > * **`!pm nohtml`** - Get or set `nohtml` of the room (`true` - ignore HTML in email; `false` - parse HTML in emails) > * **`!pm nothreads`** - Get or set `nothreads` of the room (`true` - ignore email threads; `false` - convert email threads into matrix threads) > * **`!pm nofiles`** - Get or set `nofiles` of the room (`true` - ignore email attachments; `false` - upload email attachments After: > * **`!pm help`** - Show this help message > * **`!pm stop`** - Disable bridge for the room and clear all configuration > * **`!pm mailbox`** (currently `something@example.com`) - Get or set mailbox of the room > * **`!pm owner`** (currently `@someone:example.com`) - Get or set owner of the room > * **`!pm nosender`** (currently `false`) - Get or set `nosender` of the room (`true` - hide email sender; `false` - show email sender) > * **`!pm nosubject`** (currently `true`) - Get or set `nosubject` of the room (`true` - hide email subject; `false` - show email subject) > * **`!pm nohtml`** (currently `false`) - Get or set `nohtml` of the room (`true` - ignore HTML in email; `false` - parse HTML in emails) > * **`!pm nothreads`** (currently `false`) - Get or set `nothreads` of the room (`true` - ignore email threads; `false` - convert email threads into matrix threads) > * **`!pm nofiles`** (currently `false`) - Get or set `nofiles` of the room (`true` - ignore email attachments; `false` - upload email attachments) --- bot/command.go | 45 ++++++++++++++++++++++++++++++++------------- bot/settings.go | 19 +++++++++++++++++++ 2 files changed, 51 insertions(+), 13 deletions(-) diff --git a/bot/command.go b/bot/command.go index ea19740..d514c2f 100644 --- a/bot/command.go +++ b/bot/command.go @@ -16,6 +16,7 @@ type sanitizerFunc func(string) string type commandDefinition struct { key string description string + isOption bool } type commandList []commandDefinition @@ -45,10 +46,12 @@ var ( { key: optionMailbox, description: "Get or set mailbox of the room", + isOption: true, }, { key: optionOwner, description: "Get or set owner of the room", + isOption: true, }, { key: optionNoSender, @@ -56,6 +59,7 @@ var ( "Get or set `%s` of the room (`true` - hide email sender; `false` - show email sender)", optionNoSender, ), + isOption: true, }, { key: optionNoSubject, @@ -63,6 +67,7 @@ var ( "Get or set `%s` of the room (`true` - hide email subject; `false` - show email subject)", optionNoSubject, ), + isOption: true, }, { key: optionNoHTML, @@ -70,6 +75,7 @@ var ( "Get or set `%s` of the room (`true` - ignore HTML in email; `false` - parse HTML in emails)", optionNoHTML, ), + isOption: true, }, { key: optionNoThreads, @@ -77,6 +83,7 @@ var ( "Get or set `%s` of the room (`true` - ignore email threads; `false` - convert email threads into matrix threads)", optionNoThreads, ), + isOption: true, }, { key: optionNoFiles, @@ -84,6 +91,7 @@ var ( "Get or set `%s` of the room (`true` - ignore email attachments; `false` - upload email attachments)", optionNoFiles, ), + isOption: true, }, } @@ -152,6 +160,8 @@ func (b *Bot) sendIntroduction(ctx context.Context, roomID id.RoomID) { } func (b *Bot) sendHelp(ctx context.Context, roomID id.RoomID) { + evt := eventFromContext(ctx) + var msg strings.Builder msg.WriteString("The following commands are supported:\n\n") for _, command := range commands { @@ -159,7 +169,23 @@ func (b *Bot) sendHelp(ctx context.Context, roomID id.RoomID) { msg.WriteString(b.prefix) msg.WriteString(" ") msg.WriteString(command.key) - msg.WriteString("`** - ") + msg.WriteString("`**") + + if command.isOption { + value, err := b.getSettingsOption(evt.RoomID, command.key) + if err != nil { + b.Error(ctx, evt.RoomID, err.Error()) + } else { + if value == nil { + msg.WriteString(" (currently not set)") + } else { + msg.WriteString(fmt.Sprintf(" (currently `%v`)", value)) + } + } + } + + msg.WriteString(" - ") + msg.WriteString(command.description) msg.WriteString("\n") } @@ -206,26 +232,19 @@ func (b *Bot) handleOption(ctx context.Context, command []string) { } func (b *Bot) getOption(ctx context.Context, name string) { - msg := "`%s` of this room is `%s`" - evt := eventFromContext(ctx) - cfg, err := b.getSettings(evt.RoomID) + + value, err := b.getSettingsOption(evt.RoomID, name) if err != nil { - b.Error(ctx, evt.RoomID, "failed to retrieve settings: %v", err) + b.Error(ctx, evt.RoomID, err.Error()) return } - - value := cfg.Get(name) - if value == "" { + if value == nil { b.Notice(ctx, evt.RoomID, fmt.Sprintf("`%s` is not set, kupo.", name)) return } - if name == optionMailbox { - value = fmt.Sprintf("%s@%s", value, b.domain) - } - - b.Notice(ctx, evt.RoomID, fmt.Sprintf(msg, name, value)) + b.Notice(ctx, evt.RoomID, fmt.Sprintf("`%s` of this room is `%s`", name, value)) } func (b *Bot) setOption(ctx context.Context, name, value string) { diff --git a/bot/settings.go b/bot/settings.go index ad37899..332d74f 100644 --- a/bot/settings.go +++ b/bot/settings.go @@ -1,6 +1,7 @@ package bot import ( + "fmt" "strconv" "strings" @@ -115,6 +116,24 @@ func (b *Bot) getSettings(roomID id.RoomID) (settings, error) { return config, err } +func (b *Bot) getSettingsOption(roomID id.RoomID, name string) (any, error) { + cfg, err := b.getSettings(roomID) + if err != nil { + return nil, fmt.Errorf("failed to retrieve settings: %v", err) + } + + value := cfg.Get(name) + if value == "" { + return nil, nil + } + + if name == optionMailbox { + value = fmt.Sprintf("%s@%s", value, b.domain) + } + + return value, nil +} + func (b *Bot) setSettings(roomID id.RoomID, cfg settings) error { return b.lp.GetClient().SetRoomAccountData(roomID, settingskey, cfg) } From 972b4c11c596c6d6592762cd9b50196905207d8d Mon Sep 17 00:00:00 2001 From: Slavi Pantaleev Date: Sat, 27 Aug 2022 19:21:18 +0300 Subject: [PATCH 2/4] Do not call getSettings() for each option in help Retrieving the settings object for each and every option was wasteful I don't like how we're doing custom formatting for optionMailbox in many different places. This should be redone. --- bot/command.go | 38 +++++++++++++++++++++++++------------- bot/settings.go | 19 ------------------- 2 files changed, 25 insertions(+), 32 deletions(-) diff --git a/bot/command.go b/bot/command.go index d514c2f..ebf08c9 100644 --- a/bot/command.go +++ b/bot/command.go @@ -162,6 +162,11 @@ func (b *Bot) sendIntroduction(ctx context.Context, roomID id.RoomID) { func (b *Bot) sendHelp(ctx context.Context, roomID id.RoomID) { evt := eventFromContext(ctx) + settings, settingsErr := b.getSettings(evt.RoomID) + if settingsErr != nil { + b.Error(ctx, evt.RoomID, settingsErr.Error()) + } + var msg strings.Builder msg.WriteString("The following commands are supported:\n\n") for _, command := range commands { @@ -171,16 +176,16 @@ func (b *Bot) sendHelp(ctx context.Context, roomID id.RoomID) { msg.WriteString(command.key) msg.WriteString("`**") - if command.isOption { - value, err := b.getSettingsOption(evt.RoomID, command.key) - if err != nil { - b.Error(ctx, evt.RoomID, err.Error()) + if command.isOption && settingsErr == nil { + value := settings.Get(command.key) + + if value == "" { + msg.WriteString(" (currently not set)") } else { - if value == nil { - msg.WriteString(" (currently not set)") - } else { - msg.WriteString(fmt.Sprintf(" (currently `%v`)", value)) + if command.key == optionMailbox { + value = fmt.Sprintf("%s@%s", value, b.domain) } + msg.WriteString(fmt.Sprintf(" (currently `%v`)", value)) } } @@ -232,19 +237,26 @@ func (b *Bot) handleOption(ctx context.Context, command []string) { } func (b *Bot) getOption(ctx context.Context, name string) { - evt := eventFromContext(ctx) + msg := "`%s` of this room is `%s`" - value, err := b.getSettingsOption(evt.RoomID, name) + evt := eventFromContext(ctx) + cfg, err := b.getSettings(evt.RoomID) if err != nil { - b.Error(ctx, evt.RoomID, err.Error()) + b.Error(ctx, evt.RoomID, "failed to retrieve settings: %v", err) return } - if value == nil { + + value := cfg.Get(name) + if value == "" { b.Notice(ctx, evt.RoomID, fmt.Sprintf("`%s` is not set, kupo.", name)) return } - b.Notice(ctx, evt.RoomID, fmt.Sprintf("`%s` of this room is `%s`", name, value)) + if name == optionMailbox { + value = fmt.Sprintf("%s@%s", value, b.domain) + } + + b.Notice(ctx, evt.RoomID, fmt.Sprintf(msg, name, value)) } func (b *Bot) setOption(ctx context.Context, name, value string) { diff --git a/bot/settings.go b/bot/settings.go index 332d74f..ad37899 100644 --- a/bot/settings.go +++ b/bot/settings.go @@ -1,7 +1,6 @@ package bot import ( - "fmt" "strconv" "strings" @@ -116,24 +115,6 @@ func (b *Bot) getSettings(roomID id.RoomID) (settings, error) { return config, err } -func (b *Bot) getSettingsOption(roomID id.RoomID, name string) (any, error) { - cfg, err := b.getSettings(roomID) - if err != nil { - return nil, fmt.Errorf("failed to retrieve settings: %v", err) - } - - value := cfg.Get(name) - if value == "" { - return nil, nil - } - - if name == optionMailbox { - value = fmt.Sprintf("%s@%s", value, b.domain) - } - - return value, nil -} - func (b *Bot) setSettings(roomID id.RoomID, cfg settings) error { return b.lp.GetClient().SetRoomAccountData(roomID, settingskey, cfg) } From c8331e99586a0b83d529a38888a9013f1f0d0c0f Mon Sep 17 00:00:00 2001 From: Slavi Pantaleev Date: Sat, 27 Aug 2022 19:35:45 +0300 Subject: [PATCH 3/4] Get rid of various duplicated optionMailbox formatting `formatOptionValue` takes care of these now. Besides fixing the duplication, this also fixes the lint error affecting `sendHelp` - high complexity. --- bot/command.go | 30 +++++++++++++----------------- bot/settings.go | 13 +++++++++++++ 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/bot/command.go b/bot/command.go index ebf08c9..f25c809 100644 --- a/bot/command.go +++ b/bot/command.go @@ -182,10 +182,7 @@ func (b *Bot) sendHelp(ctx context.Context, roomID id.RoomID) { if value == "" { msg.WriteString(" (currently not set)") } else { - if command.key == optionMailbox { - value = fmt.Sprintf("%s@%s", value, b.domain) - } - msg.WriteString(fmt.Sprintf(" (currently `%v`)", value)) + msg.WriteString(fmt.Sprintf(" (currently `%v`)", b.formatOptionValue(command.key, value))) } } @@ -237,8 +234,6 @@ func (b *Bot) handleOption(ctx context.Context, command []string) { } func (b *Bot) getOption(ctx context.Context, name string) { - msg := "`%s` of this room is `%s`" - evt := eventFromContext(ctx) cfg, err := b.getSettings(evt.RoomID) if err != nil { @@ -252,16 +247,14 @@ func (b *Bot) getOption(ctx context.Context, name string) { return } - if name == optionMailbox { - value = fmt.Sprintf("%s@%s", value, b.domain) - } - - b.Notice(ctx, evt.RoomID, fmt.Sprintf(msg, name, value)) + b.Notice(ctx, evt.RoomID, fmt.Sprintf( + "`%s` of this room is `%s`", + name, + b.formatOptionValue(name, value), + )) } func (b *Bot) setOption(ctx context.Context, name, value string) { - msg := "`%s` of this room set to `%s`" - sanitizer, ok := sanitizers[name] if ok { value = sanitizer(value) @@ -271,7 +264,7 @@ func (b *Bot) setOption(ctx context.Context, name, value string) { if name == optionMailbox { existingID, ok := b.GetMapping(value) if ok && existingID != "" && existingID != evt.RoomID { - b.Notice(ctx, evt.RoomID, fmt.Sprintf("Mailbox `%s@%s` already taken, kupo", value, b.domain)) + b.Notice(ctx, evt.RoomID, fmt.Sprintf("Mailbox `%s` already taken, kupo", b.formatOptionValue(name, value))) return } } @@ -289,9 +282,8 @@ func (b *Bot) setOption(ctx context.Context, name, value string) { cfg.Set(name, value) if name == optionMailbox { - value = fmt.Sprintf("%s@%s", value, b.domain) cfg.Set(optionOwner, evt.Sender.String()) - b.rooms.Store(value, evt.RoomID) + b.rooms.Store(b.formatOptionValue(name, value), evt.RoomID) } err = b.setSettings(evt.RoomID, cfg) @@ -300,5 +292,9 @@ func (b *Bot) setOption(ctx context.Context, name, value string) { return } - b.Notice(ctx, evt.RoomID, fmt.Sprintf(msg, name, value)) + b.Notice(ctx, evt.RoomID, fmt.Sprintf( + "`%s` of this room set to `%s`", + name, + b.formatOptionValue(name, value), + )) } diff --git a/bot/settings.go b/bot/settings.go index ad37899..66032a0 100644 --- a/bot/settings.go +++ b/bot/settings.go @@ -1,6 +1,7 @@ package bot import ( + "fmt" "strconv" "strings" @@ -118,3 +119,15 @@ func (b *Bot) getSettings(roomID id.RoomID) (settings, error) { func (b *Bot) setSettings(roomID id.RoomID, cfg settings) error { return b.lp.GetClient().SetRoomAccountData(roomID, settingskey, cfg) } + +func (b *Bot) formatOptionValue(name string, value string) string { + if value == "" { + return value + } + + if name == optionMailbox { + value = fmt.Sprintf("%s@%s", value, b.domain) + } + + return value +} From 53bc5e6d59c38ca84baa7f215464e7c4118fb431 Mon Sep 17 00:00:00 2001 From: Aine Date: Sat, 27 Aug 2022 21:59:58 +0300 Subject: [PATCH 4/4] proposed changes --- bot/command.go | 255 ++++++++++++++++++++++++------------------------ bot/message.go | 6 +- bot/settings.go | 21 +--- 3 files changed, 130 insertions(+), 152 deletions(-) diff --git a/bot/command.go b/bot/command.go index f25c809..bf900e7 100644 --- a/bot/command.go +++ b/bot/command.go @@ -11,103 +11,91 @@ import ( "gitlab.com/etke.cc/postmoogle/utils" ) -type sanitizerFunc func(string) string - -type commandDefinition struct { - key string - description string - isOption bool -} - -type commandList []commandDefinition - -func (c commandList) get(key string) (*commandDefinition, bool) { - for _, command := range c { - if command.key == key { - return &command, true - } - } - return nil, false -} - -var ( - commands = commandList{ - // special commands - { - key: "help", - description: "Show this help message", - }, - { - key: "stop", - description: "Disable bridge for the room and clear all configuration", - }, - - // options commands - { - key: optionMailbox, - description: "Get or set mailbox of the room", - isOption: true, - }, - { - key: optionOwner, - description: "Get or set owner of the room", - isOption: true, - }, - { - key: optionNoSender, - description: fmt.Sprintf( - "Get or set `%s` of the room (`true` - hide email sender; `false` - show email sender)", - optionNoSender, - ), - isOption: true, - }, - { - key: optionNoSubject, - description: fmt.Sprintf( - "Get or set `%s` of the room (`true` - hide email subject; `false` - show email subject)", - optionNoSubject, - ), - isOption: true, - }, - { - key: optionNoHTML, - description: fmt.Sprintf( - "Get or set `%s` of the room (`true` - ignore HTML in email; `false` - parse HTML in emails)", - optionNoHTML, - ), - isOption: true, - }, - { - key: optionNoThreads, - description: fmt.Sprintf( - "Get or set `%s` of the room (`true` - ignore email threads; `false` - convert email threads into matrix threads)", - optionNoThreads, - ), - isOption: true, - }, - { - key: optionNoFiles, - description: fmt.Sprintf( - "Get or set `%s` of the room (`true` - ignore email attachments; `false` - upload email attachments)", - optionNoFiles, - ), - isOption: true, - }, - } - - // sanitizers is map of option name => sanitizer function - sanitizers = map[string]sanitizerFunc{ - optionMailbox: utils.Mailbox, - optionNoSender: utils.SanitizeBoolString, - optionNoSubject: utils.SanitizeBoolString, - optionNoHTML: utils.SanitizeBoolString, - optionNoThreads: utils.SanitizeBoolString, - optionNoFiles: utils.SanitizeBoolString, +type ( + command struct { + key string + description string + sanitizer func(string) string } + commandList []command ) -func (b *Bot) handleCommand(ctx context.Context, evt *event.Event, command []string) { - if _, ok := commands.get(command[0]); !ok { +func (c commandList) get(key string) *command { + for _, cmd := range c { + if cmd.key == key { + return &cmd + } + } + return nil +} + +var commands = commandList{ + // special commands + { + key: "help", + description: "Show this help message", + }, + { + key: "stop", + description: "Disable bridge for the room and clear all configuration", + }, + {}, // delimiter + // options commands + { + key: optionMailbox, + description: "Get or set mailbox of the room", + sanitizer: utils.Mailbox, + }, + { + key: optionOwner, + description: "Get or set owner of the room", + sanitizer: func(s string) string { return s }, + }, + {}, // delimiter + { + key: optionNoSender, + description: fmt.Sprintf( + "Get or set `%s` of the room (`true` - hide email sender; `false` - show email sender)", + optionNoSender, + ), + sanitizer: utils.SanitizeBoolString, + }, + { + key: optionNoSubject, + description: fmt.Sprintf( + "Get or set `%s` of the room (`true` - hide email subject; `false` - show email subject)", + optionNoSubject, + ), + sanitizer: utils.SanitizeBoolString, + }, + { + key: optionNoHTML, + description: fmt.Sprintf( + "Get or set `%s` of the room (`true` - ignore HTML in email; `false` - parse HTML in emails)", + optionNoHTML, + ), + sanitizer: utils.SanitizeBoolString, + }, + { + key: optionNoThreads, + description: fmt.Sprintf( + "Get or set `%s` of the room (`true` - ignore email threads; `false` - convert email threads into matrix threads)", + optionNoThreads, + ), + sanitizer: utils.SanitizeBoolString, + }, + { + key: optionNoFiles, + description: fmt.Sprintf( + "Get or set `%s` of the room (`true` - ignore email attachments; `false` - upload email attachments)", + optionNoFiles, + ), + sanitizer: utils.SanitizeBoolString, + }, +} + +func (b *Bot) handleCommand(ctx context.Context, evt *event.Event, commandSlice []string) { + if cmd := commands.get(commandSlice[0]); cmd == nil { return } @@ -116,13 +104,13 @@ func (b *Bot) handleCommand(ctx context.Context, evt *event.Event, command []str return } - switch command[0] { + switch commandSlice[0] { case "help": b.sendHelp(ctx, evt.RoomID) case "stop": b.runStop(ctx, true) default: - b.handleOption(ctx, command) + b.handleOption(ctx, commandSlice) } } @@ -162,33 +150,42 @@ func (b *Bot) sendIntroduction(ctx context.Context, roomID id.RoomID) { func (b *Bot) sendHelp(ctx context.Context, roomID id.RoomID) { evt := eventFromContext(ctx) - settings, settingsErr := b.getSettings(evt.RoomID) - if settingsErr != nil { - b.Error(ctx, evt.RoomID, settingsErr.Error()) + cfg, serr := b.getSettings(evt.RoomID) + if serr != nil { + b.log.Error("cannot retrieve settings: %v", serr) } var msg strings.Builder msg.WriteString("The following commands are supported:\n\n") - for _, command := range commands { + for _, cmd := range commands { + if cmd.key == "" { + msg.WriteString("\n---\n") + continue + } msg.WriteString("* **`") msg.WriteString(b.prefix) msg.WriteString(" ") - msg.WriteString(command.key) + msg.WriteString(cmd.key) msg.WriteString("`**") - - if command.isOption && settingsErr == nil { - value := settings.Get(command.key) - - if value == "" { - msg.WriteString(" (currently not set)") - } else { - msg.WriteString(fmt.Sprintf(" (currently `%v`)", b.formatOptionValue(command.key, value))) + value := cfg.Get(cmd.key) + if cmd.sanitizer != nil { + switch value != "" { + case false: + msg.WriteString("(currently not set)") + case true: + msg.WriteString("(currently `") + msg.WriteString(value) + if cmd.key == optionMailbox { + msg.WriteString("@") + msg.WriteString(b.domain) + } + msg.WriteString("`)") } } msg.WriteString(" - ") - msg.WriteString(command.description) + msg.WriteString(cmd.description) msg.WriteString("\n") } @@ -225,12 +222,12 @@ func (b *Bot) runStop(ctx context.Context, checkAllowed bool) { b.Notice(ctx, evt.RoomID, "mailbox has been disabled") } -func (b *Bot) handleOption(ctx context.Context, command []string) { - if len(command) == 1 { - b.getOption(ctx, command[0]) +func (b *Bot) handleOption(ctx context.Context, cmd []string) { + if len(cmd) == 1 { + b.getOption(ctx, cmd[0]) return } - b.setOption(ctx, command[0], command[1]) + b.setOption(ctx, cmd[0], cmd[1]) } func (b *Bot) getOption(ctx context.Context, name string) { @@ -247,24 +244,24 @@ func (b *Bot) getOption(ctx context.Context, name string) { return } - b.Notice(ctx, evt.RoomID, fmt.Sprintf( - "`%s` of this room is `%s`", - name, - b.formatOptionValue(name, value), - )) + if name == optionMailbox { + value = value + "@" + b.domain + } + + b.Notice(ctx, evt.RoomID, fmt.Sprintf("`%s` of this room is `%s`", name, value)) } func (b *Bot) setOption(ctx context.Context, name, value string) { - sanitizer, ok := sanitizers[name] - if ok { - value = sanitizer(value) + cmd := commands.get(name) + if cmd != nil { + value = cmd.sanitizer(value) } evt := eventFromContext(ctx) if name == optionMailbox { existingID, ok := b.GetMapping(value) if ok && existingID != "" && existingID != evt.RoomID { - b.Notice(ctx, evt.RoomID, fmt.Sprintf("Mailbox `%s` already taken, kupo", b.formatOptionValue(name, value))) + b.Notice(ctx, evt.RoomID, fmt.Sprintf("Mailbox `%s@%s` already taken, kupo", value, b.domain)) return } } @@ -283,7 +280,7 @@ func (b *Bot) setOption(ctx context.Context, name, value string) { cfg.Set(name, value) if name == optionMailbox { cfg.Set(optionOwner, evt.Sender.String()) - b.rooms.Store(b.formatOptionValue(name, value), evt.RoomID) + b.rooms.Store(value, evt.RoomID) } err = b.setSettings(evt.RoomID, cfg) @@ -292,9 +289,9 @@ func (b *Bot) setOption(ctx context.Context, name, value string) { return } - b.Notice(ctx, evt.RoomID, fmt.Sprintf( - "`%s` of this room set to `%s`", - name, - b.formatOptionValue(name, value), - )) + if name == optionMailbox { + value = value + "@" + b.domain + } + + b.Notice(ctx, evt.RoomID, fmt.Sprintf("`%s` of this room set to `%s`", name, value)) } diff --git a/bot/message.go b/bot/message.go index 9cdf2f1..48d8063 100644 --- a/bot/message.go +++ b/bot/message.go @@ -13,10 +13,10 @@ func (b *Bot) handle(ctx context.Context) { return } message := strings.TrimSpace(content.Body) - command := b.parseCommand(message) - if command == nil { + cmd := b.parseCommand(message) + if cmd == nil { return } - b.handleCommand(ctx, evt, command) + b.handleCommand(ctx, evt, cmd) } diff --git a/bot/settings.go b/bot/settings.go index 66032a0..d1f7f2e 100644 --- a/bot/settings.go +++ b/bot/settings.go @@ -1,7 +1,6 @@ package bot import ( - "fmt" "strconv" "strings" @@ -36,13 +35,7 @@ func (s settings) Allowed(noowner bool, userID id.UserID) bool { // Get option func (s settings) Get(key string) string { - value := s[strings.ToLower(strings.TrimSpace(key))] - - sanitizer, ok := sanitizers[key] - if ok { - return sanitizer(value) - } - return value + return s[strings.ToLower(strings.TrimSpace(key))] } func (s settings) Mailbox() string { @@ -119,15 +112,3 @@ func (b *Bot) getSettings(roomID id.RoomID) (settings, error) { func (b *Bot) setSettings(roomID id.RoomID, cfg settings) error { return b.lp.GetClient().SetRoomAccountData(roomID, settingskey, cfg) } - -func (b *Bot) formatOptionValue(name string, value string) string { - if value == "" { - return value - } - - if name == optionMailbox { - value = fmt.Sprintf("%s@%s", value, b.domain) - } - - return value -}