chipmunkbot3/plugins/tab_complete.js

24 lines
569 B
JavaScript

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