An open API service indexing awesome lists of open source software.

https://github.com/leonardssh/oasis

An object oriented Discordeno framework
https://github.com/leonardssh/oasis

Last synced: 12 months ago
JSON representation

An object oriented Discordeno framework

Awesome Lists containing this project

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

```ts
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)

```ts
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](https://github.com/discordeno/discordeno) library and [website](https://discordeno.mod.land/)
- the Discordeno [Discord server](https://discord.gg/ddeno) 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:

#### 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