chipmunkbot3/commands/echo.js

35 lines
819 B
JavaScript

const { literal, argument, greedyString } = require('brigadier-commands')
module.exports = {
register (dispatcher) {
const node = dispatcher.register(
literal('echo')
.then(
argument('message', greedyString())
.executes(c => this.echoCommand(c))
)
)
node.description = 'Sends a message in chat as the bot'
node.permissionLevel = 0
},
echoCommand (context) {
const bot = context.source.bot
bot.chat.queue.push(this.sanitize(context.getArgument('message')))
},
sanitize (message) {
let clean = ''
for (let i = 0; i < message.length && clean.length < 256; i++) {
const c = message[i]
const cc = c.charCodeAt(0)
if (cc < 0x20 || cc === 0x7f || cc === 0xa7) continue
clean += c
}
return clean
}
}