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)
This commit is contained in:
@@ -16,6 +16,7 @@ type sanitizerFunc func(string) string
|
|||||||
type commandDefinition struct {
|
type commandDefinition struct {
|
||||||
key string
|
key string
|
||||||
description string
|
description string
|
||||||
|
isOption bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type commandList []commandDefinition
|
type commandList []commandDefinition
|
||||||
@@ -45,10 +46,12 @@ var (
|
|||||||
{
|
{
|
||||||
key: optionMailbox,
|
key: optionMailbox,
|
||||||
description: "Get or set mailbox of the room",
|
description: "Get or set mailbox of the room",
|
||||||
|
isOption: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: optionOwner,
|
key: optionOwner,
|
||||||
description: "Get or set owner of the room",
|
description: "Get or set owner of the room",
|
||||||
|
isOption: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: optionNoSender,
|
key: optionNoSender,
|
||||||
@@ -56,6 +59,7 @@ var (
|
|||||||
"Get or set `%s` of the room (`true` - hide email sender; `false` - show email sender)",
|
"Get or set `%s` of the room (`true` - hide email sender; `false` - show email sender)",
|
||||||
optionNoSender,
|
optionNoSender,
|
||||||
),
|
),
|
||||||
|
isOption: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: optionNoSubject,
|
key: optionNoSubject,
|
||||||
@@ -63,6 +67,7 @@ var (
|
|||||||
"Get or set `%s` of the room (`true` - hide email subject; `false` - show email subject)",
|
"Get or set `%s` of the room (`true` - hide email subject; `false` - show email subject)",
|
||||||
optionNoSubject,
|
optionNoSubject,
|
||||||
),
|
),
|
||||||
|
isOption: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: optionNoHTML,
|
key: optionNoHTML,
|
||||||
@@ -70,6 +75,7 @@ var (
|
|||||||
"Get or set `%s` of the room (`true` - ignore HTML in email; `false` - parse HTML in emails)",
|
"Get or set `%s` of the room (`true` - ignore HTML in email; `false` - parse HTML in emails)",
|
||||||
optionNoHTML,
|
optionNoHTML,
|
||||||
),
|
),
|
||||||
|
isOption: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: optionNoThreads,
|
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)",
|
"Get or set `%s` of the room (`true` - ignore email threads; `false` - convert email threads into matrix threads)",
|
||||||
optionNoThreads,
|
optionNoThreads,
|
||||||
),
|
),
|
||||||
|
isOption: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: optionNoFiles,
|
key: optionNoFiles,
|
||||||
@@ -84,6 +91,7 @@ var (
|
|||||||
"Get or set `%s` of the room (`true` - ignore email attachments; `false` - upload email attachments)",
|
"Get or set `%s` of the room (`true` - ignore email attachments; `false` - upload email attachments)",
|
||||||
optionNoFiles,
|
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) {
|
func (b *Bot) sendHelp(ctx context.Context, roomID id.RoomID) {
|
||||||
|
evt := eventFromContext(ctx)
|
||||||
|
|
||||||
var msg strings.Builder
|
var msg strings.Builder
|
||||||
msg.WriteString("The following commands are supported:\n\n")
|
msg.WriteString("The following commands are supported:\n\n")
|
||||||
for _, command := range commands {
|
for _, command := range commands {
|
||||||
@@ -159,7 +169,23 @@ func (b *Bot) sendHelp(ctx context.Context, roomID id.RoomID) {
|
|||||||
msg.WriteString(b.prefix)
|
msg.WriteString(b.prefix)
|
||||||
msg.WriteString(" ")
|
msg.WriteString(" ")
|
||||||
msg.WriteString(command.key)
|
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(command.description)
|
||||||
msg.WriteString("\n")
|
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) {
|
func (b *Bot) getOption(ctx context.Context, name string) {
|
||||||
msg := "`%s` of this room is `%s`"
|
|
||||||
|
|
||||||
evt := eventFromContext(ctx)
|
evt := eventFromContext(ctx)
|
||||||
cfg, err := b.getSettings(evt.RoomID)
|
|
||||||
|
value, err := b.getSettingsOption(evt.RoomID, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Error(ctx, evt.RoomID, "failed to retrieve settings: %v", err)
|
b.Error(ctx, evt.RoomID, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if value == nil {
|
||||||
value := cfg.Get(name)
|
|
||||||
if value == "" {
|
|
||||||
b.Notice(ctx, evt.RoomID, fmt.Sprintf("`%s` is not set, kupo.", name))
|
b.Notice(ctx, evt.RoomID, fmt.Sprintf("`%s` is not set, kupo.", name))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if name == optionMailbox {
|
b.Notice(ctx, evt.RoomID, fmt.Sprintf("`%s` of this room is `%s`", name, value))
|
||||||
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) {
|
func (b *Bot) setOption(ctx context.Context, name, value string) {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package bot
|
package bot
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -115,6 +116,24 @@ func (b *Bot) getSettings(roomID id.RoomID) (settings, error) {
|
|||||||
return config, err
|
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 {
|
func (b *Bot) setSettings(roomID id.RoomID, cfg settings) error {
|
||||||
return b.lp.GetClient().SetRoomAccountData(roomID, settingskey, cfg)
|
return b.lp.GetClient().SetRoomAccountData(roomID, settingskey, cfg)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user