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

hc-arcade-js

v1.0.1

Published

JS/TS Library to access the Hack Club Arcade API

Downloads

2

Readme

Hack Club Arcade JS

This is a library to access the Hack Club Arcade API in TypeScript/JavaScript.

To get started, simply install the package, make a js/ts file, and create a client:

const hackclub = require('hc-arcade-js');
// OR
import * as hackclub from 'hc-arcade-js';

const client = new hackclub.Client({
  slackID: 'Slack User ID',
  APIKey: 'Hack Club API Key',
});

And you're set!

Usage

Types/Classes

ResData

{
    ok: false;
    error: string;
} | {
    ok: true;
    // More Data
}

SessionData

{
  time: {
    totalMins: number;
    elapsedMins: number;
    remainingMins: number;
    createdAt: Date;
    endAt: Date;
  }
  paused: boolean;
  completed: boolean;
  goal: string | null;
  work: string;
}

Time

export default class Time {
  constructor(ms: number);
  getMS(): number;
  getSeconds(): number;
  getMinutes(): number;
  getHours(): number;
  getDays(): number;
  getWeeks(): number;
  getMonths(): number;
  getTrueMonths(): number;
  getYears(): number;
}

Methods

ping()

Returns a Promise which resolves to the string "pong".

const res = await client.ping();
console.log(res);
// pong

getStatus()

Fetches the status of the hack club arcade.

Returns a Promise which resolves with the status.

{
  activeSessions: number;
  airtableConnected: boolean;
  slackConnected: boolean;
}
const status = await client.getStatus();
console.log(`There are ${status.activeSessions} sessions active!`);
// There are (x) sessions active!

getRemainingSessionTime(slackId?: string) (DEPRECATED)

Fetches the amount of milliseconds left on the active session of a user, and also indicates if there is a session active. By default fetches the active user's session.

Returns a Promise which resolves to a ResData.

The data will either have active as false, or active as true and remainingMS as the amount of milliseconds left.

{
    active: false;
} | {
    active: true;
    remainingMS: number;
}
const status = await client.getRemainingSessionTime();

if (!status.ok) throw new Error(status.error);

if (status.active) console.log(`I have ${status.remainingMS / 1000 / 60} minutes left!`);
else console.log('I am not in an active session!');

getSessionData()

Fetches active session data of the current user.

Returns a Promise which resolves to a ResData.

The data will either have found to false and active to false if there is no active or recent session, or found will be true and the data will fill in as below.

{
    found: true;
    active: boolean;
    userID: string;
    messageTs: string;
} & SessionData
const session = await client.getSessionData();

if (!session.ok) throw new Error(session.error);

if (session.active) console.log(`I have ${session.time.remainingMinsq} minutes left!`);
else console.log('I am not in an active session!');

getUserStats()

Fetches statistics of the current user.

Returns a Promise which resolves to a ResData.

{
  sessions: number;
  time: Time;
}
const stats = await client.getUserStats();

if (!stats.ok) throw new Error(stats.error);

console.log(`I have done ${stats.sessions} sessions and spent ${stats.time.getMinutes()} minutes on the Hack Club Arcade!`);

getUserGoals()

Fetches all goals and their data of the current user.

Returns a Promise which resolves to a ResData.

{
  goals: Array<{
    name: string;
    time: Time;
  }>;
}
const goals = await client.getUserGoals();

if (!goals.ok) throw new Error(goals.error);

console.log(`I have ${goals.length} total goals!`);

getSessionHistory()

Fetches the session history of the user.

Returns a Promise which resolves to a ResData.

| NOTE: This may not retrieve all sessions

{
  sessions: Array<SessionData>;
}
const history = await client.getSessionHistory();

if (!history.ok) throw new Error(history.error);

console.log(`I have ${history.length} total sessions!`);

start(work: string)

Start a new session.

Returns a Promise which resolves to a ResData.

The data will either have created set to false in the case that there is an already active session, or created will be set to true and the data will fill in as below.

{
  created: true;
  session: {
    id: string;
    userID: string;
    createdAt: Date;
  }
}
const res = await client.start();

if (!res.ok) throw new Error(res.error);

if (res.created) console.log(`Created session ${res.session.id}`);
else console.log('Session already active!');

cancel()

Stops the current session.

Returns a Promise which resolves to a ResData.

The data will either have cancelled set to false in the case that there is no active session, or cancelled will be set to true and the data will fill in as below.

{
  cancelled: true;
  session: {
    id: string;
    userID: string;
    createdAt: Date;
  }
}
const res = await client.cancel();

if (!res.ok) throw new Error(res.error);

if (res.cancelled) console.log(`Cancelled session ${res.session.id}`);
else console.log('No active session!');

togglePaused()

Returns a Promise which resolves to a ResData.

The data will either have toggled set to false in the case that there is no active session, or toggled will be set to true and the data will fill in as below.

{
  toggled: true;
  session: {
    id: string;
    userID: string;
    createdAt: Date;
    paused: boolean;
  }
}
const res = await client.togglePaused();

if (!res.ok) throw new Error(res.error);

if (res.toggled) console.log(`${res.session.paused ? 'Paused' : 'Unpaused'} the active session!`);
else console.log('No active session!');

Events

ratelimit

ratelimit(type: 'READ' | 'WRITE', info: RateLimitData): void;

Emitted whenever new ratelimit data is received, irrespective of if the ratelimit was hit or not.