Skip to content

Commit

Permalink
Add validateToken to Utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
dxnter committed Oct 26, 2020
1 parent 5206929 commit 907f685
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
7 changes: 3 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import lastyClient from './structures/Client';
import { CronJob } from 'cron';
import './db';
import validateToken from './utils/validateToken';
import Utilities from './structures/Utilities';
import weeklyStatCron from './utils/weeklyStatCron';
import { EMBED_COLOR } from '../config.json';
import './db';
import { EMBED_COLOR, LASTFM_API_KEY } from '../config.json';

validateToken();
Utilities.validateToken(LASTFM_API_KEY);
Utilities.validateEmbedColor(EMBED_COLOR);

const client = new lastyClient();
Expand Down
10 changes: 10 additions & 0 deletions src/structures/Utilities.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { MessageEmbed } from 'discord.js';
import chalk from 'chalk';
import db from '../db';
import { isValidToken } from '../api/lastfm';
import {
ERROR,
SUCCESS,
Expand Down Expand Up @@ -67,6 +68,15 @@ export default class Utilities {
return `${word}'s`;
}

static async validateToken(apiKey) {
if (!(await isValidToken(apiKey))) {
console.log(chalk`{red.bold [Error] Invalid Last.fm API Key. Visit the link below for a key.\n}
{white https://www.last.fm/api/account/create​}
`);
process.exit(0);
}
}

static validateEmbedColor(hexCode) {
const regex = /^#([\da-f]{3}){1,2}$|^#([\da-f]{4}){1,2}$/i;
if (hexCode && regex.test(hexCode)) {
Expand Down
12 changes: 0 additions & 12 deletions src/utils/validateToken.js

This file was deleted.

0 comments on commit 907f685

Please sign in to comment.