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

ext-manager

v1.5.0

Published

A package to manage an extensions for event listeners or discord bot commands with ease

Downloads

26

Readme

ext-manager

A package to manage extensions for event listeners or discord bot commands with ease!

How to use? Easy!

Install using NPM

npm install ext-manager

Example of using event manager

at the main file

const { EventEmitter } = require('events')
const { EventManager } = require('ext-manager')

const eventEmitter = new EventEmitter()
const eventManager = new EventManager(eventEmitter)

eventManager.loadExtension('ext.js') //Load ext.js file in same directory

eventEmitter.emit('test', 'TEST!')

eventManager.reloadExtension('ext.js') //Reload ext.js extension if there is any changes
eventManager.unloadExtension('ext.js') //Unload ext.js extension

at ext.js

module.exports = {
    name: 'test', //the event listener name
    once: true, //event listener only works for once
    main(str) {
        console.log(str)
    } //the main function
}

Example of using bot

at the main file

const { Bot } = require('ext-manager')

const bot = new Bot({
    prefix: '!', //the bot prefix
    respondBot: false, //bot cannot respond to another bot
    ownerBypass: true, //owner of the bot can bypass any command filter
    insensitive: true, //command are case insensitive
    filters: [] //adding a custom filter to commands
})

bot.loadExtension('commands.js')
bot.loadExtension('memberjoin.js')

bot.login('BOT_TOKEN')

at commands.js

module.exports = {
    type: 'command', //the type of the ext
    name: 'ping', //the command name
    description: 'show the bot ping.', //the command description
    async main(message, args, prefix) {
        const now = Date.now()
        const msg = await message.channel.send('Pinging...')

        msg.edit(`Pong! my ping is ${Date.now() - now}ms`)
    } //the command code
}

at memberjoin.js

module.exports = {
    type: 'event', //the type of the ext
    name: 'guildMemberAdd', //the event listener name
    async main(member) {
        const channel = member.guild.channels.cache.first()

        await channel.send(`A member has joined, the name is ${member.user.tag}`)
    } //the main function
}

Methods

//Load an extension
loadExtension(String)

//Reload an extension
reloadExtension(String)

//Unload an extension
unloadExtension(String)

You can put events or commands in an array to make it as a group

example

module.exports = [{
    name: 'test',
    once: true,
    main(str) {
        console.log(str)
    }
}, {
    name: 'error',
    main(err) {
        console.error('An error occured', err)
    }
}]

EventManager parameters

new EventManager(eventEmitter)

Bot parameters

new Bot({
    prefix: Array<Function || String> || Function || String,
    owner: Array,
    respondBot: Boolean,
    ownerBypass: Boolean,
    insensitive: Boolean,
    filters: Array,
    noPermission: String,
    helpCommand: {
        embed: Discord.MessageEmbed,
        hideDuplicate: Boolean,
        decorator: {
            group: {
                title: String,
                separator: String
            },
            command: {
                title: String,
                separator: String,
                notFound: String
            }
        }
    },
    extensionCommand: {
        embed: Discord.MessageEmbed
    },
    evalCommand: {
        embed: Discord.MessageEmbed
    },
    ...Discord.ClientOptions
})

Event property

module.exports = {
    type: 'event', //only for discord bot extension
    name: String,
    once: Boolean,
    main: Function
}

Command property

module.exports = {
    type: 'command',
    category: String,
    name: String,
    aliases: Array,
    description: String,
    guildOnly: String,
    ownerOnly: String,
    usage: String,
    notes: String,
    cooldown: {
        limit: Number,
        timeout: Number,
        target: 'guild' || 'channel' || 'author',
        response: String
    },
    permission: {
        type: 'guild' || 'channel',
        optional: Boolean,
        perms: Discord.Permissions || Array<String || Number> || String || Number,
        response: String
    },
    botPermission: {
        type: 'guild' || 'channel',
        optional: Boolean,
        perms: Discord.Permissions || Array<String || Number> || String || Number,
        response: String
    },
    args: [{
        position: Number,
        response: String,
        prompt: {
            timeout: Number,
            cancelled: String,
            failed: String,
            timedOut: String
        }
    }],
    main: Function
}

Notes

- Node version must be not less than v10.x to avoid any bugs
- Discord.js version must be 12.x or so

Example of adding help command

at the main file

const { Bot } = require('ext-manager')

const bot = new Bot({
    ...BotParameters
})

bot.loadExtension('help.js')

bot.login('BOT_TOKEN')

at help.js

const { Commands } = require('ext-manager')
const { HelpCommand } = Commands

module.exports = new HelpCommand({
    ...CommandProperty
})

Example of adding extension command

at the main file

const { Bot } = require('ext-manager')

const bot = new Bot({
    ...BotParameters
})

bot.loadExtension('extension.js')

bot.login('BOT_TOKEN')

at extension.js

const { Commands } = require('ext-manager')
const { ExtensionCommand } = Commands

module.exports = new ExtensionCommand({
    ...CommandProperty
})

Example of adding eval command

at the main file

const { Bot } = require('ext-manager')

const bot = new Bot({
    ...BotParameters
})

bot.loadExtension('eval.js')

bot.login('BOT_TOKEN')

at eval.js

const { Commands } = require('ext-manager')
const { EvalCommand } = Commands

module.exports = new EvalCommand({
    ...CommandProperty
})