New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

ariwa

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ariwa

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

latest
Source
npmnpm
Version
0.0.6-A
Version published
Weekly downloads
1
-80%
Maintainers
1
Weekly downloads
 
Created
Source

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

OptionTypeDescriptionDefault
wsstringWebSockets-TopGG tokenRequired
topggstringTop.gg API tokenundefined
namestringClient name for WebSocket connectionRequired
cachenumberCache TTL in milliseconds300000 (5 minutes)
autoReconnectbooleanAuto reconnect on disconnecttrue
reconnectOptionsobjectReconnection configurationSee below
persistPathstringPath to save timestamp informationundefined

Reconnection Options

OptionTypeDescriptionDefault
initialDelaynumberInitial reconnection delay in ms1000
maxDelaynumberMaximum reconnection delay in ms30000
maxAttemptsnumberMaximum number of reconnection attemptsInfinity

Event Types

The AriwaClient emits the following events:

EventDescriptionData
readyConnection establishedConnection details
voteUser voted for a botVote details (user, bot, etc.)
testTest event receivedTest data
reminderVote reminder eventReminder details
disconnectedWebSocket disconnectedcode and reason
errorError occurredError object
unknownOpUnknown operation receivedop 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.

Keywords

topgg

FAQs

Package last updated on 31 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts