mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-12-20 20:01:17 +00:00
[templating] Add userExists
function
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
f56a7a3266
commit
ebf734be40
3 changed files with 35 additions and 2 deletions
|
@ -523,7 +523,7 @@ Send raw IRC message
|
||||||
|
|
||||||
## Send Whisper
|
## Send Whisper
|
||||||
|
|
||||||
Send a whisper (requires a verified bot!)
|
Send a whisper
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- type: whisper
|
- type: whisper
|
||||||
|
|
|
@ -467,7 +467,7 @@ Example:
|
||||||
|
|
||||||
```
|
```
|
||||||
# Your int this hour: {{ printf "%.0f" (mulf (seededRandom (list "int" .username (now | date "2006-01-02 15") | join ":")) 100) }}%
|
# Your int this hour: {{ printf "%.0f" (mulf (seededRandom (list "int" .username (now | date "2006-01-02 15") | join ":")) 100) }}%
|
||||||
< Your int this hour: 88%
|
< Your int this hour: 72%
|
||||||
```
|
```
|
||||||
|
|
||||||
### `spotifyCurrentPlaying`
|
### `spotifyCurrentPlaying`
|
||||||
|
@ -567,6 +567,19 @@ Example:
|
||||||
* Weather for Hamburg, DE: Few clouds with a temperature of 22 C (71.6 F). [...]
|
* Weather for Hamburg, DE: Few clouds with a temperature of 22 C (71.6 F). [...]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### `userExists`
|
||||||
|
|
||||||
|
Checks whether the given user exists
|
||||||
|
|
||||||
|
Syntax: `userExists <username>`
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```
|
||||||
|
# {{ userExists "luziferus" }}
|
||||||
|
* true
|
||||||
|
```
|
||||||
|
|
||||||
### `usernameForID`
|
### `usernameForID`
|
||||||
|
|
||||||
Returns the current login name of an user-id
|
Returns the current login name of an user-id
|
||||||
|
|
|
@ -14,6 +14,7 @@ func init() {
|
||||||
tplTwitchDisplayName,
|
tplTwitchDisplayName,
|
||||||
tplTwitchIDForUsername,
|
tplTwitchIDForUsername,
|
||||||
tplTwitchProfileImage,
|
tplTwitchProfileImage,
|
||||||
|
tplTwitchUserExists,
|
||||||
tplTwitchUsernameForID,
|
tplTwitchUsernameForID,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -68,6 +69,25 @@ func tplTwitchProfileImage(args plugins.RegistrationArguments) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func tplTwitchUserExists(args plugins.RegistrationArguments) {
|
||||||
|
args.RegisterTemplateFunction("userExists", plugins.GenericTemplateFunctionGetter(func(username string) bool {
|
||||||
|
user, err := args.GetTwitchClient().GetUserInformation(context.Background(), strings.TrimLeft(username, "#@"))
|
||||||
|
if err != nil {
|
||||||
|
// Well, they probably don't exist
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return strings.EqualFold(username, user.Login)
|
||||||
|
}), plugins.TemplateFuncDocumentation{
|
||||||
|
Description: "Checks whether the given user exists",
|
||||||
|
Syntax: "userExists <username>",
|
||||||
|
Example: &plugins.TemplateFuncDocumentationExample{
|
||||||
|
Template: `{{ userExists "luziferus" }}`,
|
||||||
|
FakedOutput: "true",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func tplTwitchUsernameForID(args plugins.RegistrationArguments) {
|
func tplTwitchUsernameForID(args plugins.RegistrationArguments) {
|
||||||
args.RegisterTemplateFunction("usernameForID", plugins.GenericTemplateFunctionGetter(func(id string) (string, error) {
|
args.RegisterTemplateFunction("usernameForID", plugins.GenericTemplateFunctionGetter(func(id string) (string, error) {
|
||||||
username, err := args.GetTwitchClient().GetUsernameForID(context.Background(), id)
|
username, err := args.GetTwitchClient().GetUsernameForID(context.Background(), id)
|
||||||
|
|
Loading…
Reference in a new issue