Browse Source
Implemented a working Giphy module
Implemented a working Giphy module
* Added example required config * Refactored config tools for more generic config loading * Added NODE_PATH to entrypoint.sh * NODE_PATH environment variable is now required to run Baphoment-JS * Added Axios library * Added config handling to AbstractModule and init process * Added basic working Giphy modulepull/10/head
Drew Short
5 years ago
11 changed files with 140 additions and 35 deletions
-
25bot/config.js
-
15bot/engine.js
-
35bot/module/abstract.js
-
2bot/module/admin.js
-
29bot/module/giphy.js
-
4data/giphy-config.json.example
-
3entrypoint.sh
-
2index.js
-
47package-lock.json
-
1package.json
@ -1,22 +1,25 @@ |
|||
let { logger } = require('./logging'); |
|||
|
|||
var configPath = null; |
|||
var config = null; |
|||
let loadedConfigs = new Map(); |
|||
|
|||
function sanitizeConfig(config) { |
|||
function sanitizeConfig(config, fields=[]) { |
|||
let clonedConfig = { ...config }; |
|||
clonedConfig.accessToken = "******" |
|||
fields.forEach((field) => { |
|||
clonedConfig[field] = '******' |
|||
}) |
|||
return clonedConfig; |
|||
} |
|||
|
|||
function getConfig(configFile) { |
|||
if (config === null) { |
|||
configPath = configFile; |
|||
config = require(configFile); |
|||
logger.info("Loaded config:"); |
|||
logger.debug("%o", sanitizeConfig(config)); |
|||
} |
|||
function getConfig(configFile, sanitizedFields=[]) { |
|||
if (!loadedConfigs.has(configFile)) { |
|||
let config = require(configFile); |
|||
logger.info("Loaded config: %s", configFile); |
|||
logger.debug("%o", sanitizeConfig(config, sanitizedFields)); |
|||
loadedConfigs.set(configFile, config); |
|||
return config; |
|||
} else { |
|||
return loadedConfigs.get(configFile); |
|||
} |
|||
} |
|||
|
|||
exports.getConfig = getConfig |
@ -0,0 +1,4 @@ |
|||
{ |
|||
"endpoint": "api.giphy.com/v1", |
|||
"apiKey": "<Your API Key Here>" |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue