@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