hubot 13.1.4 → 13.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/Listener.mjs +1 -2
- package/src/adapters/Shell.mjs +22 -21
package/package.json
CHANGED
package/src/Listener.mjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
import { inspect } from 'node:util'
|
|
4
|
-
import { TextMessage } from './Message.mjs'
|
|
5
4
|
import Middleware from './Middleware.mjs'
|
|
6
5
|
|
|
7
6
|
class Listener {
|
|
@@ -97,7 +96,7 @@ class TextListener extends Listener {
|
|
|
97
96
|
// callback - A Function that is triggered if the incoming message matches.
|
|
98
97
|
constructor (robot, regex, options, callback) {
|
|
99
98
|
function matcher (message) {
|
|
100
|
-
if (message
|
|
99
|
+
if (typeof message.match === 'function') {
|
|
101
100
|
return message.match(regex)
|
|
102
101
|
}
|
|
103
102
|
}
|
package/src/adapters/Shell.mjs
CHANGED
|
@@ -35,39 +35,25 @@ const reset = '\x1b[0m'
|
|
|
35
35
|
|
|
36
36
|
class Shell extends Adapter {
|
|
37
37
|
#rl = null
|
|
38
|
+
#levels = ['trace', 'debug', 'info', 'warn', 'error', 'fatal']
|
|
39
|
+
#logLevel = 'info'
|
|
40
|
+
#levelPriorities = {}
|
|
38
41
|
constructor (robot) {
|
|
39
42
|
super(robot)
|
|
40
43
|
this.name = 'Shell'
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const levelPriorities = levels.reduce((acc, current, idx) => {
|
|
44
|
+
this.#logLevel = process.env.HUBOT_LOG_LEVEL || this.#logLevel
|
|
45
|
+
this.#levelPriorities = this.#levels.reduce((acc, current, idx) => {
|
|
44
46
|
acc[current] = idx
|
|
45
47
|
return acc
|
|
46
48
|
}, {})
|
|
47
49
|
|
|
48
|
-
const configuredPriority = levelPriorities[logLevel]
|
|
49
|
-
|
|
50
|
-
const noop = async () => {}
|
|
51
|
-
|
|
52
|
-
levels.forEach(level => {
|
|
53
|
-
const priority = levelPriorities[level]
|
|
54
|
-
if (priority >= configuredPriority) {
|
|
55
|
-
robot.logger[level] = async (...args) => {
|
|
56
|
-
const color = levelColors[level] || ''
|
|
57
|
-
const msg = `${color}[${level}]${reset} ${args.map(a => typeof a === 'object' ? JSON.stringify(a) : a).join(' ')}`
|
|
58
|
-
await this.send({ user: { name: 'Logger', room: 'Shell' } }, msg)
|
|
59
|
-
}
|
|
60
|
-
} else {
|
|
61
|
-
robot.logger[level] = noop
|
|
62
|
-
}
|
|
63
|
-
})
|
|
64
50
|
this.robot.on('scripts have loaded', () => {
|
|
65
|
-
this.#rl
|
|
51
|
+
this.#rl?.prompt()
|
|
66
52
|
})
|
|
67
53
|
}
|
|
68
54
|
|
|
69
55
|
async send (envelope, ...strings) {
|
|
70
|
-
this.#rl
|
|
56
|
+
this.#rl?.prompt()
|
|
71
57
|
Array.from(strings).forEach(str => console.log(bold(str)))
|
|
72
58
|
}
|
|
73
59
|
|
|
@@ -142,6 +128,21 @@ class Shell extends Adapter {
|
|
|
142
128
|
const existingHistory = (await readFile(historyPath, 'utf8')).split('\n')
|
|
143
129
|
existingHistory.reverse().forEach(line => this.#rl.history.push(line))
|
|
144
130
|
|
|
131
|
+
const configuredPriority = this.#levelPriorities[this.#logLevel]
|
|
132
|
+
const noop = async () => {}
|
|
133
|
+
this.#levels.forEach(level => {
|
|
134
|
+
const priority = this.#levelPriorities[level]
|
|
135
|
+
if (priority >= configuredPriority) {
|
|
136
|
+
this.robot.logger[level] = async (...args) => {
|
|
137
|
+
const color = levelColors[level] || ''
|
|
138
|
+
const msg = `${color}[${level}]${reset} ${args.map(a => typeof a === 'object' ? JSON.stringify(a) : a).join(' ')}`
|
|
139
|
+
await this.send({ user: { name: 'Logger', room: 'Shell' } }, msg)
|
|
140
|
+
}
|
|
141
|
+
} else {
|
|
142
|
+
this.robot.logger[level] = noop
|
|
143
|
+
}
|
|
144
|
+
})
|
|
145
|
+
|
|
145
146
|
try {
|
|
146
147
|
this.emit('connected', this)
|
|
147
148
|
} catch (error) {
|