mirror of
https://github.com/qwerinope/qweribot.git
synced 2025-12-19 08:41:39 +01:00
absolutely terrible betterttv, frankerfacez and 7tv emote implementation, need to fix
This commit is contained in:
@@ -9,6 +9,10 @@ type badgeObject = {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type emoteObject = {
|
||||||
|
[key: string]: string;
|
||||||
|
}
|
||||||
|
|
||||||
const port = Number(process.env.CHATWIDGET_PORT);
|
const port = Number(process.env.CHATWIDGET_PORT);
|
||||||
if (isNaN(port)) { logger.enverr("CHATWIDGET_PORT"); process.exit(1); };
|
if (isNaN(port)) { logger.enverr("CHATWIDGET_PORT"); process.exit(1); };
|
||||||
|
|
||||||
@@ -31,6 +35,38 @@ const server = Bun.serve({
|
|||||||
|
|
||||||
return Response.json(newObj);
|
return Response.json(newObj);
|
||||||
},
|
},
|
||||||
|
"/getEmotes": async () => {
|
||||||
|
const [bttvglobal, bttvuser, ffzglobal, ffzuser, seventvglobal, seventvuser] = await Promise.all([
|
||||||
|
fetch("https://api.betterttv.net/3/cached/emotes/global").then(a => a.json() as any),
|
||||||
|
fetch("https://api.betterttv.net/3/cached/users/twitch/" + streamerId).then(a => a.json() as any),
|
||||||
|
fetch("https://api.frankerfacez.com/v1/set/global").then(a => a.json() as any),
|
||||||
|
fetch("https://api.frankerfacez.com/v1/room/id/" + streamerId).then(a => a.json() as any),
|
||||||
|
fetch("https://7tv.io/v3/emote-sets/global").then(a => a.json() as any),
|
||||||
|
fetch("https://7tv.io/v3/users/twitch/" + streamerId).then(a => a.json() as any)
|
||||||
|
]);
|
||||||
|
const emotes: emoteObject = {};
|
||||||
|
for (const a of bttvglobal) {
|
||||||
|
emotes[a.code] = `https://cdn.betterttv.net/emote/${a.id}/3x.${a.imageType}`;
|
||||||
|
};
|
||||||
|
for (const a of bttvuser.sharedEmotes) {
|
||||||
|
emotes[a.code] = `https://cdn.betterttv.net/emote/${a.id}/3x.${a.imageType}`;
|
||||||
|
};
|
||||||
|
for (const a of ffzglobal.default_sets) {
|
||||||
|
for (const b of ffzglobal.sets[a].emoticons) {
|
||||||
|
emotes[b.name] = `https://cdn.frankerfacez.com/emote/${b.id}/4`;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
for (const a of ffzuser.sets[ffzuser.room.set].emoticons) {
|
||||||
|
emotes[a.name] = `https://cdn.frankerfacez.com/emote/${a.id}/4`;
|
||||||
|
}
|
||||||
|
for (const a of seventvglobal.emotes) {
|
||||||
|
emotes[a.name] = `https://cdn.7tv.app/emote/${a.id}/4x.avif`;
|
||||||
|
};
|
||||||
|
for (const a of seventvuser.emote_set.emotes) {
|
||||||
|
emotes[a.name] = `https://cdn.7tv.app/emote/${a.id}/4x.avif`;
|
||||||
|
};
|
||||||
|
return Response.json(emotes);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
websocket: {
|
websocket: {
|
||||||
open(_ws) {
|
open(_ws) {
|
||||||
@@ -57,7 +93,7 @@ const server = Bun.serve({
|
|||||||
ws.close();
|
ws.close();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
development: false,
|
development: true,
|
||||||
error(error) {
|
error(error) {
|
||||||
logger.err(`Error at chatwidget server: ${error}`);
|
logger.err(`Error at chatwidget server: ${error}`);
|
||||||
return new Response("Internal Server Error", { status: 500 })
|
return new Response("Internal Server Error", { status: 500 })
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
const badges = await fetch(`http://${location.host}/getBadges`).then(data => data.json());
|
const badges = await fetch(`http://${location.host}/getBadges`).then(data => data.json());
|
||||||
|
const emotes = await fetch(`http://${location.host}/getEmotes`).then(data => data.json());
|
||||||
|
|
||||||
import { type createMessageEvent } from '../../websockettypes';
|
import { type createMessageEvent } from '../../websockettypes';
|
||||||
|
|
||||||
@@ -25,18 +26,38 @@ export function parseMessage(data: createMessageEvent): HTMLDivElement {
|
|||||||
parentDiv.appendChild(chatterName);
|
parentDiv.appendChild(chatterName);
|
||||||
|
|
||||||
const seperator = document.createElement('span');
|
const seperator = document.createElement('span');
|
||||||
seperator.innerText = ": ";
|
seperator.innerText = ":";
|
||||||
seperator.className = "chatMessageSeparator";
|
seperator.className = "chatMessageSeparator";
|
||||||
parentDiv.appendChild(seperator);
|
parentDiv.appendChild(seperator);
|
||||||
|
|
||||||
const textElement = document.createElement('div');
|
const textElement = document.createElement('div');
|
||||||
|
textElement.className = "chatMessage"
|
||||||
for (const messagePart of data.messageParts) {
|
for (const messagePart of data.messageParts) {
|
||||||
let messageElement;
|
let messageElement;
|
||||||
switch (messagePart.type) {
|
switch (messagePart.type) {
|
||||||
case 'text':
|
case 'text':
|
||||||
messageElement = document.createElement('span');
|
messageElement = document.createElement('div');
|
||||||
messageElement.className = "textMessage";
|
messageElement.className = "textMessage";
|
||||||
messageElement.innerText = messagePart.text;
|
let temparray: string[] = [];
|
||||||
|
for (const part of messagePart.text.split(' ')) {
|
||||||
|
if (emotes[part]) {
|
||||||
|
const messagepart = document.createElement('span');
|
||||||
|
messagepart.className = 'textPart';
|
||||||
|
messagepart.innerText = temparray.join(' ');
|
||||||
|
messageElement.appendChild(messagepart);
|
||||||
|
temparray = []; // We flush the array of all pieces of text
|
||||||
|
const emotePart = document.createElement('img');
|
||||||
|
emotePart.className = 'emotePart';
|
||||||
|
emotePart.src = emotes[part];
|
||||||
|
messageElement.appendChild(emotePart);
|
||||||
|
} else {
|
||||||
|
temparray.push(part);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
const finalmessagepart = document.createElement('span');
|
||||||
|
finalmessagepart.className = 'textPart';
|
||||||
|
finalmessagepart.innerText = temparray.join(' ');
|
||||||
|
messageElement.appendChild(finalmessagepart);
|
||||||
break;
|
break;
|
||||||
case 'cheermote':
|
case 'cheermote':
|
||||||
messageElement = document.createElement('img');
|
messageElement = document.createElement('img');
|
||||||
|
|||||||
@@ -31,7 +31,11 @@ body {
|
|||||||
display: inline;
|
display: inline;
|
||||||
}
|
}
|
||||||
|
|
||||||
.replymessage {
|
.chatMesssage {
|
||||||
|
display: inline;
|
||||||
|
}
|
||||||
|
|
||||||
|
.replyMessage {
|
||||||
color: grey;
|
color: grey;
|
||||||
font-size: 2px;
|
font-size: 2px;
|
||||||
}
|
}
|
||||||
@@ -41,6 +45,14 @@ body {
|
|||||||
|
|
||||||
img {
|
img {
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
width: 18px;
|
height: 18px;
|
||||||
padding: 1px;
|
padding: 1px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.message {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chatMessageSeparator {
|
||||||
|
margin-right: 5px
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user