0
Fork 0
mirror of https://codeberg.org/SafeTwitch/safetwitch-backend.git synced 2025-01-05 04:10:06 -05:00
safetwitch-backend/util/scraping/extractor/emoteHandler.ts
2023-04-29 23:09:53 -04:00

53 lines
No EOL
1.2 KiB
TypeScript

import { Urls, bttvData, ffzData } from "../../../types/scraping/emotes"
interface Emote {
name: string
urls: Urls
}
export const ffzEmotesHandler = (emoteData: ffzData) => {
const sets = emoteData.sets[emoteData.room.set]
const emotes: Emote[] = []
for (let emote of sets.emoticons) {
const data: Emote = {
name: emote.name,
urls: emote.urls
}
emotes.push(data)
}
return emotes
}
const generateBttvEmoteUrls = (id: string) => {
const bttvApi = 'https://cdn.betterttv.net/emote/'
const urls: Urls = {}
// Creates urls like "https://cdn.betterttv.net/emote/6368b11b9013520589f5ac0c/3x" from 1x to 3x
for (let i = 1; i < 4; i++) {
urls[i] = `${bttvApi}${id}/${i}x`
}
return urls
}
export const bttvEmotesHandler = (emoteData: bttvData) => {
const rawEmoteArray = emoteData
console.log(emoteData.length)
const emotes: Emote[] = []
for (let rawEmote of rawEmoteArray) {
const formattedEmote: Emote = {
name: rawEmote.code,
urls: generateBttvEmoteUrls(rawEmote.id)
}
emotes.push(formattedEmote)
}
console.log(emotes.length)
console.log(emotes)
return emotes
}