const { literal, argument, greedyString } = require('brigadier-commands')

module.exports = {
  register (dispatcher) {
    const node = dispatcher.register(
      literal('netmsg')
        .then(
          argument('message', greedyString())
            .executes(c => this.netMsgCommand(c))
        )
    )

    node.description = 'Runs a command in the command core'
    node.permissionLevel = 0
  },

  netMsgCommand (context) {
    const source = context.source
    const bot = source.bot
    const message = context.getArgument('message')

    bot.bots.forEach((bot2) => bot2.fancyMsg(bot.hostPortPair, source.displayName, message))
  }
}