tree-wide: make sources more bundler friendly

This commit is contained in:
liushuyu 2022-12-31 02:02:40 -07:00
parent e46432ac22
commit 4f8bf4574f
No known key found for this signature in database
GPG Key ID: 23D1CE4534419437
3 changed files with 20 additions and 10 deletions

View File

@ -1,6 +1,12 @@
import * as fs from 'fs'; import * as fs from 'fs';
import state from './state'; import state from './state';
import logger from './logging'; import logger from './logging';
import { IResponses } from './models/interfaces';
const responses: { [index: string]: IResponses } = {
citra: require('./responses/citra.json'),
yuzu: require('./responses/yuzu.json')
};
export function readWarnings () { export function readWarnings () {
// Load the warnings file into the application state. // Load the warnings file into the application state.
@ -32,12 +38,14 @@ export function readBans () {
export function readCustomResponses () { export function readCustomResponses () {
// Load the responses file into the responses variable. // Load the responses file into the responses variable.
try { if (process.env.TENANT) {
state.responses = require(`./responses/${process.env.TENANT}.json`); state.responses = responses[process.env.TENANT];
if (state.responses) {
logger.debug(`Loaded responses file for ${process.env.TENANT} from external source.`); logger.debug(`Loaded responses file for ${process.env.TENANT} from external source.`);
} catch (e) { return;
logger.error(`Failed to load ${process.env.TENANT}.json! Custom responses are disabled.`);
} }
}
logger.error(`Failed to load ${process.env.TENANT}.json! Custom responses are disabled.`);
} }
export function flushWarnings () { export function flushWarnings () {

View File

@ -1,6 +1,7 @@
import * as winston from 'winston'; import * as winston from 'winston';
import * as ip from 'ip'; import * as ip from 'ip';
import * as os from 'os'; import * as os from 'os';
import LogdnaWinston from 'logdna-winston';
const logger = winston.createLogger({ const logger = winston.createLogger({
level: 'debug', level: 'debug',
@ -18,10 +19,9 @@ const logger = winston.createLogger({
// Setup logging for LogDNA cloud logging. // Setup logging for LogDNA cloud logging.
if (process.env.LOGDNA_API_KEY) { if (process.env.LOGDNA_API_KEY) {
const logdnaWinston = require('logdna-winston');
const logLevel = process.env.LOGDNA_LEVEL || 'info'; const logLevel = process.env.LOGDNA_LEVEL || 'info';
logger.add(new logdnaWinston({ logger.add(new LogdnaWinston({
level: logLevel, level: logLevel,
app: process.env.LOGDNA_APPNAME, app: process.env.LOGDNA_APPNAME,
index_meta: true, index_meta: true,

View File

@ -9,7 +9,9 @@ import triggers from './triggers/_';
// Check for environmental variables. // Check for environmental variables.
import * as checkenv from 'checkenv'; import * as checkenv from 'checkenv';
checkenv.setConfig(require('../env.json')); import envConfig from '../env.json';
checkenv.setConfig(envConfig);
checkenv.check(); checkenv.check();
interface IModuleMap { interface IModuleMap {
@ -31,11 +33,11 @@ if (!rulesRole) {
throw new Error('DISCORD_RULES_ROLE somehow became undefined.'); throw new Error('DISCORD_RULES_ROLE somehow became undefined.');
} }
function findArray(haystack: string | string[], arr: string[]) { function findArray (haystack: string | string[], arr: string[]) {
return arr.some((v: string) => haystack.indexOf(v) >= 0); return arr.some((v: string) => haystack.indexOf(v) >= 0);
} }
function IsIgnoredCategory(categoryName: string) { function IsIgnoredCategory (categoryName: string) {
const IgnoredCategory = ['internal', 'team', 'development']; const IgnoredCategory = ['internal', 'team', 'development'];
return IgnoredCategory.includes(categoryName); return IgnoredCategory.includes(categoryName);
} }