Skip to main content

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'];

    // declare string option 'question' as required
    @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
    }

    // run 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) {
        // if is bot 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;
    }

    // deno-fmt-ignore
    const [command] = commands.get(commandName) ?? commands.get(commandAliases.get(commandName) ?? '') ?? [];

    // check if command exists
    if (command) {
        command.run(ctx); // do not await so we can run commands "en paralelo"
    }

    messageCreate(bot, message);
};

Installation

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

Useful resources

TODO’s:

  • adding more builders
  • make a CLI