Skip to content

Crash on second call to help command #776

@scriptdaemon

Description

@scriptdaemon

EDIT: The same error occurs doing anything a second time when using help().

Version:

6.6.0

Error:

/mnt/c/Users/kwilliams/Documents/Projects/cheevobot/node_modules/yargs/yargs.js:899
          return k.length > 1
                  ^

TypeError: Cannot read property 'length' of undefined
    at /mnt/c/Users/kwilliams/Documents/Projects/cheevobot/node_modules/yargs/yargs.js:899:19
    at Array.filter (native)
    at parseArgs (/mnt/c/Users/kwilliams/Documents/Projects/cheevobot/node_modules/yargs/yargs.js:898:42)
    at Object.Yargs.self.parse (/mnt/c/Users/kwilliams/Documents/Projects/cheevobot/node_modules/yargs/yargs.js:499:18)
    at SteamBot.exec (/mnt/c/Users/kwilliams/Documents/Projects/cheevobot/lib/steam-bot.js:81:18)
    at SteamUser.SteamBot._client.on (/mnt/c/Users/kwilliams/Documents/Projects/cheevobot/lib/steam-bot.js:35:12)
    at emitThree (events.js:116:13)
    at SteamUser.emit (events.js:195:7)
    at SteamUser._emitIdEvent (/mnt/c/Users/kwilliams/Documents/Projects/cheevobot/node_modules/steam-user/components/utility.js:29:12)
    at SteamUser._handlers.(anonymous function) (/mnt/c/Users/kwilliams/Documents/Projects/cheevobot/node_modules/steam-user/components/chat.js:282:9)

Code:

'use strict'

// -- Dependencies -------------------------------------------------------------

// Node.js API
const path = require('path')

// Node packaged modules
const confit = require('confit')
const SteamUser = require('steam-user')
const yargs = require('yargs/yargs')

// Local modules
const dice = require('./plugins/cmds/dice')
const uptime = require('./plugins/cmds/uptime')

// -- Public Interface ---------------------------------------------------------

class SteamBot {
  constructor () {
    this._client = new SteamUser()
    this._client.on('friendOrChatMessage', (sender, msg, chat) => {
      this.exec(msg, { sender, chat })
    })
  }

  start (cb) {
    confit(path.resolve('config/')).create((err, config) => {
      if (err) return cb(err)

      // Build command parser
      this._parser = yargs()
      this._parser.command({
        'command': '!ch <cmd>', // config.get('cmd'),
        'description': 'test desc', // config.get('description'),
        'builder': yargs => {
          yargs.command(dice(this))
          yargs.command(uptime(this))
          yargs.help()
          yargs.version()
        }
      })

      this._client.logOn(config.get('login'))
      this._client.on('loggedOn', response => {
        this._client.setPersona(SteamUser.EPersonaState.Online)
        cb()
      })
    })
  }

  exec (cmd, context) {
    this._parser.parse(cmd, context, (err, argv, output) => {
      if (err && !output) throw err
      if (output) {
        this._client.chatMessage(context.chat, output)
      }
    })
  }
}

// -- Exports ------------------------------------------------------------------

module.exports = SteamBot

Steps to produce:

Scriptdaemon: !ch help // First call
CheevoBot:  !ch <cmd> // Description doesn't appear?

Commands:
  dice [roll]  Simulate a dice roll
  uptime       Retrieve bot uptime

Options:
  --help     Show help                                                 [boolean]
  --version  Show version number                                       [boolean]
Scriptdaemon: !ch help // Second call
CheevoBot is now Offline. // Crash

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions