diff --git a/js/Documentation.md b/js/Documentation.md index 79416ef..ced9716 100644 --- a/js/Documentation.md +++ b/js/Documentation.md @@ -30,6 +30,7 @@ Each handler provides its own triggers and actions that can be used in a trigger * [Triggers](#chat-triggers) + [OnCommand](#oncommand) + [OnEveryChatMessage](#oneverychatmessage) + + [OnHypeChat](#onhypechat) + [OnKeyword](#onkeyword) + [OnSpeak](#onspeak) * [Actions](#chat-actions) @@ -726,6 +727,31 @@ _WARNING: Kruiz Control responds to messages sent by Kruiz Control. Please be mi *** +#### OnHypeChat +| | | +------------ | ------------- +**Info** | Used to trigger a set of actions when a user sends a hype chat. Using `*` as the `` will execute the trigger for all users. +**Format** | `OnHypeChat ` +**Format w/ Aliases** | `OnHypeChat ` +**Example** | `OnHypeChat Kruiser8` +**Example w/ Aliases** | `OnHypeChat Kruiser8 Kruizbot` + +##### Parameters +| | | +------------ | ------------- +**user** | The display name of the user that sent the command. +**message** | The entire chat message, including the command. +**message_id** | The id of the message (used with [Twitch DeleteMessage](#twitch-deletemessage)). If the message was sent by Kruiz Control, the id will be an empty string (`""`). +**amount** | The value of the Hype Chat sent by the user. Example: `500` if $5 was tipped. +**formatted_amount** | The formatted value of the Hype Chat sent by the user. Example: `5.00` is $5 was tipped. +**currency** | The [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217#List_of_ISO_4217_currency_codes) alphabetic currency code the user has sent the Hype Chat in. +**exponent** | Indicates how many decimal points this currency represents partial amounts in. Decimal points start from the right side of the value defined in `amount`. +**level** | The level of the Hype Chat, in English. Possible values are [`ONE`, `TWO`, ..., `TEN`], written in all caps. +**is_system_message** | A boolean value that determines if the message sent with the Hype Chat was filled in by the system. +**data** | An object with all metadata about the message (for use with [Function](#function)). + +*** + #### OnKeyword _WARNING: Kruiz Control responds to messages sent by Kruiz Control. Please be mindful of your commands, keywords, and messages so that you do not trigger an infinite loop of messages. Twitch has [chat limits](https://dev.twitch.tv/docs/irc/guide#command--message-limits) and will block you from chatting._ @@ -1073,7 +1099,6 @@ None at the moment. **Info** | Used to send a message to discord, using any embed data currently set. `` is the id that was used to register the webhook in a [`Discord Create`](#discord-create). **Format** | `Discord Send ` **Example** | `Discord Send "GeneralChannel"` -**Example w/ Message** | `Discord Send "GeneralChannel" "Hey folks!"` ##### Parameters | | | @@ -3805,6 +3830,7 @@ _Note: Bit voting is not currently supported, however Twitch provides these valu ##### Parameters | | | ------------ | ------------- +**channel_id** | The broadcaster's Twitch channel ID. **client_id** | The Twitch client ID. **client_secret** | The Twitch client secret. **access_token** | The current Twitch OAuth access token (The _bearer_ token). diff --git a/js/chat/chatHandler.js b/js/chat/chatHandler.js index 27db9bb..a2d287f 100644 --- a/js/chat/chatHandler.js +++ b/js/chat/chatHandler.js @@ -3,7 +3,7 @@ class ChatHandler extends Handler { * Create a new Chat handler. */ constructor() { - super('Chat', ['OnCommand','OnKeyword','OnEveryChatMessage','OnSpeak']); + super('Chat', ['OnCommand','OnKeyword','OnEveryChatMessage','OnHypeChat', 'OnSpeak']); /* OnCommand */ this.commands = []; @@ -23,6 +23,10 @@ class ChatHandler extends Handler { /* OnEveryChatMessage */ this.chatTriggers = []; + /* OnHypeChat */ + this.onHypeChats = []; + this.onHypeChatsInfo = {}; + this.init.bind(this); this.checkPermissions.bind(this); this.addFollowerActions.bind(this); @@ -149,6 +153,17 @@ class ChatHandler extends Handler { case 'oneverychatmessage': this.chatTriggers.push(triggerId); break; + case 'onhypechat': + var { users } = Parser.getInputs(triggerLine, ['users'], true); + users.forEach(user => { + user = user.toLowerCase(); + if (this.onHypeChats.indexOf(user) === -1) { + this.onHypeChats.push(user); + this.onHypeChatsInfo[user] = []; + } + this.onHypeChatsInfo[user].push(triggerId); + }); + break; default: // do nothing } @@ -439,6 +454,35 @@ class ChatHandler extends Handler { controller.handleData(triggerId, data); }); + // Check for OnHypeChat + if ("pinned-chat-paid-amount" in data.data.extra.userState) { + var userLower = user.toLowerCase(); + var onHypeChatTriggers = []; + if (this.onHypeChats.indexOf(userLower) !== -1) { + onHypeChatTriggers.push(...this.onHypeChatsInfo[userLower]); + } + if (this.onHypeChats.indexOf('*') !== -1) { + onHypeChatTriggers.push(...this.onHypeChatsInfo['*']); + } + if (onHypeChatTriggers.length > 0) { + var userState = data.data.extra.userState; + var hypeChatData = { + amount: userState["pinned-chat-paid-amount"], + formatted_amount: (userState["pinned-chat-paid-amount"] / Math.pow(10, userState["pinned-chat-paid-exponent"])).toFixed(userState["pinned-chat-paid-exponent"]), + currency: userState["pinned-chat-paid-currency"], + exponent: userState["pinned-chat-paid-exponent"], + level: userState["pinned-chat-paid-level"], + is_system_message: userState["pinned-chat-paid-is-system-message"], + ...data + }; + + onHypeChatTriggers.sort((a, b) => a-b); + onHypeChatTriggers.forEach(triggerId => { + controller.handleData(triggerId, hypeChatData); + }); + } + } + // Check for OnSpeak Event var userLower = user.toLowerCase(); var onSpeakTriggers = []; diff --git a/js/twitch/twitch-api.js b/js/twitch/twitch-api.js index 6c0b9fd..9d93dcb 100644 --- a/js/twitch/twitch-api.js +++ b/js/twitch/twitch-api.js @@ -89,6 +89,9 @@ class TwitchAPI { var response = 'Error with Twitch API'; if (!this.triedRefresh && error.status === 401) { this.triedRefresh = true; + setTimeout(() => { + this.triedRefresh = false; + }, 600000); response = await this.refreshAuthToken({ method, endpoint, headers, params, data }); } resolve(response); diff --git a/js/twitch/twitchHandler.js b/js/twitch/twitchHandler.js index 496cbdb..f6f73e8 100644 --- a/js/twitch/twitchHandler.js +++ b/js/twitch/twitchHandler.js @@ -966,6 +966,7 @@ class TwitchHandler extends Handler { break; case 'auth': return { + channel_id: this.channelId, client_id: this.api.clientId, client_secret: this.api.clientSecret, access_token: this.api.accessToken diff --git a/version.txt b/version.txt index 0ac852d..f256be6 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -v2.0.1 +v2.0.3