From 5a4002e7d4518fb9bc98b68de516c10fa3118cf4 Mon Sep 17 00:00:00 2001 From: GingerPlusPlus Date: Fri, 24 Nov 2017 12:31:47 +0100 Subject: [PATCH] Don't assume config file extension Even if we want to enforce one extension, doing it in requires scattered across the whole project doesn't sound like a good idea (don't repeat yourself). This commit also enables .js configs, so I added that to .gitignore. I'll document it when we settle on default config format. Why was .json everywhere in the first place? I thought it was neccessary in some older versions of Node to be able to require a .json file. --- .gitignore | 3 ++- bot/index.js | 2 +- handlers/commands/groups.js | 2 +- handlers/commands/index.js | 2 +- handlers/commands/unwarn.js | 2 +- handlers/commands/warn.js | 2 +- handlers/messages/addUser.js | 2 +- handlers/messages/removeLinks.js | 2 +- handlers/middlewares/addedToGroup.js | 2 +- handlers/middlewares/removeCommands.js | 2 +- plugins/index.js | 2 +- 11 files changed, 12 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 7ad2c7c..155f90b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ node_modules data/ config.json +config.js .env -.idea/ \ No newline at end of file +.idea/ diff --git a/bot/index.js b/bot/index.js index 9b176b6..7287650 100644 --- a/bot/index.js +++ b/bot/index.js @@ -1,7 +1,7 @@ 'use strict'; const Telegraf = require('telegraf'); -const config = require('../config.json'); +const config = require('../config'); const bot = new Telegraf(config.token); diff --git a/handlers/commands/groups.js b/handlers/commands/groups.js index 461121a..0d34ca1 100644 --- a/handlers/commands/groups.js +++ b/handlers/commands/groups.js @@ -6,7 +6,7 @@ const { escapeHtml, scheduleDeletion } = require('../../utils/tg'); // DB const { listGroups } = require('../../stores/group'); -const config = require('../../config.json'); +const config = require('../../config'); const inline_keyboard = config.groupsInlineKeyboard; diff --git a/handlers/commands/index.js b/handlers/commands/index.js index 01bc7cf..7f9d4d5 100644 --- a/handlers/commands/index.js +++ b/handlers/commands/index.js @@ -22,7 +22,7 @@ const addCommandHandler = require('./addCommand'); const removeCommandHandler = require('./removeCommand'); const helpHandler = require('./help'); -let { deleteCommands } = require('../../config.json'); +let { deleteCommands } = require('../../config'); if (typeof deleteCommands === 'undefined') { deleteCommands = 'own'; diff --git a/handlers/commands/unwarn.js b/handlers/commands/unwarn.js index 25f1031..ae9ff92 100644 --- a/handlers/commands/unwarn.js +++ b/handlers/commands/unwarn.js @@ -4,7 +4,7 @@ const { link, scheduleDeletion } = require('../../utils/tg'); // Config -const { numberOfWarnsToBan } = require('../../config.json'); +const { numberOfWarnsToBan } = require('../../config'); // Bot const { replyOptions } = require('../../bot/options'); diff --git a/handlers/commands/warn.js b/handlers/commands/warn.js index 665ec51..e37552b 100644 --- a/handlers/commands/warn.js +++ b/handlers/commands/warn.js @@ -8,7 +8,7 @@ const { logError } = require('../../utils/log'); const { numberOfWarnsToBan, warnInlineKeyboard, -} = require('../../config.json'); +} = require('../../config'); const reply_markup = { inline_keyboard: warnInlineKeyboard }; // Bot diff --git a/handlers/messages/addUser.js b/handlers/messages/addUser.js index a7420b7..85c0d29 100644 --- a/handlers/messages/addUser.js +++ b/handlers/messages/addUser.js @@ -1,7 +1,7 @@ 'use strict'; // Config -const { master } = require('../../config.json'); +const { master } = require('../../config'); // DB const { addUser, isUser } = require('../../stores/user'); diff --git a/handlers/messages/removeLinks.js b/handlers/messages/removeLinks.js index 9323c10..07ecf3d 100644 --- a/handlers/messages/removeLinks.js +++ b/handlers/messages/removeLinks.js @@ -9,7 +9,7 @@ const { excludeLinks, numberOfWarnsToBan, warnInlineKeyboard, -} = require('../../config.json'); +} = require('../../config'); const reply_markup = { inline_keyboard: warnInlineKeyboard }; diff --git a/handlers/middlewares/addedToGroup.js b/handlers/middlewares/addedToGroup.js index f29b40a..66d29d1 100644 --- a/handlers/middlewares/addedToGroup.js +++ b/handlers/middlewares/addedToGroup.js @@ -5,7 +5,7 @@ const { replyOptions } = require('../../bot/options'); const { admin } = require('../../stores/user'); const { addGroup, managesGroup } = require('../../stores/group'); -const { master } = require('../../config.json'); +const { master } = require('../../config'); const addedToGroupHandler = async (ctx, next) => { const msg = ctx.message; diff --git a/handlers/middlewares/removeCommands.js b/handlers/middlewares/removeCommands.js index f7c56b6..eca4b12 100644 --- a/handlers/middlewares/removeCommands.js +++ b/handlers/middlewares/removeCommands.js @@ -1,6 +1,6 @@ 'use strict'; -const { deleteCommands } = require('../../config.json'); +const { deleteCommands } = require('../../config'); const noop = Function.prototype; diff --git a/plugins/index.js b/plugins/index.js index 623be72..2ded51d 100644 --- a/plugins/index.js +++ b/plugins/index.js @@ -2,7 +2,7 @@ const { compose } = require('telegraf'); -const config = require('../config.json'); +const config = require('../config'); const names = config.plugins || []; const plugins = names.map(name => `./${name}`).map(require);