npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mineflayer-dashboard

v2.0.1

Published

A dashboard layout for single mineflayer bot.

Downloads

78

Readme

mineflayer-dashboard

A dashboard layout for single mineflayer bot.

dashboard screenshot

Table of contents

Installation

Install using yarn

Install the package with yarn

yarn add mineflayer-dashboard

Install using npm

Install the package with npm

npm install --save mineflayer-dashboard

Initialization

Then load up the plugin using mineflayer. You can pass options argument:

  • chatPattern - a pattern that is tested against a message to determine if it's chat message or a system message. It's better to add this option as mineflayer's chat pattern will match messages like [SkinsRestorer] Your skin has been changed.. Also custom patterns are much faster than mineflayer's default one.
bot.loadPlugin(require('mineflayer-dashboard')({
  chatPattern: /^» \w+? » /
}))
// or
bot.loadPlugin(require('mineflayer-dashboard'))

Layout

+--------------------+-----------+
|                    |           |
|                    |           |
|     MODE WINDOW    |    LOG    |
|                    |           |
|                    |           |
+----+---------------+-----------+
|MODE| TEXT INPUT                |
+----+---------------------------+
  • TEXT INPUT - Here you insert your text / commands
  • MODE - Mode indicator, tells you current mode
  • LOG - Here you can print out some stuff
  • MODE WINDOW - Here you can print out mode related stuff

Logging

Logging in log window is accessible by using bot.dashboard.log function.

NOTE: Please do not use console.log as it may create some unwanted artifacts. If any other dependency is using console.log you may try to overwrite this function by

bot.once('inject_allowed', () => {
  global.console.log = bot.dashboard.log
  global.console.error = bot.dashboard.log
})

Error logging

All error logging is passed to the dashboard log window. That means all of the error handlers created before plugin load are no longer listened. This was a crucial step to maintain the layout of the app.

Modes

Included modes

Dashboard comes with 2 modes:

  • CHAT - Default mode. In CHAT mode you can see all of the chat messages sent to the player.
  • REPL - In REPL mode you can run javascript code to control over your bot.

Defining custom modes

We expose Mode class in the bot.dashboard.

The first parameter is mode name. It'll be used to create :<name> command to switch to this mode

Second one is options:

  • fg - foreground color for mode indicator
  • bg - background color for mode indicator
  • interpreter - It defines what is happening when you hit enter in the text input. Bound to mode instance
  • completer - This function should return String[] or Promise<String[]> with the completions to current string. Bound to mode instance
    • A single completion needs to be the remainder of the completed string. For example, when I want to complete nickname wvffle and I hit <tab> with cursor posiotioned in position wv| then I need to return [ 'ffle' ]
  • bypassDefaultCompletion - bypass default completion system, don't cache matches.

Example whisper mode

When in this mode, we can send messages to different players. To change the reciever simply add :to <user> at the end of the message

let lastUser = null
const whisper = new bot.dashboard.Mode('whisper', {
  bg: 'blue',
  interpreter (string) {
    let words = string.split(' ')

    // Check if we change receiver
    if (/ :to \w{3,16}$/.test(string)) {
      lastUser = words[words.length - 1]
      words = words.slice(0, -2)
    }
    
    // Log an error if there is no receiver
    if (lastUser === null) {
      return bot.dashboard.log("No receiver set, please add ' :to <user>' at the end of the message")
    }   

    // Send message
    const message = words.join(' ')
    bot.chat(`/msg ${lastUser} ${message}`)
    this.println(`to ${lastUser}: ${message}`)
  },
  async completer (string) {
    // We're using already well defined minecraft completer
    return bot.dashboard._minecraftCompleter(string)
  }
})

bot.dashboard.addMode(whisper)

bot.on('whisper', (username, message) => {
  // Log a notification if not in whisper mode
  if (bot.dashboard.mode !== whisper) {
    return bot.dashboard.log(`You have a new message from ${username}`)
  } 

  // Display messages in the mode
  whisper.println(`${username}: ${message}`)
})

Commands

Running commands

Simply type :<command> arg1 arg2...

:say wvffle "I like waffles"

NOTE: In this case :say is a custom command NOTE: In this case "I like waffles" is a string passed as arg2

Available commands

We provide some basic commands for the dashboard.

  • :help - Display available commands
  • :exit - Kill the bot / exit the application
  • :clear - Clear mode window
  • :<mode> - Change to <mode> mode
    • :chat - Change to CHAT mode
    • :repl - Change to REPL mode

Custom commands

You can add custom commands by simply doing

bot.dashboard.commands['say'] = (user, ...words) => {
  const sentence = words.join(' ')
  bot.chat(`/forcesay ${user} ${sentence}`)
}