Skip to content

Commit

Permalink
fix logger field
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiTenno committed Feb 10, 2021
1 parent 83e2c97 commit 504624b
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 16 deletions.
12 changes: 6 additions & 6 deletions src/Logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,20 @@ const scopes = {
* @property {function} fatal - Logs a fatal message. The program should terminate after such
* an error
*/
class Logger {
isLoggable(level) {
return Object.keys(levels).indexOf(level.toUpperCase()) >= Object.keys(levels).indexOf(l.logLevel)
}
}
class Logger {}

const colorify = (level, map) => level[map[level] || 'red'];
const fmt = (level, msg) => `[${colorify(scope, scopes)}] ${(colorify(level, levels) || 'ukn').toLowerCase()}: ${msg}`;

Logger.prototype.isLoggable = (level) => {
return Object.keys(levels).indexOf(level.toUpperCase()) >= Object.keys(levels).indexOf(l.logLevel);
}

Object.keys(levels).forEach((level) => {
Logger.prototype[level.toLowerCase()] = (message) => {
const simple = fmt(level, message);
const nonError = Object.keys(levels).indexOf(level) < Object.keys(levels).indexOf('ERROR');
if (this.isLoggable(level) && nonError) {
if (Logger.prototype.isLoggable(level) && nonError) {
console.log(simple);
}

Expand Down
2 changes: 1 addition & 1 deletion src/commands/Settings/AllowCustomCommands.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class AllowCustomCommands extends Command {
constructor(bot) {
super(bot, 'settings.allowCustom', 'allow custom commands', 'Toggle whether or not custom commands are allowed here.', 'CUST_CMDS');
this.usages = [
{ description: 'Change if this channel can use custom commands', parameters: ['custom commands enabled'] },
{ description: 'Change if this channel can use custom commands', parameters: ['on', 'off'] },
];
this.regex = new RegExp('^allow\\s?custom(?:\\s?commands)?\\s?(on|off)?(?:\\s+in\\s+((?:\\<\\#)?\\d+(?:\\>)?|here))?$', 'i');
this.requiresAuth = true;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/Settings/AllowInlineCommands.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class AllowInlineCommands extends Command {
constructor(bot) {
super(bot, 'settings.allowinline', 'allow inline commands', 'Toggle whether or not inline commands are allowed here.', 'CMD_MGMT');
this.usages = [
{ description: 'Change if this channel can use inline commands', parameters: ['inline commands enabled'] },
{ description: 'Change if this channel can use inline commands', parameters: ['on', 'off'] },
];
this.regex = new RegExp('^allow\\s?inline(?:\\s?commands)?\\s?(on|off)?(?:\\s+in\\s+((?:\\<\\#)?\\d+(?:\\>)?|here))?$', 'i');
this.requiresAuth = true;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/Settings/DeleteAfterRespond.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class RespondToSettings extends Command {
constructor(bot) {
super(bot, 'settings.deleteafterrespond', 'delete after respond', 'Set whether or not to allow the bot to delete commands and/or responses after responding.', 'CMD_MGMT');
this.usages = [
{ description: 'Change if the bot to delete commands and/or responses after responding in this channel', parameters: ['deleting enabled'] },
{ description: 'Change if the bot to delete commands and/or responses after responding in this channel', parameters: ['all', 'command', 'respond', 'none'] },
];
this.regex = new RegExp('^delete\\s?after\\s?respond\\s?(all|command|respond|none)?(?:\\s+in\\s+((?:\\<\\#)?\\d+(?:\\>)?|here))?$', 'i');
this.requiresAuth = true;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/Settings/Language.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Language extends Command {
constructor(bot) {
super(bot, 'settings.language', 'language', 'Set the channel\'s language', 'CORE');
this.usages = [
{ description: 'Change this channel\'s language', parameters: ['language'] },
{ description: 'Change this channel\'s language', parameters: languages, separator: '|'},
];
this.regex = new RegExp(`^${this.call}\\s?(${languages.join('|')})?(?:\\s+in\\s+(${captures.channel}|here))?$`, 'i');
this.requiresAuth = true;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/Settings/Platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Platform extends Command {
constructor(bot) {
super(bot, 'settings.platform', 'platform', 'Change a channel\'s platform', 'CORE');
this.usages = [
{ description: 'Change this channel\'s platform', parameters: ['platform'] },
{ description: 'Change this channel\'s platform', parameters: platforms, separator: '|' },
];
this.regex = new RegExp(`^${this.call}(?:\\s+(${platforms.join('|')}))?(?:\\s+in\\s+(${captures.channel}|here))?$`, 'i');
this.requiresAuth = true;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/Settings/RespondToSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class RespondToSettings extends Command {
constructor(bot) {
super(bot, 'settings.respondSettings', 'respond to settings', 'Toggle whether or not the bot tells you when settings change from your command.', 'CMD_MGMT');
this.usages = [
{ description: 'Change if this channel has settings changes responded in it', parameters: ['response enabled'] },
{ description: 'Change if this channel has settings changes responded in it', parameters: ['on', 'off'] },
];
this.regex = new RegExp(`^respond(?:\\sto)?\\s?settings\\s?(on|off)?(?:\\s+in\\s+(${captures.channel}|here))?$`, 'i');
this.requiresAuth = true;
Expand Down
6 changes: 2 additions & 4 deletions src/tools/generateManifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const fs = require('fs');
const path = require('path');
const BaseCommand = require('../models/Command');
const { games } = require('../CommonFunctions');
const logger = require('../Logger');

const generateManifest = async () => {
const commandDir = path.join(__dirname, '../commands');
Expand Down Expand Up @@ -43,10 +44,7 @@ const generateManifest = async () => {

try {
fs.writeFileSync('commands.json', JSON.stringify(commands), 'utf8');
if (['DEBUG', 'INFO'].some(str => str === process.env.LOG_LEVEL)) {
// eslint-disable-next-line no-console
console.log('[DEBUG] Wrote command manifest...');
}
logger.info('Wrote command manifest...');
} catch (e) {
// eslint-disable-next-line no-console
console.error(e);
Expand Down

0 comments on commit 504624b

Please sign in to comment.