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

@oasisjs/framework

v2.1.0

Published

Bleeding edge object oriented Discordeno framework for creating bots

Downloads

2

Readme

Oasis

Bleeding edge object oriented Discordeno framework for creating bots Oasis is minimal by design and it does not ship any cache layer so you can implement your own

Oasis is written Fully in typescript

Efficient & Cross-platform

Oasis is based on Discordeno, a lightweight Discord library for building mostly big Discord bots Since Discordeno is cross platform Oasis ships a Node version by default which is a lot more bleeding-edge! npm install oasis-framework

Creating commands with Deno

Oasis makes it easier to write commands that work on both messages and interactions Oasis avoids the use inheriterance and prefers composition and middlewares

import { Argument, Command, Context } from 'oasis';

// define responses
const responses = [
    'It is certain',
    'It is decidedly so',
    'Without a doubt',
    'Yes, definitely',
    'You may rely on it',
    'Most likely',
    'Outlook good',
    'Yes',
];

@Command
class EightBall {
    readonly data = {
        name: `${responses.length}ball`,
        description: 'Ask the magic 8ball a question',
    };

    readonly aliases = ['ball'];

    @Argument('The question', true)
    declare question: string; // it works without 'declare' if you compile down to ES2020

    // get all options
    get options(): unknown[] {
        return [this.question]; // first argument in the command
    }

    async run(ctx: Context) {
        const question = ctx.options.getString(0) ?? ctx.options.getString('question');
        const response = responses[Math.floor(Math.random() * responses.length)];

        if (question) {
            await ctx.respond({ with: `Question: ${question} | Reply: ${response}` });
        }
    }
}

How make a simple middleware to execute commands

Oasis is minimal by design, so you can make your own Context class that suits your needs heres a minimal example of how to write a middleware (no typescript needed)

const PREFIX = '->';
const { interactionCreate, messageCreate } = bot.events;

bot.events.interactionCreate = (bot, interaction) => {
    if (interaction.user.toggles.bot) {
        interactionCreate(bot, interaction);
        return;
    }

    const ctx = new Context(PREFIX, bot, undefined, interaction);
    const commandName = ctx.getCommandName();

    if (!commandName) {
        return;
    }

    const [command] = commands.get(commandName) ?? [];

    if (command) {
        command.run(ctx);
    }

    interactionCreate(bot, interaction);
};

bot.events.messageCreate = (bot, message) => {
    if (message.isBot) {
        // forward the event
        messageCreate(bot, message);
        return;
    }

    // make sure to import Context from oasis
    const ctx = new Context(PREFIX, bot, message, undefined);
    const commandName = ctx.getCommandName();

    if (!commandName) {
        return;
    }

    const [command] = commands.get(commandName) ?? commands.get(commandAliases.get(commandName) ?? '') ?? [];

    if (command) {
        command.run(ctx);
    }

    messageCreate(bot, message);
};

Installation

Deno: deno cache https://deno.land/x/oasis/mod.ts Node: npm install oasis-framework

Useful resources

  • the Discordeno library and website
  • the Discordeno Discord server so you can ask me for help
  • Cache layer for Discordeno https://github.com/discordeno/discordeno/blob/main/plugins/cache
  • Bot using the Oasis framework (not released yet) https://github.com/yuzudev/akebi

TODO's:

  • adding more builders
  • make a CLI

Changelog:

2.0.0

  • Refactor the entire codebase
  • better support for Subcommands
  • Testing
  • 2 new contrib/ files
  • bug fix

1.6.X

  • hotfixes and new contrib file

1.5.X

  • new contrib file
  • bug fixes

1.4.X

  • remove the need for an id when instantiating a bot
  • add the OasisClient class
  • latest bleeding edge version of Discordeno (rc45)

1.3.X

  • remove dead code
  • latest bleeding edge version of Discordeno (rc39)

1.2.X

  • remove the logger plugin