Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const axios = require('axios');
- const config = require('../../config.json');
- const PROFILE_PREFIX = 'https://www.margonem.pl/?task=profile&id=';
- class MargoParser {
- static verifyLink(link) {
- if (!link.startsWith(PROFILE_PREFIX)) {
- return false;
- }
- const id = link.substr(PROFILE_PREFIX.length);
- if (isNaN(Number(id))) {
- return false;
- }
- return true;
- }
- static getIdFromLink(link) {
- return Number(link.substr(PROFILE_PREFIX.length));
- }
- static async getProfileContent(profileId) {
- try {
- const response = await axios.get(`https://www.margonem.pl/?task=profile&id=${profileId}&t=${Math.random()}`);
- return response.data;
- } catch {
- return '';
- }
- }
- static getNick(profileContent) {
- const prefix = '<p id="nick" tip="';
- const suffix = '">';
- try {
- const result = profileContent.split(prefix)[1].split(suffix)[0];
- return result;
- } catch {
- return '';
- }
- }
- static async hasPosts(forumNick) {
- try {
- const request = await axios.request({
- url: 'https://www.margonem.pl/',
- method: 'get',
- headers: { Cookie: config.cookies },
- params: { task: 'forum', show: 'found', cat: '17', onlycat: 'on', playerposts: 'Szukaj postów gracza', kw: forumNick }
- });
- const prefix = '<table id=posts>';
- const suffix = '</table>';
- const result = request.data.split(prefix)[1].split(suffix)[0].split('<div class="pavatar_new">').length;
- return result > 15;
- } catch {
- return false;
- }
- }
- }
- module.exports = MargoParser;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement