Skip to content
This repository was archived by the owner on Nov 1, 2023. It is now read-only.

Commit

Permalink
feat: added date formatting to logs
Browse files Browse the repository at this point in the history
  • Loading branch information
4lch4 committed Jun 11, 2021
1 parent d2bbe0c commit 5156757
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"dependencies": {
"@types/fs-extra": "^9.0.11",
"bunyan": "1.8.15",
"dayjs": "^1.10.5",
"discord-akairo": "8.1.0",
"discord.js": "12.5.1",
"eris": "^0.15.1",
Expand Down
37 changes: 22 additions & 15 deletions src/Tron.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@
import { CommandClient } from 'eris'
import { unknown, getCommands } from './commands'
import { getClient } from './util'
import { getCommands, unknown } from './commands'
import { BotConfig, DateFormatter, getClient } from './lib'

const { logDate } = new DateFormatter()

if (process.env.DISCORD_TOKEN) {
const tron: CommandClient = getClient()
// const { execute, label, opts } = new Ping()

for (const { execute, label, opts } of getCommands()) {
tron.registerCommand(label, (msg, args) => execute(msg, args), opts)
}

// tron.registerCommand(
// 'ping',
// (_msg, _args) => {
// return 'Pong!'
// },
// {
// aliases: ['pang'],
// caseInsensitive: true
// }
// )

tron.on('ready', () => {
console.log('Ready!')
console.log(`[${logDate}] - Tron has come online!`)
tron.createMessage(
BotConfig.homeChannel,
`[${logDate}] - Tron has come online!`
)
})

tron.on('messageCreate', msg => unknown(tron, msg))
tron.on('error', (err, id) => {
console.error('Uncaught error retrieved...')
console.error(`Error id = ${id}`)
console.error(err)
})
tron.on('warn', (msg, id) => {
console.warn(`Warning from Tron. Msg id = ${id}`)
console.warn(msg)
})
tron.on('unknown', (packet, id) => {
console.log(`Unknown event... Id = ${id}`)
console.log(packet)
})

tron.connect()
} else {
Expand Down
7 changes: 7 additions & 0 deletions src/lib/util/DateFormatter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import dayjs from 'dayjs'

export class DateFormatter {
get logDate(): string {
return dayjs().format('YYYY-MM-DDTHH:mm:ssZ[Z]')
}
}

0 comments on commit 5156757

Please sign in to comment.