chipmunkbot3/commands/echo.js

36 lines
819 B
JavaScript
Raw Permalink Normal View History

2024-04-02 17:53:10 -04:00
const { literal, argument, greedyString } = require('brigadier-commands')
2024-02-11 21:23:41 -05:00
2024-04-02 17:53:10 -04:00
module.exports = {
register (dispatcher) {
const node = dispatcher.register(
literal('echo')
.then(
argument('message', greedyString())
.executes(c => this.echoCommand(c))
2024-04-02 17:53:10 -04:00
)
)
2024-02-11 21:23:41 -05:00
2024-04-02 17:53:10 -04:00
node.description = 'Sends a message in chat as the bot'
node.permissionLevel = 0
},
2024-02-11 21:23:41 -05:00
2024-04-02 17:53:10 -04:00
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
2024-04-02 17:53:10 -04:00
}
}