diff --git a/docs/content/configuration/templating.md b/docs/content/configuration/templating.md index 442808f..2b4ed31 100644 --- a/docs/content/configuration/templating.md +++ b/docs/content/configuration/templating.md @@ -232,6 +232,19 @@ Example: < test - oops ``` +### `idForUsername` + +Returns the user-id for the given username + +Syntax: `idForUsername ` + +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 ` + +Example: + +``` +# {{ usernameForID "12826" }} +* twitch +``` + ### `variable` Returns the variable value or default in case it is empty diff --git a/functions_twitch.go b/functions_twitch.go index 25d8848..0b2468d 100644 --- a/functions_twitch.go +++ b/functions_twitch.go @@ -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 ", + 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 ", @@ -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 ", 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 {