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 🙏

© 2026 – Pkg Stats / Ryan Hefner

ariwa

v0.0.6-A

Published

A unified Discord bot client supporting Top.gg and WebSocket APIs

Readme

Ariwa

A TypeScript library for interacting with Top.gg API and websocket-topgg services. Ariwa provides a simple and efficient way to receive real-time vote events, check vote status, and manage bot statistics on Top.gg.

Features

  • Real-time vote notifications via WebSocket connection
  • Automatic reconnection handling
  • Persistent event tracking across restarts
  • Comprehensive Top.gg API integration
  • Built-in response caching for optimal performance
  • Fully typed with TypeScript

Installation

npm install ariwa

Basic Usage

Setting up a WebSocket Client

import { AriwaClient } from 'ariwa';

const client = new AriwaClient({
  ws: 'your-websockets-topgg-token',
  topgg: 'your-topgg-api-token', // Optional, for Top.gg API access
  name: 'my-awesome-bot',
  persistPath: './timestamp.json' // Optional, for persisting last event timestamp
});

// Connect to the WebSocket server
client.connect();

// Listen for vote events
client.on('vote', (voteData) => {
  console.log(`User ${voteData.user} voted for bot ${voteData.bot}!`);
  // Reward your users here
});

// Listen for other events
client.on('ready', (data) => {
  console.log('Connected to Top.gg WebSocket!');
});

client.on('test', (testData) => {
  console.log('Received test event:', testData);
});

client.on('reminder', (reminderData) => {
  console.log('Received reminder event:', reminderData);
});

// Handle disconnections
client.on('disconnected', (code, reason) => {
  console.log(`Disconnected: ${code} - ${reason}`);
});

// Handle errors
client.on('error', (err) => {
  console.error('WebSocket error:', err);
});

// Gracefully disconnect
process.on('SIGINT', async () => {
  console.log('Disconnecting...');
  await client.disconnect();
  process.exit(0);
});

Working with Top.gg API

// Using the API through the client
const botResult = await client.topgg.getBot('botId');
if (botResult.isOk()) {
  const bot = botResult.unwrap();
  console.log(`Bot ${bot.username} has ${bot.server_count} servers!`);
}

// Post stats to Top.gg
await client.topgg.postStats('botId', {
  server_count: 1500,
  shard_count: 10
});

// Check if a user voted
const hasVotedResult = await client.topgg.hasVoted('botId', 'userId');
if (hasVotedResult.isOk() && hasVotedResult.unwrap()) {
  console.log('User has voted!');
}

Using the WebSocket API Directly

import { AriwaAPI } from 'ariwa';

const api = new AriwaAPI({ token: 'your-websockets-topgg-token' });

// Get entity information
const entityResult = await api.getEntity();
if (entityResult.isOk()) {
  console.log('Connected entity:', entityResult.unwrap());
}

// Get user information
const userResult = await api.getUser('userId');
if (userResult.isOk()) {
  console.log('User data:', userResult.unwrap());
}

// Set user reminders
await api.setUserReminders('userId', true);

Configuration Options

AriwaClient Options

| Option | Type | Description | Default | |--------|------|-------------|---------| | ws | string | WebSockets-TopGG token | Required | | topgg | string | Top.gg API token | undefined | | name | string | Client name for WebSocket connection | Required | | cache | number | Cache TTL in milliseconds | 300000 (5 minutes) | | autoReconnect | boolean | Auto reconnect on disconnect | true | | reconnectOptions | object | Reconnection configuration | See below | | persistPath | string | Path to save timestamp information | undefined |

Reconnection Options

| Option | Type | Description | Default | |--------|------|-------------|---------| | initialDelay | number | Initial reconnection delay in ms | 1000 | | maxDelay | number | Maximum reconnection delay in ms | 30000 | | maxAttempts | number | Maximum number of reconnection attempts | Infinity |

Event Types

The AriwaClient emits the following events:

| Event | Description | Data | |-------|-------------|------| | ready | Connection established | Connection details | | vote | User voted for a bot | Vote details (user, bot, etc.) | | test | Test event received | Test data | | reminder | Vote reminder event | Reminder details | | disconnected | WebSocket disconnected | code and reason | | error | Error occurred | Error object | | unknownOp | Unknown operation received | op and data |

Error Handling

Ariwa uses the @sapphire/result package for error handling. All API methods return a Result object that can be safely unwrapped:

const result = await client.topgg.getBot('botId');
if (result.isOk()) {
  // Success
  const data = result.unwrap();
  console.log(data);
} else {
  // Error
  const error = result.unwrapErr();
  console.error('Failed to get bot:', error);
}

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.