Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dice extensions - many #91

Merged
merged 50 commits into from
Jan 4, 2022
Merged
Show file tree
Hide file tree
Changes from 46 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
5d1c41f
playing around with parsers
L0neGamer Dec 7, 2021
1171c0b
added text as an option to rolling dice
L0neGamer Dec 8, 2021
3743b19
Merge branch 'command-alias' of https://github.com/the-Bruce/tablebot…
L0neGamer Dec 8, 2021
95f8a21
merged with anna's branch and some tidying
L0neGamer Dec 8, 2021
c98877f
added inline rolling syntax
L0neGamer Dec 8, 2021
f5ed78c
fixed issue with parsing text beyond the end of a command
L0neGamer Dec 8, 2021
b990286
cleaned up a bit
L0neGamer Dec 8, 2021
43e3649
Merge branch 'inline-command-help' of github.com:L0neGamer/tablebot i…
L0neGamer Dec 8, 2021
6a4c333
used utility function
L0neGamer Dec 8, 2021
2c85a6a
halfway through new function storage
L0neGamer Dec 8, 2021
696b071
Merge branch 'inline-command-help' of github.com:L0neGamer/tablebot i…
L0neGamer Dec 8, 2021
26d81c1
merged changes
L0neGamer Dec 8, 2021
f09fa64
moved commit
L0neGamer Dec 8, 2021
f39f071
starting on expanding functions
L0neGamer Dec 8, 2021
dd59bb2
started the function revamp
L0neGamer Dec 9, 2021
2e5a0cc
Merge branch 'inline-command-help' of github.com:L0neGamer/tablebot i…
L0neGamer Dec 12, 2021
b15ec7e
transferring from laptop to desktop
L0neGamer Dec 13, 2021
2c5305b
finishing up the initial lists and integers stuff - needs more testing!
L0neGamer Dec 13, 2021
322b042
more parsing shenanigans
L0neGamer Dec 13, 2021
33aa9b1
reformatting
L0neGamer Dec 13, 2021
b3e0dcb
split out source files
L0neGamer Dec 13, 2021
0cadbe7
removed eq from data types, added method to easily promote items, cha…
L0neGamer Dec 13, 2021
6affe8e
added genchar command
L0neGamer Dec 13, 2021
3765c3d
satisfying ormolu
L0neGamer Dec 13, 2021
7c26718
some tweaks and comments
L0neGamer Dec 14, 2021
248ebd0
started creating functions that create lists
L0neGamer Dec 14, 2021
1556936
started barking up the wrong tree wrt IOEval
L0neGamer Dec 14, 2021
0bbf4d0
added functions that return lists, as well as played around with a wh…
L0neGamer Dec 14, 2021
2b9f484
fixed qualified text imports
L0neGamer Dec 14, 2021
4f96295
merged paths
L0neGamer Dec 25, 2021
9379d6d
a little tidy
L0neGamer Dec 25, 2021
f36e12e
satisfying ormolu
L0neGamer Dec 25, 2021
cb64bbf
fixing some headers
L0neGamer Dec 25, 2021
278550c
cleaning up a bit
L0neGamer Dec 25, 2021
db21473
minor comment
L0neGamer Dec 25, 2021
077c265
commenting and then fixing inline commands so they, you know, work.
L0neGamer Dec 27, 2021
04745d2
removed old comments
L0neGamer Dec 27, 2021
342ec37
updated listvalues so it can no longer be a single value.
L0neGamer Dec 28, 2021
0ebfa36
created new listvaluesbase, and now custom dice can use any list to s…
L0neGamer Dec 28, 2021
dc622fb
did some documentation
L0neGamer Dec 28, 2021
5f646fb
added length and index as functions
L0neGamer Dec 28, 2021
dd480de
let there be spaces in function calling
L0neGamer Dec 28, 2021
bfc7a5b
update parse description
L0neGamer Dec 28, 2021
7cf1bc0
added a way to communicate that an inline query is incorrect
L0neGamer Dec 29, 2021
4218eb5
run all inline commands, catching any errors
L0neGamer Dec 30, 2021
9904931
simplified catching all errors
L0neGamer Dec 30, 2021
1767e0e
removed some formatting from outputs
L0neGamer Jan 3, 2022
e8852d8
added some comments and modified how IOEvalList works
L0neGamer Jan 4, 2022
6ebcc4e
I hate it when qualified is in a postpositive position
L0neGamer Jan 4, 2022
07ac648
explained some of the internal files
L0neGamer Jan 4, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions docs/Roll.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

The roll command has a staggering amount of flexibility, as well as additional features.

Below are listed the current full capabilities of the bot for rolling dice and evaluation expressions. All operations (currently) result in integers.
Below are listed the current full capabilities of the bot for rolling dice and evaluation expressions. All operations (currently) result in integers or a list. A list of functions is available in the [functions section](#Functions).

## Basic Operators

- Addition
- Subtraction
- Multiplication
- Division
- Single input function application (currently for `id`,`abs`, `neg`, and `fact` (factorial) up to some number determined by the bot owner, 50 by default)
- Negation using `-`
- Exponentiation
- Parentheses
Expand Down Expand Up @@ -56,3 +55,31 @@ There is additional notation for evaluating dice in different ways, detailed bel
- `10d{1d4,1d4+5}!rr<(2d4)` - when evaluation begins, the values for the custom die are calculated. Every time a die value is potentially rerolled, the value that it is being checked against is evaluated.

With the introduction of this notation, it is worth noting that the normal (without exclamation mark) operation of dice means that the values are evaluated once, at the beginning, and then those values are used for the rest of the operation of the program. Additionally, lazily evaluating will often lead to excessive amounts of RNG calls, which can easily exceed the maximum.

## Lists

As well as simple expressions, basic list expressions can be formed. You can form a basic list using `{e,f,g}`, where `e`, `f`, and `g` are expressions as seen before. Additionally, by using `N#YdX` syntax, you can roll `N` amount of dice following `YdX`.

As an addendum to custom dice, if a list value is bracketed then it can be used in custom dice. For example, `5d(4#4d6)` rolls five dice, whose sides are determined by rolling 4d6 4 times. Do note that laziness still applies here, meaning that the RNG cap can be very quickly reached.

## Functions

Here are all the functions, what they take, and what they return.

### Returns an Integer
- abs (integer) - the absolute value of an integer
- fact (integer < 50) - the factorial of an integer
- id (integer) - the integer
- maximum (list) - get the maximum item in a list
- minimum (list) - get the minimum item in a list
- mod (two integers, second /= 0) - get the modulo of two integers
- neg (integer) - the negation of an integer
- sum (list) - the summation of all values in a list
- length (list) - the length of the list
- index (integer (within list bounds), list) - get the item at a given index in the list, 0 indexed

### Returns a List
- drop (integer, list) - drop the first `n` values from a list, where `n` is the integer given
- reverse (list) - reverse the list
- sort (list) - sort the list in ascending order
- take (integer, list) - take the first `n` values from a list, where `n` is the integer given
2 changes: 2 additions & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ library:
- ConstraintKinds
- ImportQualifiedPost
- RecordWildCards
- TypeOperators
- RankNTypes
ghc-options:
- -Wall

Expand Down
13 changes: 6 additions & 7 deletions src/Tablebot/Internal/Handler/Command.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import Tablebot.Utility.Exception (BotException (ParserException), embedError)
import Tablebot.Utility.Parser (skipSpace1, space, word)
import Tablebot.Utility.Types (Parser)
import Text.Megaparsec
import qualified UnliftIO.Exception as UIOE (tryAny)

-- | @parseNewMessage@ parses a new message, first by attempting to match the
-- bot's prefix to the start of the message, then (if that fails) by attempting
Expand Down Expand Up @@ -119,12 +120,10 @@ makeReadable (TrivialError i _ good) =
makeReadable e = (mapParseError (const UnknownError) e, Nothing)

-- | Given a list of 'InlineCommand' @cs@ and a message @m@, run each inline
-- command's parser on the message text until one succeeds. Errors are not sent
-- to the user, and do not halt command attempts (achieved using 'try').
-- command's parser on the message text. Errors are not sent to the user, and do
-- not halt command attempts (achieved using 'tryAny').
parseInlineCommands :: [CompiledInlineCommand] -> Message -> CompiledDatabaseDiscord ()
parseInlineCommands cs m = case parse (parser cs) "" (messageText m) of
Right p -> p m
Left _ -> pure ()
parseInlineCommands cs m = mapM_ (fromResult . (\cic -> parse (inlineCommandParser cic) "" (messageText m))) cs
where
parser :: [CompiledInlineCommand] -> Parser (Message -> CompiledDatabaseDiscord ())
parser cs' = choice $ map (try . inlineCommandParser) cs'
fromResult (Right p) = UIOE.tryAny (p m)
fromResult _ = return $ return ()
5 changes: 2 additions & 3 deletions src/Tablebot/Plugins/Netrunner/Plugin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ nrFindInline = InlineCommand nrInlineComm
nrInlineComm :: Parser (Message -> EnvDatabaseDiscord NrApi ())
nrInlineComm = do
queries <- netrunnerQuery
let limitedQs = if length queries > 5 then take 5 queries else queries
return $ \m -> mapM_ (\q -> sendEmbed q m) limitedQs
return $ \m -> mapM_ (`sendEmbed` m) (take 5 queries)
sendEmbed :: NrQuery -> Message -> EnvDatabaseDiscord NrApi ()
sendEmbed query m = do
api <- ask
Expand All @@ -123,7 +122,7 @@ nrSearch = Command "search" searchPars []
embedCards
("Query: `" <> pairsToNrdb pairs <> "`\n")
res
("_[..." <> (pack $ show $ length res - 10) <> " more](" <> pairsToQuery pairs <> ")_")
("_[..." <> pack (show $ length res - 10) <> " more](" <> pairsToQuery pairs <> ")_")
m

-- | @nrCustom@ is a command that lets users generate a card embed out of custom
Expand Down
Loading