Commit Graph

67 Commits

Author SHA1 Message Date
projectmoon 896acee5ba Avoid cloned command input with From<String> instead of From<&str>. 2021-05-27 15:50:43 +00:00
projectmoon 49db0062a3 Various improvements to bot responses.
- Do not display username pill with quoted HTML replies.
 - Do not attempt to create matrix.to link in plain text replies.
 - Move plain text formatting responsibility outside of matrix
   send_message function.
2021-05-26 22:20:53 +00:00
projectmoon 4ae871224a Remove ExecutionError, as it is unnecessary. 2021-05-26 21:25:32 +00:00
projectmoon 1ebd13e912 Change execution_allowed to a match for shorter reading. 2021-05-26 21:12:21 +00:00
projectmoon 8f5b6f0636 Replace db query with simple in-memory check of if account already exists. 2021-05-26 21:04:53 +00:00
projectmoon 5b3d174edc Separate registering and linking accounts.
Can register an account with the bot to manage variables and stuff in
private room, and then separately "link" it with a password, which
makes it available to anything using the bot API (aka web app). Can
also unlink and unregister. Check command no longer validates
password. It just checks and reports your account status.
2021-05-26 15:28:59 +00:00
projectmoon 495df13fe6 Do not automatically create accounts; use enum to show this instead.
Instead of automatically creating a user account entry for any user
executing a command, we use an Account enum which covers both
registered and "transient" unregistered users. If a user registers,
the context has the actual user instance available, with state and
everything. If a user is unregistered, then the account is considered
transient for the request, with only the username available.
2021-05-26 14:20:18 +00:00
projectmoon de92fc8488 Remove nested <p> tags in error messages. 2021-05-26 07:06:00 +00:00
projectmoon b05129ad9f Localize all command parsing code into trait impls.
This cleans up the command parser a lot, as all of the one or two line
functions and associated imports have been removed. Unfortunately it
does make the command files larger, as two trait impls are required:
one for converting to Box<dyn Command>, and one for converting from
&str to the command type.

Fixes #66.
2021-05-25 23:55:50 +00:00
projectmoon 5d002e5063 Add ability to store user active room, with skeleton accounts.
- Adds a user_state table, currently only with active_room.
 - A user must have an account to take advantage of state.
 - Now, all users will get an 'account' even if they don't explicitly register.
 - Bonus: converts user queries to compile-time checked macros.

To support these automatically created "accounts," the accounts table
now also has an account_status column, indicating if the user is
registered or not (or pending activation--future use).

The User model has been updated with extra properties from the state,
and the user is now carrried in the Context during command execution.
A user is ensured to be created before executing the command.
2021-05-25 22:29:01 +00:00
projectmoon 395753e8a9 Remove room state mgmt; let matrix SDK do it on-demand instead.
Fixes #71.

Fixes #20.
2021-05-24 21:45:51 +00:00
projectmoon df0248d99a More useful account registration message. 2021-05-23 13:58:58 +00:00
projectmoon 76214bc790 Add an account deletion command. 2021-05-22 23:12:17 +00:00
projectmoon 8c2a90e86b Tests for secure commands and user DB API. 2021-05-22 22:48:47 +00:00
projectmoon 926dae57fb Add check password command. 2021-05-22 22:25:00 +00:00
projectmoon 4557498ac6 Improved command logging, sensitive to secure commands. 2021-05-22 22:17:33 +00:00
projectmoon ca34841d86 Functional user account registration. 2021-05-22 14:52:32 +00:00
projectmoon c1ec7366e4 Add user accounts, registration command, secure command valiation. 2021-05-22 14:01:16 +00:00
projectmoon a84d4fd869 Make command parsing case insensitive. 2021-05-21 22:40:03 +00:00
projectmoon 34ee2c6e5d Consider command execution secure when proper conditions are met.
- If the room is end-to-end encrypted.
 - If only the sending user and the bot are present in the room.

This lays groundwork for sensitive commands like registering a user
account with the bot.
2021-05-21 22:28:45 +00:00
projectmoon 9de74d05a9 Add an is_secure attribute for commands. 2021-05-21 15:32:08 +00:00
projectmoon 5643677627 Consolidate dice and variable parsers under parser module. 2021-05-21 14:44:03 +00:00
projectmoon de63fd914e Move commands.rs to commands/mod.rs; move migrate_cli.rs. 2021-05-21 14:35:56 +00:00
projectmoon 4de273db4a Remove sled code; promote sql to top level 2021-05-21 14:05:25 +00:00
projectmoon cf9ce63892 Replace application-level database connectivity.
- Some database methods not yet implemented.
 - Unit tests create temp files that are not cleaned up (but they should be).
2021-05-15 23:45:30 +00:00
projectmoon 30f800eb4a Relicense to AGPL, change project name. 2021-05-14 22:07:16 +00:00
projectmoon 490d17790a Add a few more aliases for cthulhu advancement rolls. 2021-05-13 22:12:47 +00:00
projectmoon 0396911c56 Remove extraneous <p> tags in dice roll outputs. 2021-05-13 21:29:44 +00:00
projectmoon e5431a587d Support complex expressions on CoC advancement rolls. (#55)
Also remove todo, update some CoC command descriptions.

Fixes #54.
Co-Authored-By: projectmoon <projectmoon@noreply.git.agnos.is>
Co-Committed-By: projectmoon <projectmoon@noreply.git.agnos.is>
2021-03-18 20:54:49 +00:00
projectmoon 8e4eb574d2 Update to latest matrix SDK and other dependencies. 2021-03-15 20:10:42 +00:00
projectmoon 304c91c69d Rename CommandResult to ExecutionResult 2021-02-07 21:39:21 +00:00
projectmoon b3c4d8a38c Centralize plain text formatting at point of message sending.
Instead of relying on all parts of the application to construct both
HTML and plain-text responses, we now construct only HTML responses,
and convert the HTML to plain text right before sending the message to
Matrix.

This is a first iteration, because the plain text has a few extra
newlines than it should, created by use of nested <p> tags.
2021-01-31 14:12:09 +00:00
projectmoon 055bad3a46 Move a type on collect() to variable assignment 2021-01-30 22:12:44 +00:00
projectmoon 16eb87e50f Convert command execution to use results. 2021-01-30 14:28:14 +00:00
projectmoon 1b0003ff1b Upgrade to Matrix SDK latest (Store Rewrite) and Tokio 1.0
This upgrade introduces a handful of breaking changes in the Rust
Matrix SDK.
 - Some types have disappeared and changed name.
 - Some functions are no longer async.
 - Room display name now has a Result type instead of just returning
   the value.
 - Client state store has breaking changes (not really a big deal).

This required introduction of a new type to store room information
that we are interested in on the context struct. This new RoomContext
is required mostly due to unit tests, because it is no longer possible
to instantiate the Room type in the Matrix SDK.
2021-01-30 12:54:47 +00:00
projectmoon e177da9c25 Centralize record_room_information function. 2020-11-30 19:53:26 +00:00
projectmoon 7e1abab66d Resync command now uses record_room_information. 2020-11-29 21:18:41 +00:00
projectmoon 569ba4f2e0 Carry full room instance in context instead of just room id. 2020-11-29 21:03:45 +00:00
projectmoon 68db038336 Properly avoid allocation for our_username in resync command. 2020-11-23 19:54:20 +00:00
projectmoon 18352c8c19 Filter out our username when resyncing (with an allocation). 2020-11-22 22:13:11 +00:00
projectmoon dda0d74f45 Implement resync command without filtering ourselves out. 2020-11-22 21:30:24 +00:00
projectmoon f352c90b6b Return error on unrecognized commands. 2020-11-12 21:05:14 +00:00
projectmoon 472f02d153 Execute commands even when surrounded by weird whitespace. 2020-11-05 23:03:22 +00:00
projectmoon 66f9bc6013 Move original dice rolling code into its own 'basic' module.
This gives it parity with the other systems: cofd and cthulhu. More
refactoring and a rewrite later as we trend towards more
system-specific implementations.
2020-11-04 20:46:25 +00:00
projectmoon 39e6eb9b46 Implement support for user variables in CoC dice rolling.
Also comes with reorganization of the dice rolling code to centralize
the variable -> dice amount logic, and changes the way the results of
those rolls are displayed.
2020-11-04 20:33:30 +00:00
projectmoon bf4ce24b79 Better public API for user variables, avoid allocations in Context.
The database API for user variables has changed somewhat again, this
time closer to the proper vision. There are now two separate sled
Trees in the Variables struct, one for user-defined variables, and one
for counts. Keys have been changed to be username-first, then room ID.
The signatures of the functions now also use a strongly-typed struct,
UserAndRoom.

As part of this, the Context object now once again avoids allocating
new strings.

Other random changes included here:
 - Remove tempfile crate in favor of sled temporary db config.
 - Add bincode crate in anticipation of future (de)serializing.
2020-11-03 20:31:29 +00:00
projectmoon f4417d4c1a Remove unnecessary Option from parse_command return type. 2020-10-31 21:03:17 +00:00
projectmoon 08b0e58193 Implement parsing of Cthulhu dice, only basic for now.
Does not understand anything besides single numbers at the moment.
2020-10-31 20:51:17 +00:00
projectmoon c290393ddf Centralize common parsing code.
Needed for further development of different systems that rely on these
kind of expressions, and lays groundwork for future changes.
2020-10-31 20:51:17 +00:00
projectmoon e3b819ecb0 Wire up regular cthulhu roll commmand (not yet parsed). 2020-10-31 20:51:17 +00:00