chipmunkbot3/plugins/tab_complete.js
2024-02-16 22:59:09 -05:00

24 lines
575 B
JavaScript

function inject (bot, client) {
const transactions = {}
let transactionId = 0
function tabComplete (text) {
return new Promise(resolve => {
transactions[transactionId] = resolve
client.write('tab_complete', { transactionId, text })
transactionId = (transactionId + 1) % 256
})
}
client.on('tab_complete', packet => {
if (!transactions[packet.transactionId]) return
transactions[packet.transactionId](packet)
delete transactions[packet.transactionId]
})
bot.tabComplete = tabComplete
}
module.exports.client = inject