Advertisement
Guest User

Untitled

a guest
Mar 19th, 2020
431
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const axios = require('axios');
  2. const config = require('../../config.json');
  3. const PROFILE_PREFIX = 'https://www.margonem.pl/?task=profile&id=';
  4.  
  5. class MargoParser {
  6.     static verifyLink(link) {
  7.         if (!link.startsWith(PROFILE_PREFIX)) {
  8.             return false;
  9.         }
  10.  
  11.         const id = link.substr(PROFILE_PREFIX.length);
  12.         if (isNaN(Number(id))) {
  13.             return false;
  14.         }
  15.  
  16.         return true;
  17.     }
  18.  
  19.     static getIdFromLink(link) {
  20.         return Number(link.substr(PROFILE_PREFIX.length));
  21.     }
  22.  
  23.     static async getProfileContent(profileId) {
  24.         try {
  25.             const response = await axios.get(`https://www.margonem.pl/?task=profile&id=${profileId}&t=${Math.random()}`);
  26.             return response.data;
  27.         } catch {
  28.             return '';
  29.         }
  30.     }
  31.  
  32.     static getNick(profileContent) {
  33.         const prefix = '<p id="nick" tip="';
  34.         const suffix = '">';
  35.  
  36.         try {
  37.             const result = profileContent.split(prefix)[1].split(suffix)[0];
  38.             return result;
  39.         } catch {
  40.             return '';
  41.         }
  42.     }
  43.  
  44.     static async hasPosts(forumNick) {
  45.         try {
  46.             const request = await axios.request({
  47.                 url: 'https://www.margonem.pl/',
  48.                 method: 'get',
  49.                 headers: { Cookie: config.cookies },
  50.                 params: { task: 'forum', show: 'found', cat: '17', onlycat: 'on', playerposts: 'Szukaj postów gracza', kw: forumNick }
  51.             });
  52.  
  53.             const prefix = '<table id=posts>';
  54.             const suffix = '</table>';
  55.             const result = request.data.split(prefix)[1].split(suffix)[0].split('<div class="pavatar_new">').length;
  56.  
  57.             return result > 15;
  58.         } catch {
  59.             return false;
  60.         }
  61.     }
  62. }
  63.  
  64. module.exports = MargoParser;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement