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

@headz/discuit

v0.5.3

Published

A simple, lightweight, and easy to use Discord API wrapper for Node.js and browser.

Downloads

33

Readme

Discuit Client

Install

yarn add @headz/discuit

Usage

import { Discuit } from '@headz/discuit';

const discuit = new Discuit();
await discuit.login(process.env.DISCUIT_USERNAME, process.env.DISCUIT_PASSWORD);

// Get the latest posts.
const posts = await discuit.getPosts('latest', 50);
for (let i = 0; i < posts.length; i++) {
  const post = posts[i];
  const comment = await discuit.postComment(post.id, 'Welcome to the community!');
  await discuit.deleteComment(comment.postId, comment.id);
}

// Get the user's notifications.
const notifications = await discuit.getNotifications();
console.log(notifications);

for (let i = 0; i < notifications.length; i++) {
  const notification = notifications[i];
  await discuit.markNotificationAsSeen(notification.id);
  await discuit.deleteNotification(notification.id);
}

await discuit.deleteAllNotifications();

Using the watch method.

import { Discuit } from '@headz/discuit';

const communities = ['news', 'politics', 'sports'];

const discuit = new Discuit();
await discuit.login(process.env.DISCUIT_USERNAME, process.env.DISCUIT_PASSWORD);

// Watch for new posts in the communities.
discuit.watchPosts(communities, async (community, post) => {
  console.log(community, post);

  const comment = await discuit.postComment(post.id, 'Welcome to the community!');
  await discuit.deleteComment(comment.postId, comment.id);
});

Configuration

import { Discuit } from '@headz/discuit';
import winston from 'winston';

const discuit = new Discuit();

// Attach a logger.
discuit.logger = winston.createLogger({
    level: 'debug',
    format: winston.format.json(),
    defaultMeta: { service: 'discuit' },
    transports: [
        new winston.transports.Console({
            format: winston.format.simple(),
        })
    ],
});

// Configure how often the watch() command checks for new posts.
// Don't set this too low or discuit will rate limit the bot.
discuit.watchInterval = 1000 * 60 * 10 // 10 minutes

// How long to wait between callbacks in the watch loop.
discuit.sleepPeriod = 5000;

Methods

The library is still in development, so the API is subject to change.

login(username: string, password: string): Promise

Logs into the server.

import { Discuit } from '@headz/discuit';

const discuit = new Discuit();
await discuit.login('DISCUIT_USERNAME', 'DISCUIT_PASSWORD');

getMe(): Promise<User | null>

Returns the logged-in user.

const user = await discuit.getMe();

getPosts(sort: string, limit: number, next?: string, communityId?: string): Promise<Post[]>

Fetches the latest posts.

const posts = await discuit.getPosts('latest', 50);

getPost(publicId: string): Promise<Post | null>

Returns the details of a post.

const post = await discuit.getPost('12345');

votePost(postId: string, up: boolean): Promise

Votes a post up or down and returns the post. If already voted, then changes the vote.

await discuit.votePost('12345', true);

getPostComments(publicId: string, next?: string, parentId?: string): Promise<{ comments: Comment[]; next: string }>

Returns the comments for the given post.

const comments = await discuit.getPostComments('12345');

getNotifications(): Promise<Notification[]>

Returns all the user's notifications.

const notifications = await discuit.getNotifications();

markNotificationAsSeen(id: number): Promise

Marks a notification as seen.

await discuit.markNotificationAsSeen(80155);

deleteNotification(id: number): Promise

Deletes a notification.

await discuit.deleteNotification(80155);

deleteAllNotifications(): Promise

Deletes all notifications.

await discuit.deleteAllNotifications();

getComment(id: string): Promise<Comment | null>

Returns the comment with the given id.

const comment = await discuit.getComment('12345');

postComment(publicId: number, content: string): Promise

Submits a comment.

const comment = await discuit.postComment(12345, 'Welcome to the community!');

updateComment(publicId: string, commentId: string, content: string): Promise

Updates a comment.

const comment = await discuit.updateComment('12345', '67890', 'Welcome to the community!');

deleteComment(postId: string, commentId: string): Promise

Deletes a comment.

await discuit.deleteComment('12345', '67890');

watchPosts(communities: string[], callback: (community: string, post: Post) => void): Promise

Watches for new posts.

discuit.watchPosts(['news', 'politics', 'sports'], async (community, post) => {
  console.log(community, post);

  const comment = await discuit.postComment(post.id, 'Welcome to the community!');
  await discuit.deleteComment(comment.postId, comment.id);
});

voteComment(commentId: string, up: boolean): Promise

Votes on a comment.

await discuit.voteComment('12345', true);

getCommunities(): Promise<Community[]>

Returns an array of the site communities.

const communities = await discuit.getCommunities();

getCommunity(communityId: string): Promise<Community | null>

Returns the community with the given id.

const community = await discuit.getCommunity('12346');

updateCommunity(communityId: string, community: Partial): Promise

const community = await discuit.updateCommunity('12346', {
  nsfw: true,
  about: 'My community description.',
});

joinCommunity(communityId: string, leave: boolean): Promise

Make the authenticated user join or leave a community.

await discuit.joinCommunity('12346', false);

getCommunityMods(communityId: string): Promise<User[]>

Returns the moderators of a community.

const mods = await discuit.getCommunityMods('12346');

addCommunityMod(communityId: string, username: string): Promise

Adds a moderator to a community.

await discuit.addCommunityMod('12346', 'username');

deleteCommunityMod(communityId: string, username: string): Promise

Removes a moderator from a community.

await discuit.deleteCommunityMod('12346', 'username');

getCommunityRules(communityId: string): Promise<CommunityRule[]>

Returns the rules of a community.

const rules = await discuit.getCommunityRules('12346');

createCommunityRule(communityId: string, rule: string, description: string): Promise

Creates a rule for a community.

await discuit.createCommunityRule('12346', 'Rule 1', 'This is rule 1.');

updateCommunityRule(communityId: string, ruleId: number, rule: Partial): Promise

Updates a rule for a community.

await discuit.updateCommunityRule('12346', 1, {
  rule: 'Rule 1',
  description: 'This is rule 1.',
    zIndex: 4,
});

deleteCommunityRule(communityId: string, ruleId: number): Promise

Deletes a rule from a community.

await discuit.deleteCommunityRule('12346', 1);