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

discord-activity

v1.0.4

Published

discord-activity is a tool to create discord bot more easily.

Downloads

4

Readme

Discord Activity

discord-activity is a tool to create discord bot more easily.

Installation

$ npm install discord-activity

Summary

General Info

With discord-activity you can create a message with a reaction that will serve as a button, you can also put states in the messages e.g. {{myState}} to create a dynamic message that changes according to the status of a game server, a quiz, a bot for moderation, see example below.

Exemple

Exemple Game Server

this is an example to display the status of a game server, full exmple here

const { DiscordActivity } = require('discord-activity');
const activityClient = new DiscordActivity();

var mainActivity = activityClient.createActivity({
    isActive: true
});

var component = mainActivity.createComponent('messageEmbed');
component.setTitle("My garry's mod server");
component.addField('Status', 'Server is {{serverState}} with {{slot}} players connected out of {{max_slot}}');
component.addField('CPU Usage', '{{cpu}}', true);
component.addField('RAM Usage', '{{ram}}', true);

// Set color ex: is started green or red if not
component.setColor(0x00FF00); // set color to green

// set default states
component.setState('cpu', '0%');
component.setState('ram', '0G');
component.setState('slot', '0');
component.setState('max_slot', '100');
component.setState('serverState', 'on');

var startButton = component.addButton('✅');
stopButton.on('click', () => MyServerControler.startServer());

var stopButton = component.addButton('❌');
stopButton.on('click', () => MyServerControler.stopServer());

activityClient.on('ready', async () => {
    console.log('Client ready');

    MyServerControler.on('data', (data) => {
        if (data.isOnline) {
            component.setState('cpu', data.cpuUsage);
            component.setState('ram', data.ramUsage);
            component.setState('slot', data.slot);
            component.setState('max_slot', data.maxSlot);
            component.setState('serverState', 'on');
            component.setColor(0x00FF00); // set color to green
        } else {
            component.setState('cpu', 'N/A');
            component.setState('ram', 'N/A');
            component.setState('slot', 'N/A');
            component.setState('max_slot', 'N/A');
            component.setState('serverState', 'off');
            component.setColor(0xFF0000); // set color to red
        }
    });
});

activityClient.login(process.env.TOKEN, process.env.CHANNEL_ID);

Exemple Help Menu

You can also create messages that will display all available commands., full exmple here

const { DiscordActivity } = require('discord-activity');
const Discord = require('discord.js');
const activityClient = new DiscordActivity();

var mainActivity = activityClient.createActivity({
    isActive: true
});

var component = mainActivity.createComponent('messageEmbed', {
    isHidden: true
});
component.setTitle("Help Menu");
component.setAuthor("My server name");
component.setThumbnail('https://github.com/google/material-design-icons/raw/master/png/action/help/materialicons/24dp/2x/baseline_help_black_24dp.png');
component.setDescription('Display all available commands');
component.addField('\u200b', '\u200b');
component.addField('!help', 'Show this menu', true);
component.addField('!ban :username:', 'Ban Someone', true);
component.addField('!mute :username:', 'Mute Someone', true);
component.addField('!kick :username:', 'Exclude Someone', true);

var closeButton = component.addButton('❌');
closeButton.setCooldown(1000);

closeButton.on('click', (event) => {
    console.log('Close button click by', event.user.username);

    component.setVisibile(false);
});

activityClient.on('ready', async () => {
    console.log('Client ready');
});

activityClient.on('error', async (err) => {
    console.log('Client error');
    console.error(err);
});

activityClient.on('message', (message) => {
    if (message.content === '!help') {
        component.setVisibile(true);
    }
});

activityClient.login(process.env.TOKEN, process.env.CHANNEL_ID);

Documentation

there is no documentation yet but I am working on it

License

MIT