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

@com1killer/hackmud-chat-api

v1.0.3

Published

A client for the Hackmud Chat API.

Downloads

2

Readme

hackmud-chat-api

A client for the Hackmud Chat API.

Additional docs for the chat API

Installation

npm i -s @com1killer/hackmud-chat-api for module use

npm i -g @com1killer/hackmud-chat-api for CLI use

CLI Usage

hm-pass2token <chat pass>
Converts your chat pass to a chat token.

Usage example

var HackmudChatAPI = require("@com1killer/hackmud-chat-api");
var chat = new HackmudChatAPI("YOUR_CHAT_TOKEN_OR_CHAT_PASS");
console.log(chat.token);

chat.on("poll", function pollHandler(messages) { // When messages are polled
    let cleanMessages = messages.filter(message => message.to_user == "my_bot_user" && messages.to_user != messages.from_user); // Filter messages. Only messages sent to bot user remains, and echo is removed.

    messages.forEach(message => { // For every message
        chat.tell("my_bot_user", "my_user", message.from_user + " said:\n" + message.msg); // Relay message to another user
    })
});

Reference

new HackmudChatAPI

Creates a HackmudChatAPI instance. Converts chat pass into chat token if needed, does initial account sync, and sets up timers.

Arguments:

  • tokenOrPass: Chat token or chat pass. If chat pass, it will be converted to chat token.
  • pollInterval: Polling frequency in milliseconds. Must be over 700ms to avoid ratelimits. Recommended to be over 2s. Default: 2s
  • accountSyncInterval: Account sync (updated usernames) frequency in milliseconds. Must be over 5s to avoid ratelimits, but a much bigger frequency is enough. Default: 30m
  • url: URL of Chat API. Doesn't need to be touched. Default: "https://www.hackmud.com/mobile"

Properties

  • token: Chat token.
  • users: An object of users, where the user is the key, and an array of their joined channels is the value.
  • lastPoll: The JS timestamp of the last poll.

on

Adds an event handler.

Arguments:

  • name: Name of event. (poll, error, accountSync)
  • handler: Event handler. Argument:
    • poll: An array of messages.
    • error: An error.
    • accountSync: An object of users, where the user is the key, and an array of their joined channels is the value.

supervise

Adds an event handler for every event.

Arguments:

  • handler: Event handler. See argument above.

send

Sends a message to a channel.

Arguments:

  • from: Username to send the message from.
  • channel: Channel to send the message to.
  • message: Message to send.

Returns:

  • ok: Success?

tell

Sends a tell to a user.

Arguments:

  • from: Username to send the message from.
  • to: Username to send the message to.
  • message: Message to send.

Returns:

  • ok: Success?

destroy

Destroys HackmudChatAPI instance.

Message

A message object.

Properties:

  • id: Message ID
  • t: JS timestamp of message
  • from_user: Username of sender
  • msg: Message
  • is_join: Whether the chat message is a channel join, not present if false
  • is_leave: Whether the chat message is a channel leave, not present if false
  • channel: Channel of message, not present in tells
  • to_user: Username of recipient