UNPKG

technolist

Version:

Un módulo NPM para obtener datos de TechnoList

54 lines (48 loc) 2.71 kB
const TechnoError = require('./TechnoError'); const fetch = require('node-fetch'); class TechnoList { constructor() { throw new TechnoError(`No puedes instanciar la clase ${this.constructor.name}`); } static async getBot(botID) { if(!['string', 'number'].includes(typeof(botID))) throw new TechnoError('Debes añadir la ID del bot.'); if(!parseInt(botID) || isNaN(botID)) throw new TechnoError('La ID debe ser un número.'); if(![16, 17, 18].includes(`${botID}`.length)) throw new TechnoError('Debes añadir una ID válida'); let request = await fetch(`https://technokite.glitch.me/bots/bot/${botID}`); let url = await request.url; request = await request.text(); if(url != `https://technokite.glitch.me/bots/bot/${botID}`) throw new TechnoError('Esta ID no coincide con la de ningún bot en la lista.'); let tags = []; let tagshtml = request.split('<div class="tags-list">')[1].split('</div>')[0].split('<a class="etiqueta"') tagshtml.shift(); tagshtml.forEach((data) => { return tags.push(data.split('">')[1].split('</a>')[0]) }); let links = []; let linkshtml = request.split('<div class="links">')[1].split('</div>')[0].split('<a href="') linkshtml.shift(); linkshtml.forEach((data) => { const name = data.split('">')[1].split('</a>')[0]; const url = data.split('">')[0].split('" target="')[0]; return links.push({ name: name, url: url }); }); let data = { bot: { name: request.split('class="nombre">')[1].split('</h2')[0], avatar: request.split('img class="avatar" src="')[1].split('">')[0].replace('.webp', '.png')+'?size=4096', id: request.split('img class="avatar" src="')[1].split('">')[0].split('/')[4] }, prefix: request.split('class="markdown">')[1].split('</span')[0], owner: { name: request.split('<a class="creador"')[1].split('<p>')[1].split('</p>')[0], avatar: request.split('<a class="creador"')[1].split('<img src="')[1].split('">')[0]+'?size=4096', id: request.split('<a class="creador"')[1].split('<img src="')[1].split('">')[0].split('/')[4] }, description: request.split('<p class="desc">')[1].split('</p>')[0].trim().replace(/&#34;/g, '"').replace(/&gt;/g, '>').replace(/&lt;/g, '<').replace(/ /gm, '').replace(/<br>/g, '\n'), tags: tags, links: links } return data; } } module.exports = TechnoList;