2024-02-29 20:39:21 -05:00
|
|
|
function inject (bot) {
|
2024-02-16 22:59:09 -05:00
|
|
|
const transactions = {}
|
|
|
|
let transactionId = 0
|
|
|
|
|
|
|
|
function tabComplete (text) {
|
|
|
|
return new Promise(resolve => {
|
|
|
|
transactions[transactionId] = resolve
|
2024-02-29 20:39:21 -05:00
|
|
|
bot._client.write('tab_complete', { transactionId, text })
|
2024-02-16 22:59:09 -05:00
|
|
|
|
|
|
|
transactionId = (transactionId + 1) % 256
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-02-29 20:39:21 -05:00
|
|
|
bot.on('packet.tab_complete', packet => {
|
2024-02-16 22:59:09 -05:00
|
|
|
if (!transactions[packet.transactionId]) return
|
|
|
|
|
|
|
|
transactions[packet.transactionId](packet)
|
|
|
|
delete transactions[packet.transactionId]
|
|
|
|
})
|
|
|
|
|
|
|
|
bot.tabComplete = tabComplete
|
|
|
|
}
|
|
|
|
|
2024-02-29 20:39:21 -05:00
|
|
|
module.exports = inject
|