<commit_before>'use strict';
const router = require('express').Router(); // eslint-disable-line new-cap
const uptime = require('../bin/uptime');
const games = require('../bin/lastGames');
const googleSheet = require('../bin/googleSheet');
const moment = require('moment');
const log = require('winston');
const liveSubs = require('../bin/liveSubs');
const raidmode = require('../bin/raidmode');
const report = require('../bin/report');
const status = require('../bin/status');
const request = require('node-fetch');
const config = require('../config');
const { get } = require('lodash');
require('moment-timezone');

router.get('/uptime', (req, res, next) => { // eslint-disable-line no-unused-vars
  res.send(uptime.getUptime());
});

router.get('/timestamp', (req, res, next) => { // eslint-disable-line no-unused-vars
  res.send(uptime.getTimestamp());
});

router.get('/song', (req, res, next) => {
  request(
    `http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&limit=2&user=annemunition&api_key=${
      config.lastfm.apiKey
      }&format=json`,
  )
    .then(res => res.json())
    .then(data => {
      const tracks = get(data, 'recenttracks.track', null)
      if (!tracks) return res.status(200).send('Unable to get tracks.')
      const nowPlaying = tracks.find(track =>
        get(track, '@attr.nowplaying', null),
      )
      if (!nowPlaying) res.status(200).send('No song is currently playing.')
      const str = `${get(nowPlaying, 'name', 'Track')} by ${get(
        nowPlaying,
        'artist.#text',
        'Artist',
      )}`
      res.status(200).send(str)
    })
    .catch(() => {
      res.status(200).send('LastFM Error');
    });
})

router.get('/games', (req, res, next) => { // eslint-disable-line no-unused-vars
  req.db.Games.find({}).sort({ _id: -1 })
    .then(gameResults => {
      if (gameResults.length > 0) {
        res.send(`The last played games are: ${gameResults.map(g => games.mutateName(g.name)).join(' | ')}`);
      } else {
        res.send('No games have been saved.');
      }
    })
    .catch(() => {
      res.sendStatus(503);
    });
});

router.get('/highlight', (req, res) => {
  const query = req.query.q || '';
  const user = req.query.u || '';
  googleSheet.saveHighlight(query, user)
    .then(response => {
      res.send(response);
    })
    .catch(err => {
      log.error(err);
      res.send('There was an error saving that moment. BibleThump');
    });
});

router.get('/latestSub', (req, res, next) => { // eslint-disable-line no-unused-vars
  res.render('latestSub');
});

router.get('/latestTip', (req, res, next) => { // eslint-disable-line no-unused-vars
  res.render('latestTip');
});

router.get('/latestCheer', (req, res, next) => { // eslint-disable-line no-unused-vars
  res.render('latestCheer');
});

router.get('/time', (req, res, next) => { // eslint-disable-line no-unused-vars
  res.send(`Anne's clock reads: ${moment.tz('America/Los_Angeles').format('ddd, h:mma zz')}`);
});

router.get('/getLiveSubs', (req, res, next) => { // eslint-disable-line no-unused-vars
  res.setHeader('Access-Control-Allow-Origin', '*');
  res.json(liveSubs.getCurrentlyLive());
});

router.get('/getLiveSubsCount', (req, res, next) => { // eslint-disable-line no-unused-vars
  res.send(liveSubs.getCurrentlyLive().length.toString());
});

router.get('/whatNow', async (req, res, next) => { // eslint-disable-line no-unused-vars
  const countRecord = await req.db.Counts.findOne({ name: 'liveSubs' });
  const oldCount = countRecord ? countRecord.count : 0;
  const currentCount = liveSubs.getCurrentlyLive().length;
  let str;
  if (currentCount > oldCount) {
    str = `${currentCount} of Anne's subscribers are currently live. ` +
      `Find out who at: http://annemunition.tv/armory NEW RECORD! PogChamp`;
    if (countRecord) {
      countRecord.count = currentCount;
      countRecord.save();
    } else {
      const newCount = new req.db.Counts({
        name: 'liveSubs',
        count: currentCount,
      });
      newCount.save();
    }
  } else {
    str = `${currentCount} of Anne's subscribers are currently live. Find out who at: http://annemunition.tv/armory`;
  }
  res.send(str);
});

router.get('/liveSubs', (req, res, next) => { // eslint-disable-line no-unused-vars
  res.render('liveSubs', {});
});

router.get('/allCleared', async (req, res, next) => { // eslint-disable-line no-unused-vars
  const tips = await req.db.Tips.count({ cleared: false });
  const subs = await req.db.Subscriptions.count({ cleared: false });
  const cheers = await req.db.Cheers.count({ cleared: false });
  res.json((tips + subs + cheers) === 0);
});

// Report a user on Twitch
router.get('/report/:name', async (req, res) => {
  // Extract the username
  const name = req.params.name.toLowerCase();
  // Send the user to the twitch report page right away<commit_msg>url to https<commit_after>'use strict';
const router = require('express').Router(); // eslint-disable-line new-cap
const uptime = require('../bin/uptime');
const games = require('../bin/lastGames');
const googleSheet = require('../bin/googleSheet');
const moment = require('moment');
const log = require('winston');
const liveSubs = require('../bin/liveSubs');
const raidmode = require('../bin/raidmode');
const report = require('../bin/report');
const status = require('../bin/status');
const request = require('node-fetch');
const config = require('../config');
const { get } = require('lodash');
require('moment-timezone');

router.get('/uptime', (req, res, next) => { // eslint-disable-line no-unused-vars
  res.send(uptime.getUptime());
});

router.get('/timestamp', (req, res, next) => { // eslint-disable-line no-unused-vars
  res.send(uptime.getTimestamp());
});

router.get('/song', (req, res, next) => {
  request(
    `http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&limit=2&user=annemunition&api_key=${
      config.lastfm.apiKey
      }&format=json`,
  )
    .then(res => res.json())
    .then(data => {
      const tracks = get(data, 'recenttracks.track', null)
      if (!tracks) return res.status(200).send('Unable to get tracks.')
      const nowPlaying = tracks.find(track =>
        get(track, '@attr.nowplaying', null),
      )
      if (!nowPlaying) res.status(200).send('No song is currently playing.')
      const str = `${get(nowPlaying, 'name', 'Track')} by ${get(
        nowPlaying,
        'artist.#text',
        'Artist',
      )}`
      res.status(200).send(str)
    })
    .catch(() => {
      res.status(200).send('LastFM Error');
    });
})

router.get('/games', (req, res, next) => { // eslint-disable-line no-unused-vars
  req.db.Games.find({}).sort({ _id: -1 })
    .then(gameResults => {
      if (gameResults.length > 0) {
        res.send(`The last played games are: ${gameResults.map(g => games.mutateName(g.name)).join(' | ')}`);
      } else {
        res.send('No games have been saved.');
      }
    })
    .catch(() => {
      res.sendStatus(503);
    });
});

router.get('/highlight', (req, res) => {
  const query = req.query.q || '';
  const user = req.query.u || '';
  googleSheet.saveHighlight(query, user)
    .then(response => {
      res.send(response);
    })
    .catch(err => {
      log.error(err);
      res.send('There was an error saving that moment. BibleThump');
    });
});

router.get('/latestSub', (req, res, next) => { // eslint-disable-line no-unused-vars
  res.render('latestSub');
});

router.get('/latestTip', (req, res, next) => { // eslint-disable-line no-unused-vars
  res.render('latestTip');
});

router.get('/latestCheer', (req, res, next) => { // eslint-disable-line no-unused-vars
  res.render('latestCheer');
});

router.get('/time', (req, res, next) => { // eslint-disable-line no-unused-vars
  res.send(`Anne's clock reads: ${moment.tz('America/Los_Angeles').format('ddd, h:mma zz')}`);
});

router.get('/getLiveSubs', (req, res, next) => { // eslint-disable-line no-unused-vars
  res.setHeader('Access-Control-Allow-Origin', '*');
  res.json(liveSubs.getCurrentlyLive());
});

router.get('/getLiveSubsCount', (req, res, next) => { // eslint-disable-line no-unused-vars
  res.send(liveSubs.getCurrentlyLive().length.toString());
});

router.get('/whatNow', async (req, res, next) => { // eslint-disable-line no-unused-vars
  const countRecord = await req.db.Counts.findOne({ name: 'liveSubs' });
  const oldCount = countRecord ? countRecord.count : 0;
  const currentCount = liveSubs.getCurrentlyLive().length;
  let str;
  if (currentCount > oldCount) {
    str = `${currentCount} of Anne's subscribers are currently live. ` +
      `Find out who at: http://annemunition.tv/armory NEW RECORD! PogChamp`;
    if (countRecord) {
      countRecord.count = currentCount;
      countRecord.save();
    } else {
      const newCount = new req.db.Counts({
        name: 'liveSubs',
        count: currentCount,
      });
      newCount.save();
    }
  } else {
    str = `${currentCount} of Anne's subscribers are currently live. Find out who at: https://annemunition.tv/armory`;
  }
  res.send(str);
});

router.get('/liveSubs', (req, res, next) => { // eslint-disable-line no-unused-vars
  res.render('liveSubs', {});
});

router.get('/allCleared', async (req, res, next) => { // eslint-disable-line no-unused-vars
  const tips = await req.db.Tips.count({ cleared: false });
  const subs = await req.db.Subscriptions.count({ cleared: false });
  const cheers = await req.db.Cheers.count({ cleared: false });
  res.json((tips + subs + cheers) === 0);
});

// Report a user on Twitch
router.get('/report/:name', async (req, res) => {
  // Extract the username
  const name = req.params.name.toLowerCase();
  // Send the user to the twitch report page right away
{'fraction_non_alphanumeric': 0.19765045342126958, 'fraction_numerical': 0.004534212695795548, 'mean_word_length': 3.3657219973009447, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 55, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1254458', 'n_tokens_mistral': 3289, 'n_tokens_neox': 3242, 'n_words': 681}