Skip to content

Commit

Permalink
Properly process 7TV API returning same emote multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
GreenComfyTea committed Nov 17, 2023
1 parent 89461d5 commit 43adee0
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ let Channel = {
url = `${url}${emoteId}`;
}

const new_emote = {
const newEmote = {
name: emote.code,
id: emoteId,
type: providerName,
Expand All @@ -77,10 +77,10 @@ let Channel = {
};

if (Channel.info.emotes[emote.code] === undefined) {
Channel.info.emotes[emote.code] = [new_emote];
Channel.info.emotes[emote.code] = [newEmote];
}
else {
Channel.info.emotes[emote.code].push(new_emote);
Channel.info.emotes[emote.code].push(newEmote);
Channel.info.duplicateEmotes[emote.code] = Channel.info.emotes[emote.code];
}

Expand Down Expand Up @@ -125,7 +125,7 @@ let Channel = {
url = `${url}${emoteId}-${emote.code}`;
}

const new_emote = {
const newEmote = {
name: emote.code,
id: emoteId,
type: providerName,
Expand All @@ -135,10 +135,10 @@ let Channel = {
};

if (Channel.info.emotes[emote.code] === undefined) {
Channel.info.emotes[emote.code] = [new_emote];
Channel.info.emotes[emote.code] = [newEmote];
}
else {
Channel.info.emotes[emote.code].push(new_emote);
Channel.info.emotes[emote.code].push(newEmote);
Channel.info.duplicateEmotes[emote.code] = Channel.info.emotes[emote.code];
}

Expand Down Expand Up @@ -177,7 +177,7 @@ let Channel = {
upscale = true;
}

const new_emote = {
const newEmote = {
name: emote.code,
id: emote.id,
type: "FFZ",
Expand All @@ -188,10 +188,10 @@ let Channel = {
};

if (Channel.info.emotes[emote.code] === undefined) {
Channel.info.emotes[emote.code] = [new_emote];
Channel.info.emotes[emote.code] = [newEmote];
}
else {
Channel.info.emotes[emote.code].push(new_emote);
Channel.info.emotes[emote.code].push(newEmote);
Channel.info.duplicateEmotes[emote.code] = Channel.info.emotes[emote.code];
}

Expand Down Expand Up @@ -225,7 +225,7 @@ let Channel = {
const url = `https://betterttv.com/emotes/${emote.id}`;
const imageUrl = `https://cdn.betterttv.net/emote/${emote.id}/3x`

const new_emote = {
const newEmote = {
name: emote.code,
id: emote.id,
type: "BTTV",
Expand All @@ -236,10 +236,10 @@ let Channel = {
};

if (Channel.info.emotes[emote.code] === undefined) {
Channel.info.emotes[emote.code] = [new_emote];
Channel.info.emotes[emote.code] = [newEmote];
}
else {
Channel.info.emotes[emote.code].push(new_emote);
Channel.info.emotes[emote.code].push(newEmote);
Channel.info.duplicateEmotes[emote.code] = Channel.info.emotes[emote.code];
}

Expand Down Expand Up @@ -275,7 +275,7 @@ let Channel = {
emotes.forEach(emote => {
const host = emote.data.host;

const new_emote = {
const newEmote = {
name: emote.name,
id: emote.id,
type: "7TV",
Expand All @@ -285,14 +285,24 @@ let Channel = {
};

if (Channel.info.emotes[emote.name] === undefined) {
Channel.info.emotes[emote.name] = [new_emote];
Channel.info.emotes[emote.name] = [newEmote];
}
else {
Channel.info.emotes[emote.name].push(new_emote);
let misduplicate = Channel.info.emotes[emote.name].some(oldEmote =>
oldEmote.name === newEmote.name &&
oldEmote.id === newEmote.id &&
oldEmote.type === newEmote.type
);

if(misduplicate) {
return;
}

Channel.info.emotes[emote.name].push(newEmote);
Channel.info.duplicateEmotes[emote.name] = Channel.info.emotes[emote.name];
}

DEBUG && console.log(`[7TV${globalString}] ${emote.name}: ${new_emote.url}`);
DEBUG && console.log(`[7TV${globalString}] ${emote.name}: ${newEmote.url}`);
});

DEBUG && console.log(`[7TV${globalString}] Done!`);
Expand Down

0 comments on commit 43adee0

Please sign in to comment.