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

dsc-ac

v1.3.3

Published

Utility for djs -> acode.

Downloads

19

Readme

dsc-ac

Utility for djs -> acode.

Prerequisites

  • Discord Bot Token and Client ID
  • acode's lib import
  • index.js file
  • Handlers JSON in the following sample format:
{
    "READY" : "/functions/events/discord/ready/ready.js",
    "BOT_MENTION": "/functions/events/discord/message/create/bot_mention/bot_mention.js",
    "PREFIX": {
        "!ping" : "/functions/events/discord/message/create/prefix/ping.js",
        "!button" : "/functions/events/discord/message/create/prefix/button.js",
        "!selectmenu" : "/functions/events/discord/message/create/prefix/selectmenu.js"
    },
    "APPLICATION_COMMAND": {
        "ping": "/functions/events/discord/command/ping.js"
    },
    "MESSAGE_COMPONENT": {
        "button-id": "/functions/events/discord/message/button/button.js",
        "selectmenu-id": "/functions/events/discord/message/selectmenu/selectmenu.js"
    },
    "MODAL_SUBMIT": {
        "ping-modal": "/functions/events/discord/modal/ping.js"
    }
}
  • Note: First-level keys shall not be modified.
  • First-level keys are the event triggers, except for INTERACTION_CREATE and MESSAGE_CREATE.

Initialization

  • Import both discordJS and lib
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const { Client, GatewayIntentBits, ActivityType } = require("discord.js");

const client = new Client({
  intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildMessages,
    GatewayIntentBits.MessageContent,
    GatewayIntentBits.GuildMembers
  ]
});

Usage

Files

  • Modules for Message Create events should have two arguments.
module.exports = async (lib, context) => {
    //your custom code here
}
  • Modules for Interaction events should have at least two arguments. interaction is needed if Interaction from this module will be used.
module.exports = async (lib, context, interaction) => {
    //your custom code here
}

Command Builder

  • Create a json file containing your command details. Strictly follow the format below:
{
    "global_commands" : [
        {
            "name": "ping",
            "description": "get pong!"
        }
    ],
    "guild_commands" : {
        "guild_id": "GUILD ID HERE",
        "commands": [
            {
                "name": "pong",
                "description": "if you want to get pong!"
            }
        ]
    }
}
  • After you initialize the CommandBuilder(), call its init() containing your json file path with respect to the index.js. Example directory:
/Discord Bot
    ├── index.js
    ├── commands.json
    └── commands
        └── ping.js
const { CommandBuilder } = require('dsc-ac');

const commandBuilder = new CommandBuilder(DISCORD_BOT_TOKEN, CLIENT_ID);

commandBuilder.init('/commands.json');

Handler

const { Handler } = require('dsc-ac');

const handlers_json = require('./handlers.json');
const handler = new Handler(handlers_json, CLIENT_ID, lib, interaction);

client.on('raw', async (data) => {
    await handler.process(data);
});

Note: interaction is optional for the Handler. This is needed if you are going to use the Interaction() properties.

Interactions

  • Initialization
const { Interaction } = require('dsc-ac');

const interaction = new Interaction(DISCORD_BOT_TOKEN, CLIENT_ID);
  • Interaction file
module.exports = async (lib, context, interaction) => {
    await interaction.responses.ephemeral.create({
        id: context.params.event.id,
        token: `${context.params.event.token}`,
        response_type: 'CHANNEL_MESSAGE_WITH_SOURCE',
        content: `pong!`
    });
}

Note: id should always be included in the parameters of responses.

  • Response Types
PONG
CHANNEL_MESSAGE_WITH_SOURCE
DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE
DEFERRED_UPDATE_MESSAGE
UPDATE_MESSAGE
APPLICATION_COMMAND_AUTOCOMPLETE_RESULT
MODAL
  • Supported Interactions
/
└── responses
    ├── create
    ├── ephemeral
    │   └── create
    └── modals
        └── create

requireModule()

  • No params
const { requireModule } = require('dsc-ac');

await requireModule('/directory/file.js');
  • With params
const { requireModule } = require('dsc-ac');

const _module = await requireModule('/directory/file.js');

await _module("Hello World!");
  • Module file:
module.exports = async function (params) {
    console.log(params);
}

Support

Need help? Contact us via Discord.