Skip to content

Commit d3cafee

Browse files
committed
7TV and Pronouns
1. Added pronouns to usercards 2. Added updated 7TV cosmetics to the more menu in chatbox 3. The 7TV EventSub webscocket gets notified each 5 minutes and when the user joins the chat
1 parent 5cb8135 commit d3cafee

6 files changed

Lines changed: 63 additions & 3 deletions

File tree

pages/channel.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
<li>Reconnect to chat</li>
127127
<li>Reload emotes</li>
128128
<li>Reload subcriber emotes</li>
129+
<li>Update 7TV cosmetics</li>
129130
</ul>
130131
</div>
131132
</button>

src/channel/SevenTVCosmetics.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ async function updateCosmetics(body) {
108108

109109
cosmetics.paints.push(push)
110110
}
111-
} else if (body.object.name == "Personal Emote Set" || body.object.name == "Personal Emotes" || body.object.user || body.object.id === "00000000000000000000000000" || (body.object.flags && body.object.flags === 11)) {
111+
} else if (body.object.flags && (body.object.flags === 4 || body.object.flags === 11) || body.object.kind && body.object.kind == "EMOTE_SET") {
112112
if (body.object.id === "00000000000000000000000000" && body.object.ref_id) {
113113
body.object.id = body.object.ref_id
114114
}

src/channel/index.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const commands = [
3838
]
3939
let rateLimitRemaining = Infinity;
4040
let rateLimitReset = 0;
41+
let pronouns_data = [];
4142

4243
//TMI
4344
let tmiUsername = 'none';
@@ -886,7 +887,7 @@ async function replaceWithEmotes(inputString, TTVMessageEmoteData, userstate, ch
886887
for (let i = 0; i < replacedParts.length; i++) {
887888
let part = replacedParts[i];
888889

889-
if (part.startsWith("@") && part.length > 2 && part.length <= 25 ) {
890+
if (part.startsWith("@") && part.length > 2 && part.length <= 25) {
890891
const username = part.replace('@', '');
891892

892893
if (/^[A-Za-z0-9_]+$/.test(username)) {
@@ -1623,6 +1624,13 @@ async function pushUserData(userData) {
16231624
};
16241625

16251626
TTVUsersData.push(user);
1627+
1628+
if (user7TV_id) {
1629+
notifyWebSocket(user7TV_id, channelTwitchID);
1630+
setInterval(() => {
1631+
notifyWebSocket(user7TV_id, channelTwitchID);
1632+
}, 300000);
1633+
}
16261634
} catch (error) {
16271635
console.error(error)
16281636
}
@@ -1681,6 +1689,7 @@ async function connectTmi() {
16811689

16821690
async function Load() {
16831691
loadCustomBadges();
1692+
getPronous();
16841693

16851694
try {
16861695
getAllTLDs();
@@ -1821,6 +1830,18 @@ async function Load() {
18211830
}
18221831

18231832
// No token needed
1833+
async function getPronous() {
1834+
const response = await fetch(`https://pronouns.alejo.io/api/pronouns`);
1835+
1836+
if (!response.ok) {
1837+
debugChange("pronouns.alejo.io", "pronouns_data", false);
1838+
return;
1839+
}
1840+
1841+
debugChange("pronouns.alejo.io", "pronouns_data", true);
1842+
1843+
pronouns_data = await response.json();
1844+
}
18241845

18251846
async function getRedeems() {
18261847
const GQLbody = `

src/channel/userCard.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,22 @@ async function openCard(username) {
100100
</div>`
101101
}
102102

103+
const pronouns_response = await fetch(`https://pronouns.alejo.io/api/users/${userInfo["login"]}`);
104+
105+
if (pronouns_response.ok) {
106+
const data = await pronouns_response.json();
107+
108+
if (data && data?.[0]?.["pronoun_id"]) {
109+
const found_pronoun = pronouns_data.find(item => item.name === data?.[0]?.["pronoun_id"]);
110+
111+
if (found_pronoun) {
112+
user_info.innerHTML += `Pronouns: ${found_pronoun["display"]}`
113+
}
114+
}
115+
116+
debugChange("pronouns.alejo.io", "user_pronouns", true);
117+
}
118+
103119
if (userInfo["id"]) {
104120
const paintName = await getPaintName(userInfo["id"]);
105121

src/debug.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,14 @@ const debugInfo = {
6666
tiles: [
6767
"badges_gists"
6868
],
69-
}
69+
},
70+
PRONOUNS: {
71+
name: 'pronouns.alejo.io',
72+
tiles: [
73+
"pronouns_data",
74+
"user_pronouns"
75+
],
76+
},
7077
};
7178

7279
function displayDebug() {

src/events.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,21 @@ dropdownItems.forEach((item) => {
267267
} else {
268268
await handleMessage(custom_userstate.Server, 'Failed reloading subscriber emotes: Not logged in.');
269269
}
270+
} else if (option_selected == "update 7tv cosmetics") {
271+
await handleMessage(custom_userstate.Server, 'Trying to notify the 7TV EventSub websocket.');
272+
273+
const foundUser = TTVUsersData.find(user => user.name === `@${tmiUsername}`);
274+
275+
if (foundUser) {
276+
if (foundUser.cosmetics && foundUser.cosmetics.user_id) {
277+
notifyWebSocket(foundUser.cosmetics.user_id, channelTwitchID);
278+
await handleMessage(custom_userstate.Server, 'Notified the 7TV EventSub websocket.');
279+
} else {
280+
await handleMessage(custom_userstate.Server, `Failed to notify the 7TV EventSub websocket, there is no 7TV userId for ${tmiUsername}.`);
281+
}
282+
} else {
283+
await handleMessage(custom_userstate.Server, `Failed to notify the 7TV EventSub websocket, ${tmiUsername} was not found in user data.`);
284+
}
270285
}
271286
});
272287
});

0 commit comments

Comments
 (0)