Commit Graph

16 Commits

Author SHA1 Message Date
projectmoon 0c394d0f79 Get all variables command. 2020-10-22 20:29:37 +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 06ff6562c1 Add more tests for handling weird input. 2020-09-01 08:17:59 +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 da0819745a Switch to non-macro nom parser with better text handling.
By using the alpha1 function in complete mode, we are able to handle
arbitrary single-word commands (e.g. "!help") and proprly map the
remaining input to an empty string.
2020-08-31 00:07:56 +00:00
projectmoon 531844fbb7 Implement basic, not-well-formatted help. 2020-08-30 21:54:01 +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 4e72498181 format 2020-04-21 00:15:18 -06:00
Taylor C. Richberger 1a34a390d4 cargo fix again 2020-04-21 00:11:52 -06:00
Taylor C. Richberger 319e016bc3 remove unneeded 2020-04-21 00:11:25 -06:00
Taylor C. Richberger e7458c12ad cargo fix and fmt 2020-04-21 00:09:43 -06:00
Taylor C. Richberger 198f0bd43f remove unnecessary annotation 2020-04-21 00:08:29 -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