Commit Graph

292 Commits

Author SHA1 Message Date
Aine
d1c48b9b31 add per-room mutex, possibly fixes #8 2022-08-27 22:10:22 +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
Slavi Pantaleev
275ccbd9e5 Implement feedback 2022-08-27 08:11:36 +03:00
Slavi Pantaleev
1100ee6b5f Improve error when configuration reading fails 2022-08-27 07:51:56 +03:00
Slavi Pantaleev
58a1fa6b3f Do not check cognitive complexity in unit tests
Works around:

> utils/user_test.go:5:1: cognitive complexity 18 of func `TestRuleToRegex` is high (> 15) (gocognit)

Alternatively, we may look for a way to skip this test only.
It doesn't seem complex at all, so it looks like some false-positive.
2022-08-27 07:50:43 +03:00
Slavi Pantaleev
698cb6b8b9 Fix imports lint error 2022-08-27 07:50:43 +03:00
Slavi Pantaleev
bb754f9aa8 Simplify MatchUserWithAllowedRegexes
This used to return an error back when it was dealing with wildcards
(which may or may not have compiled to a valid regex).

But it now deals with pre-compiled regexes and has no chance of failing,
so we need no `error` returns.
2022-08-27 07:50:43 +03:00
Slavi Pantaleev
f8a168b8e7 Add a few more unit test cases 2022-08-27 07:50:43 +03:00
Slavi Pantaleev
8ad2e29930 Add support for configuring user whitelisting
This does not do anything useful just yet.
It will be hooked to access control checks later on.

Wildcards are converted to regular expressions, because it was simpler
to do that than to write (or include) some ugly wildcard matcher library.
It also provides more flexibility, should we wish to use it later.
Regular expressions should also work well performance-wise.

We compile wildcards to regexes early on (during configuration
processing) and fail if we detect a bad pattern. This is meant to
catch various problems (typos or other mistakes) that could happen.

For this to work, configuration building had to be redone, since it can
now return an error. This may be useful in the future for validating
other configuration settings.

Related to https://gitlab.com/etke.cc/postmoogle/-/issues/1
2022-08-27 07:50:41 +03:00
Aine
9484758f33 optimize introductions and help, kupo 2022-08-26 23:19:59 +03:00
Aine
f2d81495dc refactor Send(), fixes #6 2022-08-26 23:06:20 +03:00
Aine
4000b39480 add custom status message 2022-08-26 16:40:43 +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
Aine
a7877cac00 Merge branch 'ignore-cover-out-file' into 'main'
Add cover.out to .gitignore

See merge request etke.cc/postmoogle!19
2022-08-26 12:33:15 +00:00
Aine
e6fd5a38d7 Merge branch 'code-formatted-option-value' into 'main'
Format option value as code

See merge request etke.cc/postmoogle!18
2022-08-26 12:32:56 +00: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
6bceea6bee Add cover.out to .gitignore
If tests (`make test`) fail, the file won't be removed and the git
working tree will appear dirty. Someone might accidentally commit this
`cover.out` file.
2022-08-26 09:46:15 +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
Aine
8419386a95 Merge branch 'introduction-on-join' into 'main'
Send introduction text and help after the bot joins a room

See merge request etke.cc/postmoogle!16
2022-08-25 18:44:44 +00:00
Slavi Pantaleev
8507af670a exists -> ok 2022-08-25 21:44:06 +03:00
Slavi Pantaleev
a093de51c4 Remove some useless sentry spans 2022-08-25 21:41:25 +03:00
Slavi Pantaleev
06856adb86 Simplify code 2022-08-25 21:38:42 +03:00
Aine
8d88d4a929 Merge branch 'strip-style' into 'main'
strip <style> in html emails

See merge request etke.cc/postmoogle!17
2022-08-25 18:30:06 +00:00
Aine
331c2a8d5e strip <style> in html emails 2022-08-25 21:27:00 +03:00
Slavi Pantaleev
236a128129 Fix double membership=join event handling
This fixes the problem mentioned in 8e1aa5b11c.

Turns out that it's a long-standing Synapse bug:
https://github.com/matrix-org/synapse/issues/9768
2022-08-25 20:18:09 +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
Aine
3495c60f24 Merge branch 'safer-notice' into 'main'
Make Notice() not do string formatting anymore

See merge request etke.cc/postmoogle!15
2022-08-25 08:16:48 +00: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
Aine
7e1b7f5c08 Merge branch 'better-help' into 'main'
Improve sendHelp() to show full commands

See merge request etke.cc/postmoogle!14
2022-08-25 06:40:50 +00: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
7e5ae78ba2 Merge branch 'relations' into 'main'
threads

See merge request etke.cc/postmoogle!13
2022-08-24 18:42:11 +00:00
Aine
f9cf94c914 threads 2022-08-24 21:28:30 +03:00
Aine
5b76afc0eb Merge branch 'ensure-settings-always-initialized' into 'main'
Ensure settings map is always initialized

See merge request etke.cc/postmoogle!12
2022-08-24 09:26:08 +00:00
Slavi Pantaleev
ed5ff6456a Ensure settings map is always initialized
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.
2022-08-24 12:22:19 +03:00
Aine
ef22ca03d9 Merge branch 'ordered-commands' into 'main'
Revert "visual fixes"

See merge request etke.cc/postmoogle!11
2022-08-24 09:10:10 +00:00
Aine
d021e6715e Revert "visual fixes"
This reverts commit 34735b2614.
2022-08-24 12:09:23 +03:00
Aine
8d4cb1d883 Merge branch 'ordered-commands' into 'main'
Use a command list (not a map) to have a consistent manually-defined commands order

See merge request etke.cc/postmoogle!10
2022-08-24 09:05:54 +00: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