Commit Graph

189 Commits

Author SHA1 Message Date
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
projectmoon 7a302c4489 Extract Ruma error messages from matrix SDK errors. 2020-10-31 20:51:17 +00:00
projectmoon 88db00cc3d Move commands into separate submodules 2020-10-31 20:51:17 +00:00
projectmoon d5034c11dc Basic implementation of CoC dice rolling.
Not hooked up to parser or commands yet.
2020-10-31 20:51:17 +00:00
projectmoon 9f598541fb Remove variable_count keys missed in manual data migration. 2020-10-30 22:44:19 +00:00
projectmoon 5224357f8b Add migration 2: remove old data. 2020-10-30 21:53:22 +00:00
projectmoon 6b21b0aff8 Add string name to migrations 2020-10-30 21:53:22 +00:00
projectmoon 3cec676b2f Clean up migration to make it more readable 2020-10-30 21:53:22 +00:00
projectmoon a53ce85f38 Add db migration support, change variables schema.
This is a bit of a large commit that adds basic database migration
support. It also alters the way user variables are stored in a way
requiring manual migration of existing data. The first automated
migration adds variable count in a new place.
2020-10-30 21:53:22 +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 9176e858d5 A bit of database code cleanup. 2020-10-23 20:30:03 +00:00
projectmoon 9f8ef281de Store room user variable count under a room metadata space 2020-10-23 20:30:03 +00:00
projectmoon d482046b9b Actually roll a die when converting to chance die pool. 2020-10-22 23:36:50 +00:00
projectmoon 1a980aa608 Auto-convert dice pools to chance die if below 0. 2020-10-22 23:24:24 +00:00
projectmoon 7f971703e2 Sort variable list when showing all variables.
Fixes #28
2020-10-22 21:24:24 +00:00
projectmoon c10ee5c0f3 Allow negative variables. 2020-10-22 20:47:20 +00:00
projectmoon 0c394d0f79 Get all variables command. 2020-10-22 20:29:37 +00:00
projectmoon 314b0520d9 Support multiple command execution. 2020-10-22 19:54:48 +00:00
projectmoon 2ee8ae2e34 Document the From trait on the DataError type. 2020-10-20 21:10:54 +00:00
projectmoon 114c879c6f Count user variables on a per-room basis. 2020-10-20 21:10:54 +00:00
projectmoon ebfd230f31 Use variables namespace for user variables. 2020-10-18 21:01:52 +00:00
projectmoon 6b7acbe520 Open trees for rooms and variables, but not yet use them. 2020-10-18 21:01:52 +00:00
projectmoon ce82e6ddad Fetch all variables into a map before rolling dice.
Goes from about 30 seconds to do 1 million variable resolutions down
to 18 seconds.
2020-10-18 20:37:02 +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 9268314421 Remove actix, move state to RwLock. Update dependencies. 2020-10-18 20:37:02 +00:00
projectmoon 3b70891b0a Reject dice pool expressions over 100 elements. 2020-10-16 22:20:46 +00:00
projectmoon d0a1f59ec7 Better error message when dice pool variable not defined. 2020-10-16 22:20:46 +00:00
projectmoon af2e58351f Resolve variables in dice pools. 2020-10-16 22:20:46 +00:00
projectmoon dc8a74cc35 Update help for new dice pool syntax. 2020-10-16 22:20:46 +00:00
projectmoon 4856360c6a Custom schema violation error for DB value retrieval. 2020-10-16 13:18:27 +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 05ff6af8a1 Inline all config getters. 2020-10-03 20:59:04 +00:00
projectmoon 7880d950af Use unwrap_or instead of match to calculate oldest message age. 2020-10-03 20:56:00 +00:00
projectmoon 514ac84e73 Encapsulate config with Arc. Further bot code cleanup.
Only expose config settings via methods on the Config struct. This
allows default value handling to live entirely inside the config code,
solves various borrowing issues with the "create default bot config
value" solution, and allows us to avoid cloning the bot config values.
The downside is that the config must now be in an Arc since its
ownership is shared in multiple places and the matrix SDK requires
thread-safe types (perhaps in the future we re-compose traits and use
Rc for config instead).

This commit also further cleans up and splits up the bot code for the
matrix connection, notably making the main message event handler
smaller by splitting out the "should we process the message" checks
into a separate function.
2020-10-03 20:45:14 +00:00
projectmoon 938107feae Implement Actix for state, refactor bot code.
Instead of using an Arc Mutex for state management embedded directly
into the bot, utilize actor pattern, with the idea that this will be
much more useful than simply logging a message once in the future.

This also refactors the bot code so that instead of a single run_bot
function, the DiceBot struct now has a run() method attached to it.
This also necessitated changes and cleanup to the dicebot main, which
is for the better anyhow.

The error and config types are also now in their own files, and
implemented for more in-depth use cases.
2020-10-03 20:45:14 +00:00
projectmoon f844b09213 Recover from potentially but unlikely poisioned mutexes. 2020-09-27 09:44:59 +00:00
projectmoon 620bea0521 Only use one instance of state instead of cloning it everywhere. 2020-09-27 09:44:59 +00:00
projectmoon 624c748583 Add useful logging of skipping commands.
This commit lays the groundwork for a stateful dicebot, instead of one
that only responds to commands. It now maintains a simple state
machine, used to store the current state of the bot. Currently, it
only cares about whether or not the message about skipping old
messages was logged.
2020-09-27 09:44:59 +00:00
projectmoon 6d49c9e16c Fall back to 15 minutes if oldest message age not specified.
This makes the oldest message age setting optional, in additon to the
entire bot config (for now). If the oldest message age is not
specified (or if the entire bot config is missing), it will default to
15 minutes.
2020-09-27 09:44:59 +00:00
projectmoon fabda911fd Ignore messages that are too old. 2020-09-27 09:44:59 +00:00
projectmoon 92e4a7c29b Rote die roll now respects dice pool success_on property.
Fixes #5.
2020-09-26 14:04: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 1f5c6d7553 Actually only trim the start and end of the string.
Be careful what you find on Stack Overflow, kids.
2020-08-31 00:05:40 +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 16b5a3a51a Chance die should only succeed on 10. Added no-explode rolls. 2020-08-28 21:47:09 +00:00
projectmoon 5983592eb3 Limit large the display of large dice pools. 2020-08-28 00:30:28 +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 18a05ebd7c Add auto-join, adapted from matrix SDK examples. 2020-08-27 23:50:32 +00:00
projectmoon e8ce058e5d Properly format dramatic failures. 2020-08-27 19:49:21 +00:00
jeff 0eb181a7a9 Clean up dependencies and upgrade to 0.3.0 after matrix SDK port. 2020-08-27 00:05:19 +00:00
jeff 6572e1d04e Port dice bot to use matrix-rust-sdk.
This gives us many things for free, like automated state management,
no need to declare special API structs and use HTTP requests directly,
and most importantly: ENCRYPTION!
2020-08-26 23:53:30 +00:00
jeff a62727070a Update Cargo files for fork. 2020-08-23 21:24:04 +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 6cb88a566c get everything working and slightly documented 2020-04-21 22:30:00 -06:00
Taylor C. Richberger 8e50218c03 cargo fix 2020-04-21 22:20:05 -06: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 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
Taylor C. Richberger d0f3ec7ad2 handle matrix message handling 2020-04-20 15:09:38 -06:00
Taylor C. Richberger 087e20c261 get roller working correctly 2020-04-20 13:44:18 -06:00
Taylor C. Richberger a9e1ccbf2e restructure into dice module 2020-04-20 11:19:50 -06:00
Taylor C. Richberger 9121497d17 fmt 2020-04-20 10:02:26 -06:00
Taylor C. Richberger 1ce4b54417 Make sure all parsers are complete 2020-04-20 09:19:24 -06:00
Taylor C. Richberger 56de3d34f1 write out nom-based parser 2020-04-20 00:32:57 -06:00
Taylor C. Richberger 59cb407eae Add dicebot-roll dice expression parser 2020-04-19 16:07:33 -06:00
Taylor C. Richberger b4ccae581a improve documentation 2020-04-18 17:12:25 -06:00
Taylor C. Richberger 7cc29ddf8f get things cleaned up a little bit more 2020-04-18 17:09:55 -06:00
Taylor C. Richberger f129f45864 add TODO 2020-04-17 16:54:07 -06:00
Taylor C. Richberger b30eec72b3 modularize things 2020-04-17 16:53:27 -06:00
Taylor C. Richberger 61ec4e5fa7 cargo fmt 2020-04-16 23:25:13 -06:00
Taylor C. Richberger 1196bebb92 get initial stuff working 2020-04-16 23:20:54 -06:00