From 60d3fbbba5263d31233aca26d711aaeccf698d91 Mon Sep 17 00:00:00 2001 From: Slavi Pantaleev Date: Wed, 31 Aug 2022 09:08:49 +0300 Subject: [PATCH 1/2] Improve introduction and getters usability When someone first joins a room, they see some commands (`mailbox`, `owner`, ..) and they know they are getters and setters, but they have no good example as to how to use them. Is it `!pm mailbox SOMETHING` or `!pm mailbox=SOMETHING` or something else? It's better if the introduction text gives you the full command you need to get started (e.g. `!pm mailbox SOME_MAILBOX`), instead of a partial command that you don't know how to use (e.g. `!pm mailbox` - this is merely a getter and will not set your mailbox to `SOME_MAILBOX`). Starting from this, I thought it would be a good idea to make all option getters tell you how the commands are to be used. If you send `!pm mailbox` and it tells you "not yet set", it should also tell you how to actually set it (e.g. `!pm mailbox VALUE`). --- bot/command.go | 2 +- bot/command_owner.go | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/bot/command.go b/bot/command.go index 09ba665..7fa6f36 100644 --- a/bot/command.go +++ b/bot/command.go @@ -181,7 +181,7 @@ func (b *Bot) sendIntroduction(ctx context.Context, roomID id.RoomID) { msg.WriteString(b.prefix) msg.WriteString(" ") msg.WriteString(roomOptionMailbox) - msg.WriteString("` command.\n") + msg.WriteString(" SOME_INBOX` command.\n") msg.WriteString("You will then be able to send emails to `SOME_INBOX@") msg.WriteString(b.domain) diff --git a/bot/command_owner.go b/bot/command_owner.go index becd5fe..49619c3 100644 --- a/bot/command_owner.go +++ b/bot/command_owner.go @@ -3,6 +3,7 @@ package bot import ( "context" "fmt" + "strings" ) func (b *Bot) runStop(ctx context.Context) { @@ -48,7 +49,15 @@ func (b *Bot) getOption(ctx context.Context, name string) { value := cfg.Get(name) if value == "" { - b.SendNotice(ctx, evt.RoomID, fmt.Sprintf("`%s` is not set, kupo.", name)) + var msg strings.Builder + msg.WriteString(fmt.Sprintf("`%s` is not set, kupo.", name)) + msg.WriteString("\n") + msg.WriteString(fmt.Sprintf( + "To set it, send a `%s %s VALUE` command.", + b.prefix, + name, + )) + b.SendNotice(ctx, evt.RoomID, msg.String()) return } @@ -56,7 +65,15 @@ func (b *Bot) getOption(ctx context.Context, name string) { value = value + "@" + b.domain } - b.SendNotice(ctx, evt.RoomID, fmt.Sprintf("`%s` of this room is `%s`", name, value)) + var msg strings.Builder + msg.WriteString(fmt.Sprintf("`%s` of this room is `%s`", name, value)) + msg.WriteString("\n") + msg.WriteString(fmt.Sprintf( + "To set it to a new value, send a `%s %s VALUE` command.", + b.prefix, + name, + )) + b.SendNotice(ctx, evt.RoomID, msg.String()) } func (b *Bot) setOption(ctx context.Context, name, value string) { From ab95fe5d2dd5d3eac2287fbc98b9f1b02b1b64c4 Mon Sep 17 00:00:00 2001 From: Aine Date: Wed, 31 Aug 2022 10:39:30 +0300 Subject: [PATCH 2/2] refactor to fmt.Sprintf() --- bot/command_owner.go | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/bot/command_owner.go b/bot/command_owner.go index 49619c3..e8aa69a 100644 --- a/bot/command_owner.go +++ b/bot/command_owner.go @@ -3,7 +3,6 @@ package bot import ( "context" "fmt" - "strings" ) func (b *Bot) runStop(ctx context.Context) { @@ -49,15 +48,10 @@ func (b *Bot) getOption(ctx context.Context, name string) { value := cfg.Get(name) if value == "" { - var msg strings.Builder - msg.WriteString(fmt.Sprintf("`%s` is not set, kupo.", name)) - msg.WriteString("\n") - msg.WriteString(fmt.Sprintf( + msg := fmt.Sprintf("`%s` is not set, kupo.\n"+ "To set it, send a `%s %s VALUE` command.", - b.prefix, - name, - )) - b.SendNotice(ctx, evt.RoomID, msg.String()) + name, b.prefix, name) + b.SendNotice(ctx, evt.RoomID, msg) return } @@ -65,15 +59,10 @@ func (b *Bot) getOption(ctx context.Context, name string) { value = value + "@" + b.domain } - var msg strings.Builder - msg.WriteString(fmt.Sprintf("`%s` of this room is `%s`", name, value)) - msg.WriteString("\n") - msg.WriteString(fmt.Sprintf( + msg := fmt.Sprintf("`%s` of this room is `%s`\n"+ "To set it to a new value, send a `%s %s VALUE` command.", - b.prefix, - name, - )) - b.SendNotice(ctx, evt.RoomID, msg.String()) + name, value, b.prefix, name) + b.SendNotice(ctx, evt.RoomID, msg) } func (b *Bot) setOption(ctx context.Context, name, value string) {