Skip to content

Commit 0764e47

Browse files
authored
Merge pull request #72 from Kruiser8/develop
Update for v2.0.3
2 parents ad3d41e + 73fcd1f commit 0764e47

5 files changed

Lines changed: 77 additions & 3 deletions

File tree

js/Documentation.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Each handler provides its own triggers and actions that can be used in a trigger
3030
* [Triggers](#chat-triggers)
3131
+ [OnCommand](#oncommand)
3232
+ [OnEveryChatMessage](#oneverychatmessage)
33+
+ [OnHypeChat](#onhypechat)
3334
+ [OnKeyword](#onkeyword)
3435
+ [OnSpeak](#onspeak)
3536
* [Actions](#chat-actions)
@@ -726,6 +727,31 @@ _WARNING: Kruiz Control responds to messages sent by Kruiz Control. Please be mi
726727

727728
***
728729

730+
#### OnHypeChat
731+
| | |
732+
------------ | -------------
733+
**Info** | Used to trigger a set of actions when a user sends a hype chat. Using `*` as the `<name>` will execute the trigger for all users.
734+
**Format** | `OnHypeChat <name>`
735+
**Format w/ Aliases** | `OnHypeChat <name1> <name2> <name3>`
736+
**Example** | `OnHypeChat Kruiser8`
737+
**Example w/ Aliases** | `OnHypeChat Kruiser8 Kruizbot`
738+
739+
##### Parameters
740+
| | |
741+
------------ | -------------
742+
**user** | The display name of the user that sent the command.
743+
**message** | The entire chat message, including the command.
744+
**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 (`""`).
745+
**amount** | The value of the Hype Chat sent by the user. Example: `500` if $5 was tipped.
746+
**formatted_amount** | The formatted value of the Hype Chat sent by the user. Example: `5.00` is $5 was tipped.
747+
**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.
748+
**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`.
749+
**level** | The level of the Hype Chat, in English. Possible values are [`ONE`, `TWO`, ..., `TEN`], written in all caps.
750+
**is_system_message** | A boolean value that determines if the message sent with the Hype Chat was filled in by the system.
751+
**data** | An object with all metadata about the message (for use with [Function](#function)).
752+
753+
***
754+
729755
#### OnKeyword
730756
_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._
731757

@@ -1073,7 +1099,6 @@ None at the moment.
10731099
**Info** | Used to send a message to discord, using any embed data currently set. `<name>` is the id that was used to register the webhook in a [`Discord Create`](#discord-create).
10741100
**Format** | `Discord Send <name>`
10751101
**Example** | `Discord Send "GeneralChannel"`
1076-
**Example w/ Message** | `Discord Send "GeneralChannel" "Hey folks!"`
10771102

10781103
##### Parameters
10791104
| | |
@@ -3805,6 +3830,7 @@ _Note: Bit voting is not currently supported, however Twitch provides these valu
38053830
##### Parameters
38063831
| | |
38073832
------------ | -------------
3833+
**channel_id** | The broadcaster's Twitch channel ID.
38083834
**client_id** | The Twitch client ID.
38093835
**client_secret** | The Twitch client secret.
38103836
**access_token** | The current Twitch OAuth access token (The _bearer_ token).

js/chat/chatHandler.js

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ class ChatHandler extends Handler {
33
* Create a new Chat handler.
44
*/
55
constructor() {
6-
super('Chat', ['OnCommand','OnKeyword','OnEveryChatMessage','OnSpeak']);
6+
super('Chat', ['OnCommand','OnKeyword','OnEveryChatMessage','OnHypeChat', 'OnSpeak']);
77

88
/* OnCommand */
99
this.commands = [];
@@ -23,6 +23,10 @@ class ChatHandler extends Handler {
2323
/* OnEveryChatMessage */
2424
this.chatTriggers = [];
2525

26+
/* OnHypeChat */
27+
this.onHypeChats = [];
28+
this.onHypeChatsInfo = {};
29+
2630
this.init.bind(this);
2731
this.checkPermissions.bind(this);
2832
this.addFollowerActions.bind(this);
@@ -149,6 +153,17 @@ class ChatHandler extends Handler {
149153
case 'oneverychatmessage':
150154
this.chatTriggers.push(triggerId);
151155
break;
156+
case 'onhypechat':
157+
var { users } = Parser.getInputs(triggerLine, ['users'], true);
158+
users.forEach(user => {
159+
user = user.toLowerCase();
160+
if (this.onHypeChats.indexOf(user) === -1) {
161+
this.onHypeChats.push(user);
162+
this.onHypeChatsInfo[user] = [];
163+
}
164+
this.onHypeChatsInfo[user].push(triggerId);
165+
});
166+
break;
152167
default:
153168
// do nothing
154169
}
@@ -439,6 +454,35 @@ class ChatHandler extends Handler {
439454
controller.handleData(triggerId, data);
440455
});
441456

457+
// Check for OnHypeChat
458+
if ("pinned-chat-paid-amount" in data.data.extra.userState) {
459+
var userLower = user.toLowerCase();
460+
var onHypeChatTriggers = [];
461+
if (this.onHypeChats.indexOf(userLower) !== -1) {
462+
onHypeChatTriggers.push(...this.onHypeChatsInfo[userLower]);
463+
}
464+
if (this.onHypeChats.indexOf('*') !== -1) {
465+
onHypeChatTriggers.push(...this.onHypeChatsInfo['*']);
466+
}
467+
if (onHypeChatTriggers.length > 0) {
468+
var userState = data.data.extra.userState;
469+
var hypeChatData = {
470+
amount: userState["pinned-chat-paid-amount"],
471+
formatted_amount: (userState["pinned-chat-paid-amount"] / Math.pow(10, userState["pinned-chat-paid-exponent"])).toFixed(userState["pinned-chat-paid-exponent"]),
472+
currency: userState["pinned-chat-paid-currency"],
473+
exponent: userState["pinned-chat-paid-exponent"],
474+
level: userState["pinned-chat-paid-level"],
475+
is_system_message: userState["pinned-chat-paid-is-system-message"],
476+
...data
477+
};
478+
479+
onHypeChatTriggers.sort((a, b) => a-b);
480+
onHypeChatTriggers.forEach(triggerId => {
481+
controller.handleData(triggerId, hypeChatData);
482+
});
483+
}
484+
}
485+
442486
// Check for OnSpeak Event
443487
var userLower = user.toLowerCase();
444488
var onSpeakTriggers = [];

js/twitch/twitch-api.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ class TwitchAPI {
8989
var response = 'Error with Twitch API';
9090
if (!this.triedRefresh && error.status === 401) {
9191
this.triedRefresh = true;
92+
setTimeout(() => {
93+
this.triedRefresh = false;
94+
}, 600000);
9295
response = await this.refreshAuthToken({ method, endpoint, headers, params, data });
9396
}
9497
resolve(response);

js/twitch/twitchHandler.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,7 @@ class TwitchHandler extends Handler {
966966
break;
967967
case 'auth':
968968
return {
969+
channel_id: this.channelId,
969970
client_id: this.api.clientId,
970971
client_secret: this.api.clientSecret,
971972
access_token: this.api.accessToken

version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v2.0.1
1+
v2.0.3

0 commit comments

Comments
 (0)