mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-12-20 03:41:16 +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 a whisper (requires a verified bot!)
|
||||
Send a whisper
|
||||
|
||||
```yaml
|
||||
- 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: 88%
|
||||
< Your int this hour: 72%
|
||||
```
|
||||
|
||||
### `spotifyCurrentPlaying`
|
||||
|
@ -567,6 +567,19 @@ Example:
|
|||
* 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`
|
||||
|
||||
Returns the current login name of an user-id
|
||||
|
|
|
@ -14,6 +14,7 @@ func init() {
|
|||
tplTwitchDisplayName,
|
||||
tplTwitchIDForUsername,
|
||||
tplTwitchProfileImage,
|
||||
tplTwitchUserExists,
|
||||
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) {
|
||||
args.RegisterTemplateFunction("usernameForID", plugins.GenericTemplateFunctionGetter(func(id string) (string, error) {
|
||||
username, err := args.GetTwitchClient().GetUsernameForID(context.Background(), id)
|
||||
|
|
Loading…
Reference in a new issue