Kruiser8 / Kruiz-Control

Kruiz Control enables a pseudo code approach to manage and automatically handle Twitch Channel Points, Twitch Chat, OBS or SLOBS, and StreamElements or Streamlabs alerts.
Other
233 stars 32 forks source link

Action to change stream title and category #58

Closed Epyxx closed 1 year ago

Epyxx commented 1 year ago

Would be awesome to add an Event (e.g. command) that can change the streaming title and category :)

flexiondotorg commented 1 year ago

I've got this implemented using Kruiz Control.

###################################################################################################################################
# Twitch User
# - Save your Twitch username in /settings/twitch/user.txt
#
# User Token
# - Create a user token here https://twitchtokengenerator.com/
#   - Save the API oauth token in /settings/twitch/user-bearer.txt
#   - Save the Client-ID in /settings/twitch/user-clientid.txt
#   - Save the Refresh token in /settings/twitch/user-refresh.txt
#
###################################################################################################################################

OnInit
    # User
    API GET "./settings/twitch/user.txt"
    Function 'return {api_data: [api_data].trim()}'
    Variable Set twitchUser {api_data}
    API GET "https://decapi.me/twitch/id/{twitchUser}"
    Function 'return {api_data: [api_data].trim()}'
    Variable Set twitchUserID {api_data}
    # User Token
    API GET "./settings/twitch/user-bearer.txt"
    Function 'return {api_data: [api_data].trim()}'
    Variable Set twitchUserToken {api_data}
    API GET "./settings/twitch/user-clientid.txt"
    Function 'return {api_data: [api_data].trim()}'
    Variable Set twitchUserClientID {api_data}
    API GET "./settings/twitch/user-refresh.txt"
    Function 'return {api_data: [api_data].trim()}'
    Variable Set twitchUserRefresh {api_data}
    ValidateUserToken

OnAction ValidateUserToken
    Variable Load twitchUserToken
    API Clear APIUserTokenValidate
    API URL APIUserTokenValidate "https://id.twitch.tv/oauth2/validate"
    API Method APIUserTokenValidate GET
    API Header APIUserTokenValidate "Authorization" "Bearer {twitchUserToken}"
    API Send APIUserTokenValidate
    If 1 {api_data} = "error"
        Chat Send "Twitch API User Token invalid ⛔ Time to get a new one 🪪"

OnCommand b 0 !title
    Message Send Title {after}

OnMessage Title
    Variable Set action_name "Title"
    If 2 {data} = ""
        Error "{action_name} was not provided a title"
        Exit
    Variable Load twitchUserID
    Variable Load twitchUserToken
    Variable Load twitchUserClientID
    API Clear APITitle
    API URL APITitle "https://api.twitch.tv/helix/channels?broadcaster_id={twitchUserID}"
    API Method APITitle PATCH
    API Header APITitle "Authorization" "Bearer {twitchUserToken}"
    API Header APITitle "Client-Id" "{twitchUserClientID}"
    API Data APITitle "title" "{data}"
    API Send APITitle
    If 1 {api_data} = "error"
        Error "{action_name} failed while calling Twitch API"

OnCommand b 0 !directory
    Message Send Directory {after}

OnMessage Directory
    Variable Set action_name "Directory"
    If 2 {data} = ""
        Error "{action_name} was not provided a game/directory"
        Exit
    Function 'return {encoded_name: encodeURIComponent([data])}'
    Variable Load twitchUserID
    Variable Load twitchUserToken
    Variable Load twitchUserClientID
    API Clear APIGames
    API URL APIGames "https://api.twitch.tv/helix/games?name={encoded_name}"
    API Method APIGames GET
    API Header APIGames "Authorization" "Bearer {twitchUserToken}"
    API Header APIGames "Client-Id" "{twitchUserClientID}"
    API Send APIGames
    Function 'var data = [api_data]; if (data.data.length != 0) { return {game_id: data.data[0].id}} else { return {game_id: "Error"}}'
    If 2 {game_id} = "error"
        Error "{action_name} failed to find {data} while validating it via DecAPI"
        Exit
    API Clear APIChannels
    API URL APIChannels "https://api.twitch.tv/helix/channels?broadcaster_id={twitchUserID}"
    API Method APIChannels PATCH
    API Header APIChannels "Authorization" "Bearer {twitchUserToken}"
    API Header APIChannels "Client-Id" "{twitchUserClientID}"
    API Data APIChannels "game_id" "{game_id}"
    API Send APIChannels
    If 1 {api_data} = "error"
        Error "{action_name} failed while calling Twitch API"
Kruiser8 commented 1 year ago

This is added in the upcoming release.