mirror of
https://github.com/nuttylmao/nutty.gg.git
synced 2026-09-18 19:50:58 -04:00
Added basic TikFinity support
This commit is contained in:
+178
-1
@@ -310,6 +310,60 @@ function CustomCodeEvent(data) {
|
||||
|
||||
|
||||
|
||||
//////////////////////
|
||||
// TIKFINITY CLIENT //
|
||||
//////////////////////
|
||||
|
||||
let tikfinityWebsocket = null;
|
||||
|
||||
function tikfinityConnect() {
|
||||
if (tikfinityWebsocket) return; // Already connected
|
||||
|
||||
tikfinityWebsocket = new WebSocket("ws://localhost:21213/");
|
||||
|
||||
tikfinityWebsocket.onopen = function () {
|
||||
console.log(`TikFinity successfully connected...`)
|
||||
}
|
||||
|
||||
tikfinityWebsocket.onclose = function () {
|
||||
console.error(`TikFinity disconnected...`)
|
||||
tikfinityWebsocket = null;
|
||||
setTimeout(tikfinityConnect, 1000); // Schedule a reconnect attempt
|
||||
}
|
||||
|
||||
tikfinityWebsocket.onerror = function () {
|
||||
console.error(`TikFinity failed for some reason...`)
|
||||
tikfinityWebsocket = null;
|
||||
setTimeout(tikfinityConnect, 1000); // Schedule a reconnect attempt
|
||||
}
|
||||
|
||||
tikfinityWebsocket.onmessage = function (response) {
|
||||
let payload = JSON.parse(response.data);
|
||||
|
||||
let event = payload.event;
|
||||
let data = payload.data;
|
||||
|
||||
console.debug('Event: ' + event);
|
||||
|
||||
switch (event) {
|
||||
case 'chat':
|
||||
TikTokChat(data);
|
||||
break;
|
||||
case 'gift':
|
||||
TikTokGift(data);
|
||||
break;
|
||||
case 'subscribe':
|
||||
TikTokSubscribe(data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Try connect when window is loaded
|
||||
window.addEventListener('load', tikfinityConnect);
|
||||
|
||||
|
||||
|
||||
/////////////////////
|
||||
// HORIZONTAL CHAT //
|
||||
/////////////////////
|
||||
@@ -1312,6 +1366,129 @@ function KickBan(data) {
|
||||
});
|
||||
}
|
||||
|
||||
async function TikTokChat(data) {
|
||||
// Don't post messages starting with "!"
|
||||
if (data.comment.startsWith("!") && excludeCommands)
|
||||
return;
|
||||
|
||||
// Don't post messages from users from the ignore list
|
||||
if (ignoreUserList.includes(data.comment.toLowerCase()))
|
||||
return;
|
||||
|
||||
// Get a reference to the template
|
||||
const template = document.getElementById('messageTemplate');
|
||||
|
||||
// Create a new instance of the template
|
||||
const instance = template.content.cloneNode(true);
|
||||
|
||||
// Get divs
|
||||
const userInfoDiv = instance.querySelector("#userInfo");
|
||||
const avatarDiv = instance.querySelector("#avatar");
|
||||
const timestampDiv = instance.querySelector("#timestamp");
|
||||
const platformDiv = instance.querySelector("#platform");
|
||||
const badgeListDiv = instance.querySelector("#badgeList");
|
||||
const pronounsDiv = instance.querySelector("#pronouns");
|
||||
const usernameDiv = instance.querySelector("#username");
|
||||
const messageDiv = instance.querySelector("#message");
|
||||
|
||||
// Set timestamp
|
||||
if (showTimestamps) {
|
||||
timestampDiv.classList.add("timestamp");
|
||||
timestampDiv.innerText = GetCurrentTimeFormatted();
|
||||
}
|
||||
|
||||
// Set the username info
|
||||
if (showUsername) {
|
||||
usernameDiv.innerText = data.nickname;
|
||||
usernameDiv.style.color = '#9e9e9e';
|
||||
}
|
||||
|
||||
// Set the message data
|
||||
let message = data.comment;
|
||||
|
||||
// Set furry mode
|
||||
if (furryMode)
|
||||
message = TranslateToFurry(message);
|
||||
|
||||
// Set message text
|
||||
if (showMessage) {
|
||||
messageDiv.innerText = message;
|
||||
}
|
||||
|
||||
// Render platform
|
||||
if (showPlatform) {
|
||||
const platformElements = `<img src="icons/platforms/tiktok.png" class="platform"/>`;
|
||||
platformDiv.innerHTML = platformElements;
|
||||
}
|
||||
|
||||
// Render badges
|
||||
if (showBadges) {
|
||||
badgeListDiv.innerHTML = "";
|
||||
|
||||
if (data.isModerator) {
|
||||
const badge = new Image();
|
||||
badge.src = `icons/badges/youtube-moderator.svg`;
|
||||
badge.style.filter = `invert(100%)`;
|
||||
badge.style.opacity = 0.8;
|
||||
badge.classList.add("badge");
|
||||
badgeListDiv.appendChild(badge);
|
||||
}
|
||||
|
||||
for (i in data.userBadges) {
|
||||
if (data.userBadges[i].type == 'image') {
|
||||
const badge = new Image();
|
||||
badge.src = data.userBadges[i].url;
|
||||
badge.classList.add("badge");
|
||||
badgeListDiv.appendChild(badge);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Render avatars
|
||||
if (showAvatar) {
|
||||
const avatar = new Image();
|
||||
avatar.src = data.profilePictureUrl;
|
||||
avatar.classList.add("avatar");
|
||||
avatarDiv.appendChild(avatar);
|
||||
}
|
||||
|
||||
// Hide the header if the same username sends a message twice in a row
|
||||
const messageList = document.getElementById("messageList");
|
||||
if (groupConsecutiveMessages && messageList.children.length > 0) {
|
||||
const lastPlatform = messageList.lastChild.dataset.platform;
|
||||
const lastUserId = messageList.lastChild.dataset.userId;
|
||||
if (lastPlatform == "tiktok" && lastUserId == data.userId)
|
||||
userInfoDiv.style.display = "none";
|
||||
}
|
||||
|
||||
AddMessageItem(instance, data.msgId, 'tiktok', data.userId);
|
||||
}
|
||||
|
||||
async function TikTokGift(data) {
|
||||
if (data.giftType === 1 && !data.repeatEnd) {
|
||||
// Streak in progress => show only temporary
|
||||
console.debug(`${data.uniqueId} is sending gift ${data.giftName} x${data.repeatCount}`);
|
||||
return;
|
||||
}
|
||||
|
||||
// Streak ended or non-streakable gift => process the gift with final repeat_count
|
||||
console.debug(`${data.uniqueId} has sent gift ${data.giftName} x${data.repeatCount}`);
|
||||
|
||||
const giftImg = `<img src=${data.giftPictureUrl} class="platform"/>`;
|
||||
|
||||
const message = `${data.nickname} sent ${giftImg}x${data.repeatCount}`;
|
||||
|
||||
ShowAlert(message, 'tiktok');
|
||||
}
|
||||
|
||||
async function TikTokSubscribe(data) {
|
||||
let username = data.nickname;
|
||||
|
||||
const message = `${username} subscribed on TikTok`;
|
||||
|
||||
ShowAlert(message, 'tiktok');
|
||||
}
|
||||
|
||||
|
||||
|
||||
//////////////////////
|
||||
@@ -1521,7 +1698,7 @@ function ShowAlert(message, background = null, duration = animationDuration) {
|
||||
const alertBoxContent = document.querySelector("#alertBoxContent");
|
||||
|
||||
// Set the message text
|
||||
alertBoxContent.innerHTML = message;
|
||||
alertBoxContent.innerHTML = message;
|
||||
|
||||
// Set the background
|
||||
alertBoxDiv.classList.add(background);
|
||||
|
||||
Reference in New Issue
Block a user