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

@skiilaa/hackmud-chat-api

v1.1.1

Published

An easy-to-use hackmud Chat API module.

Downloads

6

Readme

hackmud-chat-api

An easy-to-use hackmud Chat API module.

Installation

Latest NPM release (recommended): npm @skiilaa/install hackmud-chat-api Latest GitHub version: npm install moriczgergo/hackmud-chat-api

Usage

var Hackmud = require('hackmud-chat-api');

var chat = new Hackmud("token or chat_pass");
console.log("Logged in! Token: " + chat.token);
console.log("Users: " + chat.user.join(", "));

chat.subscribe(messages => {
    messages.forEach(message => {
        console.log("From: " + message.from_user);
        console.log("To: " + message.to_user);

        if (message.channel) { // If sent in a channel
            console.log("Sent in " + message.channel);
            chat.send(message.to_user, message.channel, message.msg); // Reply with the same message in the same channel with the user that received the message.
        } else { // If sent in private
            chat.tell(message.to_user, message.from_user, message.msg) // Reply with the same message in private with the user that received that message.
            console.log("Sent in private");
        }

        console.log(message.msg);
    });
});

Docs

Message

id

Unique message ID provided by the API.

t

Unix timestamp in milliseconds.

from_user

The user who sent the message.

to_user

The user who received the message.

msg

The message's text. (with color codes)

channel

Optional, only present if the message was sent in a channel, if the message wasn't a tell.

Client

new Client(auth)

Parameters:

  • auth: A token or a chat_pass.

Initializes the client.

Example:

var chat = new Client("ghwef");

subscribe(handler, users)

Params:

  • handler: A callback that receives messages.
    • 1st param: Array of messages.
  • users: Array of users to listen with. Optional.

Returns: Index of listener. You'll need this if you want to unsubscribe.

Example:

var handlerIndex = chat.subscribe(messages => {
    console.log("Messages received:");
    messages.forEach(message => {
        console.log(message.msg);
    });
});

unsubscribe(index)

Params:

  • index: Index of handler to unsubscribe.

Example:

chat.unsubscribe(handlerIndex);

send(username, channel, msg)

Params:

  • username: Username to send message with.
  • channel: Channel to send message to.
  • msg: Message to send.

Returns: null or error, if there was one.

Example:

var err = chat.send("my_bot", "0000", "my_bot.totally_not_a_scam is the best script ever.");
if (err) console.error("An error occurred: " + err);

tell(username, tell, msg)

Params:

  • username: Username to send message with.
  • tell˙: Username to send message to.
  • msg: Message to send.

Returns: null or error, if there was one.

Example:

var err = chat.tell("my_bot", "me", "Started running.");
if (err) console.error("An error occurred: " + err);

users

Array of users.

channels

An object. The keys are usernames, and the values are arrays of channel names that the user has joined.

Example:

{
    me: ["0000", "town", "CHOICE_EPSILON_2"],
    my_bot: ["0000"]
}

token

The token, either the one passed to the constructor, or the one generated from chat_pass.