Commit Graph

37 Commits

Author SHA1 Message Date
projectmoon b3c4d8a38c Centralize plain text formatting at point of message sending.
continuous-integration/drone/pr Build is passing Details
continuous-integration/drone/push Build is passing Details
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 a4e66a0ca6 Basic output for multiple command failures.
continuous-integration/drone/pr Build is failing Details
continuous-integration/drone/push Build is passing Details
Also replace newlines with <br/>s in HTML output.
2021-01-31 08:15:22 +00:00
projectmoon 16eb87e50f Convert command execution to use results.
continuous-integration/drone/pr Build is passing Details
continuous-integration/drone/push Build is passing Details
2021-01-30 14:28:14 +00:00
projectmoon 1b0003ff1b Upgrade to Matrix SDK latest (Store Rewrite) and Tokio 1.0
continuous-integration/drone/push Build is passing Details
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 569ba4f2e0 Carry full room instance in context instead of just room id.
continuous-integration/drone/push Build is passing Details
2020-11-29 21:03:45 +00:00
projectmoon dda0d74f45 Implement resync command without filtering ourselves out.
continuous-integration/drone/push Build was killed Details
2020-11-22 21:30:24 +00:00
projectmoon f46b914239 Add matrix client to context. 2020-11-22 20:52:44 +00:00
projectmoon f352c90b6b Return error on unrecognized commands.
continuous-integration/drone/push Build is passing Details
2020-11-12 21:05:14 +00:00
projectmoon 472f02d153 Execute commands even when surrounded by weird whitespace.
continuous-integration/drone/push Build is passing Details
2020-11-05 23:03:22 +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 3ccd60c173 Do not respond to or log ignored commands. 2020-11-01 12:20:45 +00:00
projectmoon f4417d4c1a Remove unnecessary Option from parse_command return type. 2020-10-31 21:03:17 +00:00
projectmoon e3b819ecb0 Wire up regular cthulhu roll commmand (not yet parsed). 2020-10-31 20:51:17 +00:00
projectmoon 88db00cc3d Move commands into separate submodules 2020-10-31 20:51:17 +00:00
projectmoon 4d9ad42bdd De-asyncify database methods 2020-10-30 21:53:22 +00:00
projectmoon 5410c53513 Split database code into separate modules. 2020-10-30 21:53:22 +00:00
projectmoon 7f971703e2 Sort variable list when showing all variables.
Fixes #28
2020-10-22 21:24:24 +00:00
projectmoon 0c394d0f79 Get all variables command. 2020-10-22 20:29:37 +00:00
projectmoon d5aae3ebb1 Fully async dice rolling. Also remove more unnecessary stuff. 2020-10-18 20:37:02 +00:00
projectmoon 3c2a37c0f7 Make command execution async. 2020-10-18 20:37:02 +00:00
projectmoon 97d91704a1 Make context owned, in hopes of async 2020-10-18 20:37:02 +00:00
projectmoon af2e58351f Resolve variables in dice pools. 2020-10-16 22:20:46 +00:00
projectmoon 4234263ee4 Localize error enums to modules, better DB error reportng. 2020-10-16 13:18:27 +00:00
projectmoon 6cdc465a2e Add database and storage of user variables.
This commit introduces the Sled embedded key-value store for keeping
track of user variables on a per-room basis. Extensive changes were
made to the command module to separate concerns and also pass the
database "connection" down the line.

 - A new "Context" object was created to hold information and state
   needed for command execution (namely the database).
 - Database is very simple for now, storing only user variables.
   Refactoring later for storing more complicated types.
 - State actor moved into Actors struct, in preparation for either
   more actors, or ripping the whole thing out entirely.
 - Other modules are also more properly separated, notably
   the config module is entirely self-contained.
2020-10-16 13:18:27 +00:00
projectmoon 7e44faf693 Dice pool and command parser rewrite to prepare for user variables.
This commit refactors the parsing and rolling for the dice pool system
to prepare for support of user variables. The nom parser was dropped
in favor of the easier-to-understand combine parser in most parts of
the code.

A breaking change was introduced into the dice pool syntax to allow
for proper expressions and variables. The syntax is now
"modifiers:pool-amount", e.g. "n:gnosis+8". The simple single-number
syntax with no modifiers is also still understood.

Dice pool expressions are translated into a Vec of "Amount" objects,
stored by the DicePool struct. They have an operator (+ or -) and
either a number or variable name. When the dice pool is rolled, this
list of Amonuts are is collapsed into a single number that is rolled,
as it was before the refactor.

The following changes were made to the dice rolling code:
 - Store Vec<Amount> on DicePool instead of single number to roll.
 - New struct RolledDicePool to store result of a dice pool roll.
 - Remove Display trait from DicePool, move it over to RolledDicePool.
 - Separate extra dice pool info into DicePoolModifiers.
 - DicePoolModifiers is shared between DicePool and RolledDicePool.
 - Dice parsing and rolling now return standard Result objects.

This commit does NOT enable support of actually using variables. Any
dice pool roll containing a variable will result in an eror.

The command parser was also rewritten to use combine and rely on the
standard Result pattern.
2020-10-11 21:22:12 +00:00
projectmoon f3f5846826 Fix command parser returning non-commands/empty messages as errors.
This behavior became broken again after switching away from the
macro-based command parsing. The bot would return any non !command
message as an error, which would cause it to read more messages, and
return those as errors, until finally the matrix SDK would throw up.

Command parser now more properly handles empty messages and
non-commands, but we also simply abort processing if the incoming
message doesn't start with an exclamation point.
2020-08-31 23:33:46 +00:00
projectmoon 8803b83ddb Remove useless trim function and unnecessary uses of eat_whitespace. 2020-08-31 20:16:43 +00:00
projectmoon 531844fbb7 Implement basic, not-well-formatted help. 2020-08-30 21:54:01 +00:00
projectmoon 8484e9ffde Allow extraneous whitespace at the end of command input. 2020-08-30 21:45:42 +00:00
projectmoon 54a3cc0880 Add basic logging to the dice bot. 2020-08-28 00:13:04 +00:00
projectmoon f0a1fe53fc Move CofD dice rolling into dice.rs file under cofd/ 2020-08-27 23:56:19 +00:00
projectmoon 2c08eb41ad Implement Chronicles of Darkness dice system, improve error handling.
Adds the Chronicles of Darkness 2E dice system to the bot, and also
somewhat improves the error handling when weird commands are received.
2020-08-23 21:24:04 +00:00
Taylor C. Richberger 6d180734d5 make actually work with messages 2020-04-21 22:19:15 -06:00
Taylor C. Richberger 81b8b2c0cc simplify the code, and invert Result and Option 2020-04-21 00:22:31 -06:00
Taylor C. Richberger e7458c12ad cargo fix and fmt 2020-04-21 00:09:43 -06:00
Taylor C. Richberger 649aec531e implement command parser fully 2020-04-21 00:07:03 -06:00
Taylor C. Richberger 90ae9c142c lay command groundwork. Maybe need to make parsing more ergonomic. 2020-04-20 21:15:13 -06:00