Closed HeCodes2Much closed 6 years ago
i'll fix that in the near future, twitch drives me crazy
Awesome if you can fix it sooner then later that would be amazing <3 as i plan to use it for my bot :)
😒
i totally didn't absolutely forget about this
i tried to use the code below but i suck with forEach
if(userstate['emotes-raw'] != null) {
var emoteInstances = userstate['emotes-raw'].split('/').reverse();
for(let emoteInstanceId in emoteInstances) {
var emoteInstance = emoteInstances[emoteInstanceId];
var emoteTokens = emoteInstance.split(':');
var emoteId = emoteTokens[0];
var emoteLocations = emoteTokens[1].split(",");
emoteLocations.forEach(function(item, index) {
var emotePos = emoteLocations[index].split('-');
var startPos = parseInt(emotePos[0]);
var endPos = parseInt(emotePos[1]);
message = message.substr(0, startPos) + '<img class="emote" src="https://static-cdn.jtvnw.net/emoticons/v1/' + emoteId + '/1.0" />' + message.substr(endPos + 1);
});
}
}
it's fucked because if you mix emotes together, you'll get emotes-raw mixed all over too, like
282353:6-15,23-32/25:0-4,17-21
so you have to get the positions out, sort them in another array then start replacing from the end again
which makes me 🤢 just thinking about
this is how another chat does theres but it requires there bot as its using websockets from there bot
Chat = {
parseManualEmotes: function(msg) {
if (Chat.data.emoticons.Twitch === undefined)
return msg;
var messageParts = msg.split(" ");
var messageOut = "";
messageParts.forEach(function(m) {
var matched = 0;
if (messageOut != "")
messageOut += " ";
if (!Chat.isLink(m)) {
Chat.data.emoticons.Twitch.forEach(function(a) {
if (matched == 0 && m.match(a.regex)) {
messageOut += "<img class=\"emote\" src=\"//static-cdn.jtvnw.net/emoticons/v1/" + a.id + "/1.0\"></img>"
matched = 1;
}
});
Chat.data.emoticons.BTTV.forEach(function(a) {
if (matched == 0 && m.match(a.regex)) {
messageOut += "<img class=\"emote\" src=\"//cdn.betterttv.net/emote/" + a.id + "/1x\"></img>"
matched = 1;
}
});
Chat.data.emoticons.FFZ.forEach(function(a) {
if (matched == 0 && m.match(a.regex)) {
messageOut += "<img class=\"emote\" src=\"//cdn.frankerfacez.com/emoticon/" + a.id + "/1\"></img>"
matched = 1;
}
});
}
if (matched == 0)
messageOut += m;
});
return messageOut;
}
}
this code is absolutely irrelevant and useless in this case
Emotes dont work if more then 1 emote :(