Commit Graph
498 Commits
Author SHA1 Message Date
gnuxie 5164e48149 Rename MakeRoomAdminCommand to HijackRoomCommand 2023-01-31 20:00:14 +00:00
gnuxie 72f554ef2e Improve HTTP Error handling.
So as a history lesson.
The Matrix Bot SDK uses the npm library "requests".
When there was a http error, matrix-bot-sdk
would literally throw the response object.
This would be a horrible 1000+line long thing to accidentally
be logged to the console via node's inspect.
Though it was inevitable since you can't be sure every catch
was handling the error correctly. Irregardless, the solution
developed at Element was to create an error object
that had concise details.
This was great, however, within the matrix-bot-sdk there is
[this](https://github.com/Half-Shot/matrix-bot-sdk/blob/f58d7ea6e24d1db8b9b8009dea4cd97cbff54d0c/src/http.ts#L66)
awful line of code which logs every http error as error using the
matrix-bot-sdk logger.
This wastes so much log space and causes alarm fatigue,
rather than muting the module, the action instead taken
was to redact stack traces from http errors.
This was not a good idea.
Eventually matrix-bot-sdk was updated to have a MatrixError type
when a request was performed via the client-server api that had an
error.
matrix-appservice-bridge depends upon this and so Mjolnir now needs
to be updated to throw MatrixError's.
We have gone a step further in this commit and also muted
the matrix-bot-sdk http module, to stop the alarm fatigue problem
https://github.com/turt2live/matrix-bot-sdk/pull/158
2023-01-31 19:57:56 +00:00
gnuxie 277140240a Catch exceptions from commands better by giving them a uuid.
They can then be used as a reference to look for in the logs.
The MakeAdminCommand has been refactored as an example.
2023-01-31 19:57:56 +00:00
gnuxie 7a076033a3 Protect Draupnir from matrix-bot-sdk 2023-01-31 18:25:42 +00:00
gnuxie fda74c1aad Keyword argument (aka options/flags) support. 2023-01-19 17:56:48 +00:00
gnuxie b28a795d04 Stop MatrixRoomReference relying on bot-sdk's MatrixClient 2023-01-19 17:56:48 +00:00
gnuxie 9efdb241ad Allow command tables to be named with symbols to ease testing. 2023-01-19 17:56:48 +00:00
gnuxie 719d7a93d0 htmlEscape when serializing TextNodes to html 2023-01-19 17:56:48 +00:00
gnuxie d17d94a80a Update TypeScript so it can infer from narrowing unknown. 2023-01-19 17:56:48 +00:00
dependabot[bot] 41d9acc32f Bump json5 from 1.0.1 to 1.0.2 (#3)
Bumps [json5](https://github.com/json5/json5) from 1.0.1 to 1.0.2.
- [Release notes](https://github.com/json5/json5/releases)
- [Changelog](https://github.com/json5/json5/blob/main/CHANGELOG.md)
- [Commits](https://github.com/json5/json5/compare/v1.0.1...v1.0.2)

---
updated-dependencies:
- dependency-name: json5
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-01-14 23:22:28 +00:00
Gnuxie bb125b3828 Dockerhub gnuxie/draupnir (#2)
Change old matrix.org/mjolnir references in github actions.
2023-01-14 22:43:39 +00:00
Gnuxie cccace8ef8 Merge pull request #1 from Gnuxie/gnuxie/command-reader
Add framework for parsing commands & hard fork Mjolnir
2023-01-14 20:15:35 +00:00
gnuxie 270910a317 note about status incase there are stragglers 2023-01-14 19:56:26 +00:00
gnuxie df671e1778 Place unban/ban back into the legacy command handler for now.
We haven't changed this yet and I'd like to merge the current changes
to the new command framework before we go to town changing all the legacy commands.
2023-01-14 19:51:37 +00:00
gnuxie b3f9fbe0af Remove stale test
Yes a test should probably be written for this, even if just as a debug
utility. This test just wasn't testing much regardless and
time needs to be put aside to do it properly.

The feature is still under development though.
2023-01-14 19:05:51 +00:00
gnuxie ccc17c4750 Add Utility for testing appservice commands in integration tests. 2023-01-14 19:00:33 +00:00
gnuxie 052ded0f30 Tidy up the interface-manager lint & doc. 2023-01-14 18:33:06 +00:00
gnuxie 0be83ae8ce We can now render to Matrix using JSX. 2023-01-14 18:33:06 +00:00
gnuxie 4b7e6637fa OK, it's plugged in, now how to test it 2023-01-14 18:33:06 +00:00
gnuxie de39bf5274 Ok, so this is how Matrix event rendering should work...
It does need a cleanup though, and i really hate how
loop initialization code is duplicated 💀
2023-01-14 18:33:06 +00:00
gnuxie da94b8d4bc Ahhhh you're doing it all wrong!!!
yeah
2023-01-14 18:33:06 +00:00
gnuxie d3e54440b2 Need PagedOutputStream instead of TransactionalOutputStream 2023-01-14 18:33:06 +00:00
gnuxie 3b49f18de2 Incremental Message rendering with JSX templates.
targetting both markdown and html.
2023-01-14 18:33:06 +00:00
gnuxie dede585d64 Pandoc AST please.
I've just realised my node model is wrong while halfway through
writing an incremental FringeWalker to help with renderering
events.
2023-01-14 18:33:06 +00:00
gnuxie eb710edc95 Remove unused, obsolete MatrixInterfaceCommand.
I'm not sure how it survived? probably f'd something up in
a rebase.
2023-01-14 18:33:06 +00:00
gnuxie de9a0a078b Two appservice bot commands to test with.
One lists unstarted mjolnirs, and one allows you to try restart them.
2023-01-14 18:33:06 +00:00
gnuxie 203f42dc0e Better argument validation error rendering. 2023-01-14 18:33:06 +00:00
gnuxie b9767532a8 help for commands.
This commit is NOT contributed under the Apache-2.0 License.
Copyright (C) 2022 Gnuxie <Gnuxie@protonmail.com>
All rights reserved.
2023-01-14 18:33:06 +00:00
gnuxie 76c48cccfc The error codes in CommandError are not going to work.
They're required which is bs because people are just going to make
up bullshit to satisfy the requirement. And it's rare
that they need to be intercepted.

What's rarer is intercepting them and not being able to change
the implementation.

So what am i going to do instead?

just not have it and you can subtype CommandError.
until i can think of something else.

This commit is NOT contributed under the Apache-2.0 License.
Copyright (C) 2022 Gnuxie <Gnuxie@protonmail.com>
All rights reserved.
2023-01-14 18:33:06 +00:00
gnuxie e6d0aaf9ea Richer paramater parsing.
This commit is NOT contributed under the Apache-2.0 License.
Copyright (C) 2022 Gnuxie <Gnuxie@protonmail.com>
All rights reserved.
2023-01-14 18:33:06 +00:00
gnuxie 66907a571e lint
This commit is NOT contributed under the Apache-2.0 License.
Copyright (C) 2022 Gnuxie <Gnuxie@protonmail.com>
All rights reserved.
2023-01-14 18:33:06 +00:00
gnuxie beb9152b10 New command system working in appservice
This commit is NOT contributed under the Apache-2.0 License.
Copyright (C) 2022 Gnuxie <Gnuxie@protonmail.com>
All rights reserved.
2023-01-14 18:33:06 +00:00
gnuxie dd21b48714 ValidationResult -> CommandResult
we need it for more than validation
probably considering getting rid of the error code thing
or making it optional idk.

This commit is NOT contributed under the Apache-2.0 License.
Copyright (C) 2022 Gnuxie <Gnuxie@protonmail.com>
All rights reserved.
2023-01-14 18:33:06 +00:00
gnuxie 6e6a3fdada MatrixInterfaceAdaptor
This commit is NOT contributed under the Apache-2.0 License.
Copyright (C) 2022 Gnuxie <Gnuxie@protonmail.com>
All rights reserved.
2023-01-14 18:33:06 +00:00
gnuxie b36376753d introduce InterfaceCommand.
We've basically made an embedded mini language for commands.

The idea is that there are a sequence of strings at the start
of a command that are pattern matched against a table.
Then eventually we will also pattern match against the presentation
types that they each accept.

This commit is NOT contributed under the Apache-2.0 License.
Copyright (C) 2022 Gnuxie <Gnuxie@protonmail.com>
All rights reserved.
2023-01-14 18:33:06 +00:00
gnuxie d7adaef0bf It's time for mjolnir-shell, a presentation style interface.
While this isn't a true presentation style interface,
the idea is that there is an argument stream to commands
that we pattern match commands against, and there are
different mediums that the commands can be invoked from.

There are translators between presentation types
and also between commands and mediums to do things like
render the result of the command for Matrix etc.

This is all inspired by the Common Lisp Interface Manager (CLIM).
But there are significant differences since, hello, this is
essentially being made for Matrix bots and appservices.

This commit is NOT contributed under the Apache-2.0 License.
Copyright (C) 2022 Gnuxie <Gnuxie@protonmail.com>
All rights reserved.
2023-01-14 18:33:06 +00:00
gnuxie 4b254e59f8 Move the MatrixInterfaceCommand into the interface-manager. 2023-01-14 18:26:12 +00:00
gnuxie 30fd1555b9 MatrixInterfaceCommand more abstract. 2023-01-14 18:26:12 +00:00
gnuxie 9e1cf659d2 Introduce the interface manager as a sub library.
This will want splitting out for other matrix bots to use eventually.
MatrixInterfaceCommand needs decoupling from Mjolnir and then it will
be added too.
2023-01-14 18:26:12 +00:00
gnuxie 722a36a358 Revert all previous changes to UnbanBanCommand.
I'm deciding that we can now go ahead and use the new parts in
the appservice bot.
The reason being that the syntax of old commands
has optional arguments bang in the middle of
the argument list.
Which makes validating and parsing the argument list (not just from
a string, but also from the result of the CommandReader) really hard
and special cased.
When this command does get refactored, the syntax will change.
2023-01-14 18:26:12 +00:00
gnuxie 98ea5a9586 Create a reader to assist parsing commands.
The idea is that the reader allows us to parse commands into
concrete types that will help us destructure/pattern match
against them later on.

This commit is NOT contributed under the Apache-2.0 License.
Copyright (C) 2022 Gnuxie <Gnuxie@protonmail.com>
All rights reserved.
2023-01-14 18:26:12 +00:00
gnuxie f571975602 MatrixRoomReference
This commit is NOT contributed under the Apache-2.0 License.
Copyright (C) 2022 Gnuxie <Gnuxie@protonmail.com>
All rights reserved.
2023-01-14 18:26:12 +00:00
gnuxie b54ed1fc24 Convenient ValidationError constructor to ValidationError.Result.
This commit is NOT contributed under the Apache-2.0 License.
Copyright (C) 2022 Gnuxie <Gnuxie@protonmail.com>
All rights reserved.
2023-01-14 18:26:12 +00:00
gnuxie b3273c5103 Name, License and Notice we are forking tada. 2023-01-14 18:26:12 +00:00
gnuxie 9330e319ce Add new header to all files. 2023-01-02 16:54:50 +00:00
gnuxie 300a339331 Use Ban/Unban command as an example. 2022-12-09 20:08:36 +00:00
gnuxie 428cbfb4d0 ValidationInterface 2022-12-09 20:08:36 +00:00
gnuxie 63e0a24e6e First stage of commands refactor. 2022-12-09 20:08:34 +00:00
dependabot[bot] dafbd20393 Bump express from 4.17.1 to 4.17.3 (#455)
Bumps [express](https://github.com/expressjs/express) from 4.17.1 to 4.17.3.
- [Release notes](https://github.com/expressjs/express/releases)
- [Changelog](https://github.com/expressjs/express/blob/master/History.md)
- [Commits](https://github.com/expressjs/express/compare/4.17.1...4.17.3)

---
updated-dependencies:
- dependency-name: express
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-12-08 16:19:00 +00:00
Gnuxie 433ff7eadd A look at PolicyList.update (#454)
This started out as just a way to find out why mjolnir was syncing with lists several times for each update to a policy list.

The main changes are

- Verbosity was irrelevant to the sync command but for some reason was an option.
  Unfortunately all this did was suppress whether to tell you when it had finished, meaning it wouldn't
  when verbose logging was disabled. Historically this was probably a parameter that got passed through
  to applyServerAcl/applyUserBans, which can be horribly verbose, but they access the config directly.

- Stop emitting `'PolicyList.update'` when there are no changes.
- Include a revision ID for the `'PolicyList.update'`method and event.
- Use the revision ID in the `ProtectedRoomsSet` so that we don't unnecessarily resynchronize all rooms when the `'PolicyList.update'` event is received. Though not when the `sync` command is used. Since this is supposed to `sync` in the case when there is a state reset or otherwise or the user has changed some room settings.
- insert an await lock around the `PolicyList.update` method to avoid a race condition where a call can be started and finished within the extent of an existing call (via another task, this can happen if the server is slow with handling one request). `PolicyList.udpate` now has a helper that is synchronous to be called directly after requesting the room state. The reason for this is to enforce that no one `await`s while updating the policy list's cache of rules. Which is important because it is one of the biggest methods that I tolerate and visually checking for `await` is impossible.
- The revision ID uses a ULID, but this is unnecessary and could have just been a "dumb counter".

closes https://github.com/matrix-org/mjolnir/issues/447
2022-12-08 16:09:55 +00:00