chipmunkbot3/plugins/tab_complete.js

25 lines
569 B
JavaScript
Raw Normal View History

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