In various places, we build messages using `Sprintf` before passing them
to `Notice()`.
If we let `Notice()` do string formatting, we run the chance of having
it try to format our already-preformatted text. If our text includes
format references (e.g. `%s`), it would cause a problem (`%s(MISSING)`).
One way to trigger it is to change the bot prefix from `!pm` to `%pm`.
Doing so, `sendHelp()` would create some help message which contains
`%pm` references. `Notice()` would then try to process them as well,
leading to a bunch of `%!p(MISSING)m` in the final text.
It previously said "the following commands" were supported
and it was only listing subcommands (help, stop, ..)
without any indication of how the user should construct the full command
(`PREFIX SUB_COMMAND`).
For perfect clarity, we now list full commands in the help message. Example:
> The following commands are supported:
>
> - !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)
The new help message is prefix-aware, instead of hardcodign `!pm`.
If the bot is running with a custom prefix (not `!pm`), this is even
more helpful, as it lets people know what the prefix is. Reading
documentation elsewhere and seeing `!pm STUFF` will no longer confuse
anyone.
With this change, we also make use of the existing `Notice()` function,
so we don't need to duplicate some code related to sending notices.
Without this, if settings are not found in account data (`M_NOT_FOUND`),
we won't initialize the map and we'll panic later:
> assignment to entry in nil map
Breaking settings for all new rooms is definitely not what we inteded.
Likely a regression since 726bc95c26, but related to fcac0a202d as
well.
This also adds `Mailbox()` and `Owner()` getters for completeness.
Wording has been changed a bit to avoid saying "that room". It sounds
better if it's "this room" or just "the room".
Sanitizing options on Get() ensures that when someone asks
for a given option which may not be defined (`nosubject`, `nosender`),
we'll return a valid value (`'true'` or `'false'`) and not `''` (empty
string, undefined).
This way, users do not need to wonder if "nosender is not set" is
handled like "true" or "false" or in some 3rd way. They also don't need
to think about "how to unset this setting, now that I've set it to something".
Options will appear to have a default sanitized value no matter if
they've explicitly been set or not.
The `NoSender()` and `NoSubject()` getters are just there for
convenience, so that we won't need to do casting in other places.
The configuration setting is called `Hide*` instead of `Show*`, because
it's backward compatible with existing configuration settings.
This is useful for when you setup an email forwarding inbox and you're
always sending to it through the same email address. In that case, you
don't need to see the email address in each Matrix message.
In the future, another similar `bool` setting (`hide-subject`) will land,
which controls whether the email's subject is shown in the final message
or not. That setting can make use of most of the same setup (all of
`handleBooleanConfigurationKey`).