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 state from './state';
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 () {
// Load the warnings file into the application state.
@ -32,12 +38,14 @@ export function readBans () {
export function readCustomResponses () {
// Load the responses file into the responses variable.
try {
state.responses = require(`./responses/${process.env.TENANT}.json`);
logger.debug(`Loaded responses file for ${process.env.TENANT} from external source.`);
} catch (e) {
logger.error(`Failed to load ${process.env.TENANT}.json! Custom responses are disabled.`);
if (process.env.TENANT) {
state.responses = responses[process.env.TENANT];
if (state.responses) {
logger.debug(`Loaded responses file for ${process.env.TENANT} from external source.`);
return;
}
}
logger.error(`Failed to load ${process.env.TENANT}.json! Custom responses are disabled.`);
}
export function flushWarnings () {

View File

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

View File

@ -9,7 +9,9 @@ import triggers from './triggers/_';
// Check for environmental variables.
import * as checkenv from 'checkenv';
checkenv.setConfig(require('../env.json'));
import envConfig from '../env.json';
checkenv.setConfig(envConfig);
checkenv.check();
interface IModuleMap {
@ -31,11 +33,11 @@ if (!rulesRole) {
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);
}
function IsIgnoredCategory(categoryName: string) {
function IsIgnoredCategory (categoryName: string) {
const IgnoredCategory = ['internal', 'team', 'development'];
return IgnoredCategory.includes(categoryName);
}