Commit Graph

60 Commits

Author SHA1 Message Date
Aine
715ec1ef2a fix #19 2022-09-07 20:24:49 +03:00
Aine
4d01579505 move email sending to b.runSend() 2022-09-06 22:43:04 +03:00
Aine
2427d41ae3 move parsing of !pm send to utils, update !pm send instructions 2022-09-05 20:10:07 +03:00
Aine
12a2d4c6f9 dkim 2022-09-05 17:02:00 +03:00
Aine
fda0d62087 send emails 2022-09-04 22:09:53 +03:00
Aine
a3c81ab232 Merge branch 'better-introduction' into 'main'
Improve introduction and getters usability

See merge request etke.cc/postmoogle!26
2022-08-31 07:40:25 +00:00
Aine
104e948b9c remove migrations 2022-08-31 10:33:13 +03:00
Slavi Pantaleev
60d3fbbba5 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`).
2022-08-31 09:08:49 +03:00
Aine
75e5ed8245 Merge branch 'improve-help-wording' into 'main'
Improve help message wording

See merge request etke.cc/postmoogle!25
2022-08-30 16:43:02 +00:00
Slavi Pantaleev
7315013912 Improve help message wording
If're an admin and mess up the `users` list, you won't see "owner"
commands.

If you're just a regular room user (not an admin, not an owner), you'll
only see the `help` command in the `help` message.

Both of these situations may make you wonder:

- is that all there is?
- earlier I saw more commands, so what's going on?

Adding "and accessible to you" hopefully clears things up, or at least
it tries to make the help message more correct.
2022-08-30 19:04:44 +03:00
Aine
9f66d1fee6 rename options, rename settings types 2022-08-30 14:45:07 +03:00
Aine
5ed3a53223 diff bot and room settings 2022-08-30 14:37:19 +03:00
Aine
f97ebb604a manage users in runtime, closes #16 2022-08-29 21:41:14 +03:00
Aine
ba73b5a97c add !pm delete, closes #13 2022-08-29 20:18:25 +03:00
Aine
505a1b42d7 removed federation, closes #12 2022-08-29 19:58:54 +03:00
Aine
1a87929567 rename files; show commands by access level 2022-08-29 15:19:07 +03:00
Slavi Pantaleev
bc30f59e96 Move owner commands to their own file 2022-08-29 14:25:14 +03:00
Slavi Pantaleev
d20d4aa5bf Move mailboxes admin command to a separate file 2022-08-29 14:20:20 +03:00
Aine
6623251695 refactored 2022-08-29 12:30:43 +03:00
Slavi Pantaleev
79775c0c13 Add basic mailboxes command
This can be improved in the future, to show some additional information
about each mailbox like:

- "how many users are in that room"
- "which users are in that room"
- "who is the owner of the mailbox"

This can all be done later though.
2022-08-29 10:28:19 +03:00
Slavi Pantaleev
a057654962 Put command access checks on the command level
Checking using `settings.Allowed` is odd. Not all commands are related
to setting configuration settings. Admin commands are coming in the
future, for which this is certainly not the case.

We now do access checks early on (during command processing), so command
handlers can be clean of access checks. If we're inside of a command
handler, the user is privileged to run it.
2022-08-29 10:27:53 +03:00
Aine
77a7e9efc6 Merge branch 'show-option-value-in-help' into 'main'
Show option values in help

See merge request etke.cc/postmoogle!21
2022-08-28 15:37:29 +00:00
Aine
bd14987561 move settings.Allowed() to bot.Allowed() 2022-08-28 18:36:01 +03:00
Slavi Pantaleev
dc5ed41723 Merge branch 'main' into 'user-whitelisting'
# Conflicts:
#   bot/bot.go
2022-08-28 14:50:57 +00:00
Aine
13776ad7a6 properly update mailbox, fixes #9 2022-08-28 09:37:18 +03:00
Aine
53bc5e6d59 proposed changes 2022-08-27 21:59:58 +03:00
Slavi Pantaleev
c8331e9958 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.
2022-08-27 19:35:45 +03:00
Slavi Pantaleev
972b4c11c5 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.
2022-08-27 19:22:21 +03:00
Slavi Pantaleev
0d88de9f77 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)
2022-08-27 17:47:16 +03:00
Slavi Pantaleev
3bc10bfe4f Honor allowed users list 2022-08-27 17:29:00 +03:00
Aine
9484758f33 optimize introductions and help, kupo 2022-08-26 23:19:59 +03:00
Aine
2da1aacc7a automatically remove mailboxes in empty rooms, fixes #3 2022-08-26 16:22:44 +03:00
Aine
2dcba843cc add 'nofiles' option, refactored bot.Send(); fixes #2 2022-08-26 16:11:08 +03:00
Aine
42c9e15619 add 'nothreads' option, fixes #4 2022-08-26 16:00:37 +03:00
Aine
41a52c1eca add 'nohtml' option, fixes #5 2022-08-26 15:56:25 +03:00
Slavi Pantaleev
a8e8b23174 Make sure mailbox value is formatted correctly in getOption/setOption 2022-08-26 09:58:57 +03:00
Slavi Pantaleev
5c443ec7aa Format options as code in getOption as well
This is like 10f44e621d (which handled `setOption()`), but for `getOption()`.
2022-08-26 09:58:25 +03:00
Slavi Pantaleev
10f44e621d Format option value as code 2022-08-26 07:46:50 +03:00
Aine
0a5bc5d989 refactor rooms/roomsmu to sync.Map 2022-08-25 22:38:45 +03:00
Aine
b0c274491f refactor to context, remove sentry spans 2022-08-25 22:31:12 +03:00
Slavi Pantaleev
8e1aa5b11c [WIP] Send introduction text and help after the bot joins a room
This appears to work, except that the join event is triggered twice,
and we send the (introduction + help) twice.
2022-08-25 11:58:18 +03:00
Slavi Pantaleev
1babbb7169 Make Notice() not do string formatting anymore
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.
2022-08-25 10:55:15 +03:00
Slavi Pantaleev
e7610a34a3 Decrease number of WriteString() calls in sendHelp() 2022-08-25 09:03:22 +03:00
Slavi Pantaleev
cda8ee0a25 Improve sendHelp() to show full commands
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.
2022-08-25 08:33:28 +03:00
Aine
d021e6715e Revert "visual fixes"
This reverts commit 34735b2614.
2022-08-24 12:09:23 +03:00
Aine
34735b2614 visual fixes 2022-08-24 12:02:41 +03:00
Slavi Pantaleev
afe24beb4d Use a command list (not a map) to have a consistent manually-defined commands order 2022-08-24 11:39:24 +03:00
Slavi Pantaleev
26edcdadbc Use string constants for options, not magic strings
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".
2022-08-24 10:56:47 +03:00
Aine
d361e31a60 adjust stop's help message 2022-08-24 09:57:22 +03:00
Aine
82b84e3c35 Merge branch 'stop' into 'main'
add '!pm stop'

See merge request etke.cc/postmoogle!7
2022-08-24 06:41:15 +00:00