[bot] break out RPC and shared packages for bot service breakout

This commit is contained in:
41666 2019-04-04 11:13:34 -05:00
parent 544ae65c58
commit 50b5e334a3
No known key found for this signature in database
GPG key ID: BC51D07640DC10AF
31 changed files with 233 additions and 111 deletions

View file

@ -0,0 +1,14 @@
{
"presets": [ ["@babel/preset-env", {
"targets": {
"node": true
}
}], "@babel/preset-flow" ],
"plugins": [
"@babel/plugin-syntax-dynamic-import",
"@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-optional-chaining",
["@babel/plugin-transform-runtime",
{ "helpers": false }]
]
}

View file

View file

@ -0,0 +1,5 @@
// @flow
import Bot from './Bot'
const B = new Bot()
B.start()

View file

@ -0,0 +1,70 @@
// @flow
import chalk from 'chalk'
export class Logger {
debugOn: boolean
name: string
quietSql: boolean
constructor (name: string, debugOverride: boolean = false) {
this.name = name
this.debugOn = (process.env.DEBUG === 'true' || process.env.DEBUG === '*') || debugOverride
this.quietSql = (process.env.DEBUG_SQL !== 'true')
}
fatal (text: string, ...data: any) {
this.error(text, data)
if (typeof data[data.length - 1] === 'number') {
process.exit(data[data.length - 1])
} else {
process.exit(1)
}
}
error (text: string, ...data: any) {
console.error(chalk.red.bold(`ERR ${this.name}:`) + `\n ${text}`, data)
}
warn (text: string, ...data: any) {
console.warn(chalk.yellow.bold(`WARN ${this.name}:`) + `\n ${text}`, data)
}
notice (text: string, ...data: any) {
console.log(chalk.cyan.bold(`NOTICE ${this.name}:`) + `\n ${text}`, data)
}
info (text: string, ...data: any) {
console.info(chalk.blue.bold(`INFO ${this.name}:`) + `\n ${text}`, data)
}
bot (text: string, ...data: any) {
console.log(chalk.yellowBright.bold(`BOT CMD:`) + `\n ${text}`, data)
}
deprecated (text: string, ...data: any) {
console.warn(chalk.yellowBright(`DEPRECATED ${this.name}:`) + `\n ${text}`, data)
console.trace()
}
request (text: string, ...data: any) {
console.info(chalk.green.bold(`HTTP ${this.name}:`) + `\n ${text}`)
}
debug (text: string, ...data: any) {
if (this.debugOn) {
console.log(chalk.gray.bold(`DEBUG ${this.name}:`) + `\n ${text}`, data)
}
}
sql (logger: Logger, ...data: any) {
if (logger.debugOn && !logger.quietSql) {
console.log(chalk.bold('DEBUG SQL:\n '), data)
}
}
}
export default (pathname: string) => {
const name = pathname.replace(__dirname, '').replace('.js', '')
return new Logger(name)
}

View file

@ -0,0 +1,17 @@
{
"private": true,
"name": "@roleypoly/bot",
"version": "2.0.0",
"scripts": {
"build": "babel --delete-dir-on-start -d lib .",
"dev": "yarn build --watch"
},
"main": "./lib/Bot.js",
"dependencies": {
"eris": "^0.9.0",
"@roleypoly/rpc-client": "2.0.0"
},
"devDependencies": {
"@babel/cli": "^7.4.3"
}
}