hubot 11.1.8 → 11.2.0

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hubot",
3
- "version": "11.1.8",
3
+ "version": "11.2.0",
4
4
  "author": "hubot",
5
5
  "keywords": [
6
6
  "github",
@@ -51,9 +51,10 @@ class Shell extends Adapter {
51
51
  if (stats.size > historySize) {
52
52
  fs.unlinkSync(historyPath)
53
53
  }
54
+
54
55
  this.#rl = readline.createInterface({
55
- input: process.stdin,
56
- output: process.stdout,
56
+ input: this.robot.stdin ?? process.stdin,
57
+ output: this.robot.stdout ?? process.stdout,
57
58
  prompt: `${this.robot.name ?? this.robot.alias}> `,
58
59
  completer
59
60
  })
@@ -76,19 +77,24 @@ class Shell extends Adapter {
76
77
  break
77
78
  }
78
79
  if (input.length > 0) {
79
- fs.appendFileSync(historyPath, `${input}\n`)
80
+ this.#rl.history.push(input)
80
81
  }
81
- const history = fs.readFileSync(historyPath, 'utf-8').split('\n').reverse()
82
- this.#rl.history = history
83
82
  let userId = process.env.HUBOT_SHELL_USER_ID || '1'
84
83
  if (userId.match(/A\d+z/)) {
85
84
  userId = parseInt(userId)
86
85
  }
87
86
  const userName = process.env.HUBOT_SHELL_USER_NAME || 'Shell'
88
87
  const user = this.robot.brain.userForId(userId, { name: userName, room: 'Shell' })
89
- await this.receive(new TextMessage(user, input, 'messageId'))
88
+ const message = new TextMessage(user, input, 'messageId')
89
+ if (!message.text.startsWith(this.robot.name) && !message.text.startsWith(this.robot.alias)) {
90
+ message.text = `${this.robot.name} ${message.text}`
91
+ }
92
+ await this.receive(message)
90
93
  this.#rl.prompt()
91
94
  })
95
+ this.#rl.on('history', async (history) => {
96
+ await fs.promises.writeFile(historyPath, history.reverse().join('\n'))
97
+ })
92
98
  try {
93
99
  this.#rl.prompt()
94
100
  this.emit('connected', this)