Added a setting for Twitch GIPHY support

This commit is contained in:
nutty
2026-09-18 07:19:42 +10:00
parent dc7a163a52
commit 66348b14f7
5 changed files with 36 additions and 13 deletions
+9 -4
View File
@@ -325,7 +325,7 @@ function RandomHex(str) {
}
// Used to construct a message from "parts" variable commonly found in Streamer.bot chat messages
function ConstructMessageFromParts(parts, isHorizontalChat = false) {
function ConstructMessageFromParts(parts, isHorizontalChat = false, twitchGIFsEnabled = false) {
return parts.map(part => {
if (part.emoji)
return ` <img src="${EscapeHTML(part.image)}" alt="${EscapeHTML(part.text)}" title="${EscapeHTML(part.text)}" class="emote"> `;
@@ -358,10 +358,15 @@ function ConstructMessageFromParts(parts, isHorizontalChat = false) {
case "mention":
return part.text;
case "gif":
if (!isHorizontalChat)
return `<img src="${EscapeHTML(part.url)}" class="gif">`;
if (twitchGIFsEnabled)
{
if (!isHorizontalChat)
return `<img src="${EscapeHTML(part.url)}" class="gif">`;
else
return `<img src="${EscapeHTML(part.url)}" class="emote">`;
}
else
return `<img src="${EscapeHTML(part.url)}" class="emote">`;
return `<b><i>${EscapeHTML(part.text)}</i></b>`;
default:
return `<img src="${EscapeHTML(part.imageUrl)}" alt="${EscapeHTML(part.text)}" title="${EscapeHTML(part.text)}" class="emote">`;
}
+5 -4
View File
@@ -51,6 +51,7 @@ const showTwitchPowerUpRedemptions = GetBooleanParam("showTwitchPowerUpRedemptio
const showTwitchRaids = GetBooleanParam("showTwitchRaids", true);
const showTwitchWatchStreaks = GetBooleanParam("showTwitchWatchStreaks", true);
const showTwitchSharedChat = GetBooleanParam("showTwitchSharedChat", true);
const showTwitchGIFs = GetBooleanParam("showTwitchGIFs", false);
const showKickMessages = GetBooleanParam("showKickMessages", true);
const showKickFollows = GetBooleanParam("showKickFollows", false);
@@ -588,7 +589,7 @@ async function TwitchChatMessage(data) {
}
// Set the message data
let message = ConstructMessageFromParts(data.parts, isHorizontalChat = true);
let message = ConstructMessageFromParts(data.parts, true, showTwitchGIFs);
const messageColor = data.user.color;
const role = data.user.role;
@@ -693,7 +694,7 @@ async function TwitchAnnouncement(data) {
break;
}
let message = ConstructMessageFromParts(data.parts, isHorizontalChat = true);
let message = ConstructMessageFromParts(data.parts, true, showTwitchGIFs);
ShowAlert(message, background);
}
@@ -949,7 +950,7 @@ function YouTubeMessage(data) {
// Set the message data
//let message = RenderMessageWithEmotesHTML(data.message, data.emotes);
let message = ConstructMessageFromParts(data.parts, isHorizontalChat = true);
let message = ConstructMessageFromParts(data.parts, true, showTwitchGIFs);
// Set furry mode
if (furryMode)
@@ -1394,7 +1395,7 @@ async function KickChatMessage(data) {
}
// Set the message data
let message = ConstructMessageFromParts(data.parts, isHorizontalChat = true);
let message = ConstructMessageFromParts(data.parts, true, showTwitchGIFs);
// Set furry mode
if (furryMode)
+8
View File
@@ -226,6 +226,14 @@
"defaultValue": true,
"group": "Which Twitch messages do you want to see?"
},
{
"id": "showTwitchGIFs",
"label": "GIFs",
"description": "Tier 2/3 subs only",
"type": "checkbox",
"defaultValue": false,
"group": "Which Twitch messages do you want to see?"
},
{
"id": "showYouTubeMessages",
"label": "Chat Messages",
+6 -5
View File
@@ -57,6 +57,7 @@ const showTwitchPowerUpRedemptions = GetBooleanParam("showTwitchPowerUpRedemptio
const showTwitchRaids = GetBooleanParam("showTwitchRaids", true);
const showTwitchWatchStreaks = GetBooleanParam("showTwitchWatchStreaks", true);
const showTwitchSharedChat = GetIntParam("showTwitchSharedChat", 2);
const showTwitchGIFs = GetBooleanParam("showTwitchGIFs", true);
const showKickMessages = GetBooleanParam("showKickMessages", true);
const showKickFollows = GetBooleanParam("showKickFollows", false);
@@ -687,7 +688,7 @@ async function TwitchChatMessage(data) {
}
// Set the message data
let message = ConstructMessageFromParts(data.parts);
let message = ConstructMessageFromParts(data.parts, false, showTwitchGIFs);
const messageColor = data.user.color;
const role = data.user.role;
@@ -939,7 +940,7 @@ async function TwitchAnnouncement(data) {
else
content.querySelector("#username").innerText = `${data.user.name} (${data.user.login})`;
content.querySelector("#username").style.color = data.user.color;
content.querySelector("#message").innerHTML = ConstructMessageFromParts(data.parts);
content.querySelector("#message").innerHTML = ConstructMessageFromParts(data.parts, false, showTwitchGIFs);
// Remove the line break
content.querySelector("#colon-separator").style.display = `inline`;
@@ -1322,7 +1323,7 @@ async function TwitchWatchStreak(data) {
const watchStreak = data.watchStreak ?? data.streak_count ?? data.streakCount;
titleDiv.innerText = `${displayName} is currently on a ${watchStreak} stream streak! `;
contentDiv.innerHTML = ConstructMessageFromParts(data.parts);
contentDiv.innerHTML = ConstructMessageFromParts(data.parts, false, showTwitchGIFs);
AddMessageItem(instance, data.messageId);
}
@@ -1439,7 +1440,7 @@ async function YouTubeMessage(data) {
// Set the message data
//let message = RenderMessageWithEmotesHTML(data.message, data.emotes);
let message = ConstructMessageFromParts(data.parts);
let message = ConstructMessageFromParts(data.parts, false, showTwitchGIFs);
// Highlight mentions
const mentionRgx = new RegExp(`(^|\\s)@${youtubeUsername}(\\s|$)`, 'i');
@@ -2484,7 +2485,7 @@ async function KickChatMessage(data) {
}
// Set the message data
let message = ConstructMessageFromParts(data.parts);
let message = ConstructMessageFromParts(data.parts, false, showTwitchGIFs);
// Highlight mentions
const mentionRgx = new RegExp(`(^|\\s)@${kickUsername}(\\s|$)`, 'i');
+8
View File
@@ -355,6 +355,14 @@
"defaultValue": 2,
"group": "Which Twitch messages do you want to see?"
},
{
"id": "showTwitchGIFs",
"label": "GIFs",
"description": "Tier 2/3 subs only",
"type": "checkbox",
"defaultValue": true,
"group": "Which Twitch messages do you want to see?"
},
{
"id": "showYouTubeMessages",
"label": "Chat Messages",