GitXplorerGitXplorer
b

bot-base

public
0 stars
0 forks
1 issues

Commits

List of commits on branch master.
Unverified
f674c7229252fbce25aed0378739e7414e6f84a0

Expose getPrefix

bbraxtonhall committed 2 years ago
Unverified
18299f82cc3c0ce0b435b25e1bf3fa83934f901c

1.1.1-rc1

bbraxtonhall committed 2 years ago
Verified
5fcf02de8da8b76a427feba15f6773d02c6ba9f1

1.1.0 (#3)

bbraxtonhall committed 2 years ago
Unverified
8b86a75ee603203477b950220081db019a668ba6

Expose partials from Discord API

bbraxtonhall committed 3 years ago
Unverified
54c09f825648ff49b9e488ee28e074e6269544ac

Support nested directory batch imports

bbraxtonhall committed 3 years ago
Unverified
2e5737405cfb14feced6845d8ca17d79254da7eb

Add Log to the API

bbraxtonhall committed 3 years ago

README

The README file for this repository.

bot-base

Example

App

import {startDiscord} from "@ubccpsc310/bot-base";
import {Intents} from "discord.js";

startDiscord({
	commandDirectory: `${__dirname}/commands`,
	listenerDirectory: `${__dirname}/listeners`,
	intents: [Intents.FLAGS.GUILDS],
	token: process.env.DISCORD_BOT_TOKEN,
});

Command

import {Command} from "@ubccpsc310/bot-base";
import {Client, Message} from "discord.js";

const echo: Command = {
	name: "echo",
	description: "Repeats a message",
	usage: "echo <message>?",
	procedure(client: Client, message: Message, args: string[]) {
		let reply;
		if (args.length > 0) {
			reply = args.join(" ");
		} else {
			reply = "... echo";
		}
		return message.channel.send(reply);
	},
};

export default echo;

Listener

import {Listener, Log} from "@ubccpsc310/bot-base";
import {Client} from "discord.js";

const ready: Listener<"ready"> = {
	event: "ready",
	procedure(client: Client) {
		Log.info("Bot started 👀");
	},
};

export default ready;

API

/**
 * The main function!
 * Registers commands and listeners, and logs into discord
 * @param options are defined below
 * @return Discord.js Client
 */
function startDiscord(options: Options): Promise<Client> {
	// ...
}

/**
 * Returns a db object for persisting/reading data
 */
function getDatabaseController(): DatabaseController {
	// ...
}

/**
 * Logging object used in place of `console`
 * Only prints to console if logging level permits,
 * set by process.env variable `LOG_LEVEL`
 * which should be DEBUG | INFO | WARN | ERROR | NONE
 * (defaults to NONE)
 */
const Log: {
	debug(...args: any[]): void;
	info(...args: any[]): void;
	warn(...args: any[]): void;
	error(...args: any[]): void;
} = {
	/* ... */
};

interface Options {
	// Directory where Command ts/js files live
	// All files in this directory should have
	// a default export that is a Command
	commandDirectory: string;

	// Directory where Listener ts/js files live
	// All files in this directory should have
	// a default export that is a Listener
	listenerDirectory: string;

	// See https://discord.js.org/#/docs/main/stable/typedef/IntentsResolvable
	intents: IntentsResolvable;

	// Bot token found in Discord's
	// developer portal
	token: string;
}

interface Command {
	// name that users will invoke the command with
	name: string;
	description: string;
	// example of how to use the command
	usage: string;
	// procedure that should be invoked whenever command is used
	procedure: (client: Client, message: Message, args: string[]) => void;
}

// ClientEvents comes from discord.js
interface Listener<T extends keyof ClientEvents> {
	// example "message" or "voiceStateUpdate"
	event: T;
	// procedure that should be invoked whenever event occurs
	procedure: (client: Client, ...args: ClientEvents[T]) => void;
}

interface DatabaseController {
	get<T extends Entity>(collection: string, id: string): Promise<T>;
	set<T extends Entity>(collection: string, value: T): Promise<void>;
	scan<T extends Entity>(collection: string, query: any): Promise<T[]>;
	delete(collection: string, id: string): Promise<void>;
}

interface Entity {
	id: string;
}