Commit Graph

40 Commits

Author SHA1 Message Date
projectmoon 3d2eb14cd3 Change room in context to origin_room, add active_room.
The context now knows about origin room (the room where the command
was executed), and the "active room," which is the room that the user
wants the command to apply to. If no active room is defined, then the
origin room acts as the active room. In a public room with the bot,
the active room is also the same as the origin room.
2021-05-30 14:18:56 +00:00
projectmoon 495df13fe6 Do not automatically create accounts; use enum to show this instead.
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is passing Details
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 5d002e5063 Add ability to store user active room, with skeleton accounts.
continuous-integration/drone/pr Build is passing Details
continuous-integration/drone/push Build is passing Details
- 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 34ee2c6e5d Consider command execution secure when proper conditions are met.
continuous-integration/drone/push Build is failing Details
- 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 5643677627 Consolidate dice and variable parsers under parser module.
continuous-integration/drone/push Build is passing Details
2021-05-21 14:44:03 +00:00
projectmoon 3d5cda39c8 Consolidate dice module into logic module. 2021-05-21 14:26:58 +00:00
projectmoon 4de273db4a Remove sled code; promote sql to top level 2021-05-21 14:05:25 +00:00
projectmoon e539dcac1f Move migrations to sqlite directory. Remove in-memory temp db until refinery supports sqlx.
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is passing Details
2021-05-18 14:50:49 +00:00
projectmoon cf9ce63892 Replace application-level database connectivity.
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is passing Details
- 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 8939d6debd Update dependencies.
continuous-integration/drone/push Build is passing Details
2021-05-13 19:48:29 +00:00
projectmoon 9ab65b8943 Update env_logger, rand, phf, itertools to newer semvers.
continuous-integration/drone/push Build is passing Details
2021-02-09 21:56:13 +00:00
projectmoon 042ecc40e0 Properly format dice plurality in CofD dice pools.
continuous-integration/drone/push Build is passing Details
Fixes #30.
2021-01-31 14:57:18 +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 297a8454f6 Avoid cloning when counting successes.
continuous-integration/drone/push Build is passing Details
2020-12-18 14:16:22 +00:00
projectmoon c9c80b974c Tests for dice pool formatting. 2020-12-17 21:14:43 +00:00
projectmoon eb42704380 Switch to into_iter instead of a non-consuming iterator.
continuous-integration/drone/push Build is passing Details
2020-12-17 21:06:43 +00:00
projectmoon f355fad06b Rename some variables for consistency.
continuous-integration/drone/push Build is passing Details
Fixes #50.
2020-12-17 20:59:29 +00:00
projectmoon 23cf9e6ba4 Show all rolls if we are below the max amount shown (15 dice).
continuous-integration/drone/push Build is passing Details
2020-12-17 20:54:01 +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 f46b914239 Add matrix client to context. 2020-11-22 20:52:44 +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 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 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 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 ebfd230f31 Use variables namespace for user variables. 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 97d91704a1 Make context owned, in hopes of async 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 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 92e4a7c29b Rote die roll now respects dice pool success_on property.
Fixes #5.
2020-09-26 14:04:12 +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 f0a1fe53fc Move CofD dice rolling into dice.rs file under cofd/ 2020-08-27 23:56:19 +00:00