Skip to content

Commit

Permalink
all personal emotes should fetch now
Browse files Browse the repository at this point in the history
  • Loading branch information
Fiszh authored Oct 12, 2024
1 parent 854029c commit 034b15b
Showing 1 changed file with 35 additions and 17 deletions.
52 changes: 35 additions & 17 deletions src/SevenTVHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,29 +67,45 @@ async function getPaint(paint_id) {
}

async function getUserPersonalEmotes(user_id) {
const response = await fetch(`https://7tv.io/v3/users/${user_id}`);
try {
const response = await fetch(`https://7tv.io/v3/users/twitch/${user_id}`);

if (!response.ok) {
throw new Error('Network response was not ok');
}
if (!response.ok) {
return null;
}

const data = await response.json();

const data = await response.json();
if (!data || !data.user || !data.user.emote_sets) {
return null;
}

if (!data.emote_sets) {
return null;
}
let fetchedEmoteSets = [];
let emoteData = [];

for (const emote_set of data.user.emote_sets) {
if (!fetchedEmoteSets[emote_set.id]) {
const emote_data = await fetch7TVEmoteData(emote_set.id);

for (const element of data.emote_sets) {
if (element.name === "Personal Emotes" && data.roles.includes("6076a86b09a4c63a38ebe801")) {
const personalEmotesData = await fetch7TVEmoteData(element.id);
return personalEmotesData;
if (emote_data && emote_data != null) {
fetchedEmoteSets[emote_set.id] = emote_data;

emoteData.push(...emote_data);
}
}
}

if (emoteData.length > 0) {
return emoteData;
}
}

return null;
return null;
} catch(error) {
return null;
}
}

async function getUser(user_id) {
async function getUser(user_id, twitch_user_id) {
try {
const response = await fetch('https://7tv.io/v3/gql', {
method: 'POST',
Expand All @@ -110,6 +126,8 @@ async function getUser(user_id) {

const data = await response.json();

console.log(data)

let infoTable = {
"lastUpdate": Date.now(),
"backgroundImage": null,
Expand Down Expand Up @@ -175,7 +193,7 @@ async function getUser(user_id) {
//Personal Emotes

try {
infoTable.personal_emotes = await getUserPersonalEmotes(user_id);
infoTable.personal_emotes = await getUserPersonalEmotes(twitch_user_id);
} catch (error) {
console.error('Error fetching personal emotes:', error);
}
Expand All @@ -191,7 +209,7 @@ async function loadPaint(user_id, textElement, userstate, sevenTVData) {
let data = null

if (sevenTVData == null || sevenTVData.length < 1) {
data = await getUser(user_id)
data = await getUser(user_id, userstate["user-id"] || userstate["userId"] || "1")
} else {
data = sevenTVData
}
Expand Down

0 comments on commit 034b15b

Please sign in to comment.