mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-12-20 11:51:17 +00:00
[templating] Add idForUsername
function
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
fb57cb9304
commit
a5df68d921
2 changed files with 42 additions and 2 deletions
|
@ -232,6 +232,19 @@ Example:
|
|||
< test - oops
|
||||
```
|
||||
|
||||
### `idForUsername`
|
||||
|
||||
Returns the user-id for the given username
|
||||
|
||||
Syntax: `idForUsername <username>`
|
||||
|
||||
Example:
|
||||
|
||||
```
|
||||
# {{ idForUsername "twitch" }}
|
||||
* 12826
|
||||
```
|
||||
|
||||
### `inList`
|
||||
|
||||
Tests whether a string is in a given list of strings (for conditional templates).
|
||||
|
@ -376,7 +389,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: 9%
|
||||
< Your int this hour: 77%
|
||||
```
|
||||
|
||||
### `streamUptime`
|
||||
|
@ -446,6 +459,19 @@ Example:
|
|||
* Weather for Hamburg, DE: Few clouds with a temperature of 22 C (71.6 F). [...]
|
||||
```
|
||||
|
||||
### `usernameForID`
|
||||
|
||||
Returns the current login name of an user-id
|
||||
|
||||
Syntax: `usernameForID <user-id>`
|
||||
|
||||
Example:
|
||||
|
||||
```
|
||||
# {{ usernameForID "12826" }}
|
||||
* twitch
|
||||
```
|
||||
|
||||
### `variable`
|
||||
|
||||
Returns the variable value or default in case it is empty
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
"github.com/Luzifer/twitch-bot/v3/plugins"
|
||||
)
|
||||
|
||||
//nolint:funlen
|
||||
func init() {
|
||||
tplFuncs.Register("displayName", plugins.GenericTemplateFunctionGetter(tplTwitchDisplayName), plugins.TemplateFuncDocumentation{
|
||||
Description: "Returns the display name the specified user set for themselves",
|
||||
|
@ -58,6 +59,15 @@ func init() {
|
|||
},
|
||||
})
|
||||
|
||||
tplFuncs.Register("idForUsername", plugins.GenericTemplateFunctionGetter(tplTwitchIDForUsername), plugins.TemplateFuncDocumentation{
|
||||
Description: "Returns the user-id for the given username",
|
||||
Syntax: "idForUsername <username>",
|
||||
Example: &plugins.TemplateFuncDocumentationExample{
|
||||
Template: `{{ idForUsername "twitch" }}`,
|
||||
FakedOutput: "12826",
|
||||
},
|
||||
})
|
||||
|
||||
tplFuncs.Register("lastPoll", plugins.GenericTemplateFunctionGetter(tplTwitchLastPoll), plugins.TemplateFuncDocumentation{
|
||||
Description: "Gets the last (currently running or archived) poll for the given channel (the channel must have given extended permission for poll access!)",
|
||||
Syntax: "lastPoll <channel>",
|
||||
|
@ -105,7 +115,7 @@ func init() {
|
|||
})
|
||||
|
||||
tplFuncs.Register("usernameForID", plugins.GenericTemplateFunctionGetter(tplTwitchUsernameForID), plugins.TemplateFuncDocumentation{
|
||||
Description: "Returns the currente login name of an user-id",
|
||||
Description: "Returns the current login name of an user-id",
|
||||
Syntax: "usernameForID <user-id>",
|
||||
Example: &plugins.TemplateFuncDocumentationExample{
|
||||
Template: `{{ usernameForID "12826" }}`,
|
||||
|
@ -178,6 +188,10 @@ func tplTwitchDoesFollowLongerThan(from, to string, t any) (bool, error) {
|
|||
}
|
||||
}
|
||||
|
||||
func tplTwitchIDForUsername(username string) (string, error) {
|
||||
return twitchClient.GetIDForUsername(username)
|
||||
}
|
||||
|
||||
func tplTwitchLastPoll(username string) (*twitch.PollInfo, error) {
|
||||
hasPollAccess, err := accessService.HasAnyPermissionForChannel(username, twitch.ScopeChannelReadPolls, twitch.ScopeChannelManagePolls)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in a new issue