SHARE
TWEET

Untitled

a guest Jan 18th, 2020 87 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const { Command, Stopwatch } = require('klasa');
  2. const fetch = require('node-fetch');
  3. const { MessageEmbed } = require('discord.js');
  4.  
  5. const PLATFORMS = {
  6.     youtube: id => `https://www.youtube.com/watch?v=${id}`,
  7.     mixer: id => `https://mixer.com/${id}`,
  8.     twitch: id => `https://www.twitch.tv/${id}`,
  9.     dlive: id => `http://dlive.tv/${id}`
  10. };
  11.  
  12. module.exports = class extends Command {
  13.  
  14.     constructor(...args) {
  15.         super(...args, {
  16.             cooldown: 60,
  17.             description: 'show who is online on cx network',
  18.             aliases: ['live', 'streamers'],
  19.             cooldownLevel: 'channel'
  20.         });
  21.  
  22.         this.bypassOnlyStaff = true;
  23.     }
  24.  
  25.     async run(msg) {
  26.         const stopwatch = new Stopwatch();
  27.         const online = await fetch(
  28.             'https://api.streampage.io/v2/site/iceposeidon.com/sources/streamers'
  29.         )
  30.             .then(response => response.json())
  31.             .then(res => res.streamers.filter(str => str.isLive).sort(() => Math.random() - 0.5))
  32.             .catch(err => {
  33.                 throw err;
  34.             });
  35.  
  36.         const totalViewers = online.reduce((a, b) => a + b.live.viewers, 0);
  37.         const list = online
  38.             .map(str => `[${str.name} - ${str.live.viewers} Viewers](${this.getLink(str.live)})`)
  39.             .join('\n');
  40.  
  41.         const embed = new MessageEmbed()
  42.             .setTitle(`${totalViewers} Watching Now`)
  43.             .setColor(6570404)
  44.             .setDescription(list)
  45.             .setFooter(stopwatch.stop());
  46.  
  47.         return msg.send({ embed });
  48.     }
  49.  
  50.     getLink({ streamId, type }) {
  51.         if (!PLATFORMS[type]) return '#';
  52.  
  53.         return PLATFORMS[type](streamId);
  54.     }
  55.  
  56. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top