mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-12-20 20:01:17 +00:00
Add randomString
template function
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
c0545d1d87
commit
07a83e2fdb
2 changed files with 22 additions and 0 deletions
|
@ -12,10 +12,19 @@ import (
|
|||
)
|
||||
|
||||
func Register(args plugins.RegistrationArguments) error {
|
||||
args.RegisterTemplateFunction("randomString", plugins.GenericTemplateFunctionGetter(randomString))
|
||||
args.RegisterTemplateFunction("seededRandom", plugins.GenericTemplateFunctionGetter(stableRandomFromSeed))
|
||||
return nil
|
||||
}
|
||||
|
||||
func randomString(lst ...string) (string, error) {
|
||||
if len(lst) == 0 {
|
||||
return "", errors.New("empty list given")
|
||||
}
|
||||
|
||||
return lst[rand.Intn(len(lst))], nil
|
||||
}
|
||||
|
||||
func stableRandomFromSeed(seed string) (float64, error) {
|
||||
seedValue, err := stringToSeed(seed)
|
||||
if err != nil {
|
||||
|
|
|
@ -251,6 +251,19 @@ Example:
|
|||
< 10000
|
||||
```
|
||||
|
||||
#### `randomString`
|
||||
|
||||
Randomly picks a string from a list of strings
|
||||
|
||||
Syntax: `randomString "a" [...]`
|
||||
|
||||
Example:
|
||||
|
||||
```
|
||||
# {{ randomString "a" "b" "c" "d" }}
|
||||
< a
|
||||
```
|
||||
|
||||
#### `recentGame`
|
||||
|
||||
Returns the last played game name of the specified user (see shoutout example) or the `fallback` if the game could not be fetched. If no fallback was supplied the message will fail and not be sent.
|
||||
|
|
Loading…
Reference in a new issue