Skip to content

Commit

Permalink
Merge pull request #72 from Kruiser8/develop
Browse files Browse the repository at this point in the history
Update for v2.0.3
  • Loading branch information
Kruiser8 authored Sep 9, 2023
2 parents ad3d41e + 73fcd1f commit 0764e47
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 3 deletions.
28 changes: 27 additions & 1 deletion js/Documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 `<name>` will execute the trigger for all users.
**Format** | `OnHypeChat <name>`
**Format w/ Aliases** | `OnHypeChat <name1> <name2> <name3>`
**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._

Expand Down Expand Up @@ -1073,7 +1099,6 @@ None at the moment.
**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).
**Format** | `Discord Send <name>`
**Example** | `Discord Send "GeneralChannel"`
**Example w/ Message** | `Discord Send "GeneralChannel" "Hey folks!"`

##### Parameters
| | |
Expand Down Expand Up @@ -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).
Expand Down
46 changes: 45 additions & 1 deletion js/chat/chatHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand All @@ -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);
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 = [];
Expand Down
3 changes: 3 additions & 0 deletions js/twitch/twitch-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions js/twitch/twitchHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v2.0.1
v2.0.3

0 comments on commit 0764e47

Please sign in to comment.