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

module.exports = {
  register (dispatcher) {
    const node = dispatcher.register(
      literal('myuser')
        .executes(c => this.myUserCommand(c))
    )

    node.description = 'Sends the username of the sender of the command'
    node.permissionLevel = 0
  },

  myUserCommand (context) {
    const source = context.source
    const bot = source.bot
    const player = source.getPlayerOrThrow()

    source.sendFeedback([
      { text: 'Your username is: ', ...bot.styles.primary },
      { text: player.username, ...bot.styles.secondary }
    ], false)
  }
}