Skip to content

Commit

Permalink
fix: I looove case insensitive OSes
Browse files Browse the repository at this point in the history
  • Loading branch information
KararTY committed Apr 16, 2022
1 parent 9e36a4b commit 357b9f0
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
61 changes: 61 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Load env variables
import { Logger } from '@adonisjs/logger'
import { PajbotAPI, TwitchAuth } from 'befriendlier-shared'
import { readdirSync } from 'fs'
import path from 'path'
import PajbotConfig from './config/Pajbot'
import TwitchConfig from './config/Twitch'
import WSConfig from './config/Ws'
import env from './env'
import packageJSON from './package.json'
import Twitch from './src/Twitch'
import Ws from './src/Ws'

const logger = new Logger({
name: 'befriendlier-bot',
enabled: true,
level: typeof env.get('LOG_LEVEL') === 'string' ? String(env.get('LOG_LEVEL')) : 'info',
prettyPrint: env.get('NODE_ENV') === 'development'
})

// Initialize config values for WS.
const wsConfig = new WSConfig(env)
const server = new Ws(wsConfig, logger)

// Initialize config values for Twitch.
const apiConfig = new TwitchConfig(env)
const api = new TwitchAuth(apiConfig, logger.level)

// Initialize Pajbot.
const pajAPIConfig = new PajbotConfig()
const pajbotAPI = new PajbotAPI(pajAPIConfig, logger.level)

// Start Twitch client.
const twitch = new Twitch(apiConfig, server, api, pajbotAPI, packageJSON, logger)

// Add command handlers
const commandDirectory = path.join(__dirname, 'src', 'Handlers')
const commandFiles = readdirSync(commandDirectory, 'utf-8').filter(fileName => fileName.endsWith('.js'))

// eslint-disable-next-line no-void
void (async function loadHandlers (): Promise<void> {
let currentFileDir: string = ''

try {
for (let index = 0; index < commandFiles.length; index++) {
currentFileDir = commandFiles[index]
const fullFileName = path.join(commandDirectory.toString(), commandFiles[index])

// Import
const Command = (await import(fullFileName)).default
twitch.handlers.push(new Command(twitch, server, logger))
}

server.connect()
} catch (error) {
logger.error({ err: error }, `Index.ts: Something went wrong while importing ${String(currentFileDir)}.`)
setTimeout(() => {
process.exit(0)
}, 10000)
}
})()
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {
"build": "rimraf build/ && tsc -b && copyfiles .env build/",
"start": "node build/Index.js --inspect",
"start-test": "ts-node-dev --respawn --clear --log-error --inspect=\"0\" -- Index.ts",
"start-test": "ts-node-dev --respawn --clear --log-error --inspect=\"0\" -- index.ts",
"lint": "ts-standard",
"format": "ts-standard --fix",
"release": "standard-version",
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"extends": "./node_modules/adonis-preset-ts/tsconfig",
"include": [
"**/*"
],
Expand All @@ -7,8 +8,8 @@
"build",
"WIP"
],
"extends": "./node_modules/adonis-preset-ts/tsconfig",
"compilerOptions": {
"forceConsistentCasingInFileNames": true,
"outDir": "build",
"incremental": true,
"rootDir": ".",
Expand Down

0 comments on commit 357b9f0

Please sign in to comment.