Compare commits

..

6 Commits

Author SHA1 Message Date
Jacob Nguyen
8ec59a3443 fix up some bugs and debugging 2024-08-11 01:48:24 -05:00
Jacob Nguyen
3e668090d8 initial prototype 2024-08-11 01:27:49 -05:00
xxDeveloper
3755b95b1a chore: Update LICENSE year (#365) 2024-08-06 10:56:25 -05:00
Jacob Nguyen
06807ea77f Update README.md 2024-07-19 01:32:22 -05:00
github-actions[bot]
3fd3f1c236 chore(main): release 4.0.1 (#364)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2024-07-18 22:55:59 -05:00
Peter-MJ-Parker
92623d2914 fix: add SDT typings to autocomplete commands (#363) 2024-07-18 22:54:23 -05:00
9 changed files with 25 additions and 15 deletions

View File

@@ -1,5 +1,12 @@
# Changelog
## [4.0.1](https://github.com/sern-handler/handler/compare/v4.0.0...v4.0.1) (2024-07-19)
### Bug Fixes
* add SDT typings to autocomplete commands ([#363](https://github.com/sern-handler/handler/issues/363)) ([92623d2](https://github.com/sern-handler/handler/commit/92623d2914fb80e31365f06cf896bb37f36fc814))
## [4.0.0](https://github.com/sern-handler/handler/compare/v3.3.4...v4.0.0) (2024-07-18)

View File

@@ -1,6 +1,6 @@
MIT License
Copyright (c) 2023 sern
Copyright (c) 2024 sern
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -25,7 +25,7 @@
- Unleash its full potential with a powerful CLI and awesome plugins.
## 📜 Installation
[Start here!!](https://sern.dev/docs/guide/walkthrough/new-project)
[Start here!!](https://sern.dev/v4/reference/getting-started)
## 👶 Basic Usage
<details><summary>ping.ts</summary>
@@ -48,7 +48,6 @@ export default commandModule({
- [Community Bot](https://github.com/sern-handler/sern-community), the community bot for our [discord server](https://sern.dev/discord).
- [Vinci](https://github.com/SrIzan10/vinci), the bot for Mara Turing.
- [Bask](https://github.com/baskbotml/bask), Listen your favorite artists on Discord.
- [ava](https://github.com/SrIzan10/ava), A discord bot that plays KNGI and Gensokyo Radio.
- [Murayama](https://github.com/murayamabot/murayama), :pepega:
- [Protector (WIP)](https://github.com/needhamgary/Protector), Just a simple bot to help enhance a private minecraft server.
- [SmokinWeed 💨](https://github.com/Peter-MJ-Parker/sern-bud), A fun bot for a small - but growing - server.

View File

@@ -1,7 +1,7 @@
{
"name": "@sern/handler",
"packageManager": "yarn@3.5.0",
"version": "4.0.0",
"version": "4.0.1",
"description": "A complete, customizable, typesafe, & reactive framework for discord bots.",
"main": "./dist/index.js",
"module": "./dist/index.js",

View File

@@ -1,7 +1,6 @@
import path from 'node:path';
import { existsSync } from 'node:fs';
import { type Dirent, existsSync } from 'node:fs';
import { readdir } from 'fs/promises';
import assert from 'node:assert';
import * as Id from './id'
import { Module } from '../types/core-modules';
@@ -38,8 +37,9 @@ export async function importModule<T>(absPath: string) {
let fileModule = await import(absPath);
let commandModule: Module = fileModule.default;
assert(commandModule , `No default export @ ${absPath}`);
if(!commandModule) {
throw Error(`No default export @ ${absPath}`);
}
if ('default' in commandModule) {
commandModule = commandModule.default as Module;
}
@@ -53,16 +53,18 @@ export async function importModule<T>(absPath: string) {
}
export async function* readRecursive(dir: string): AsyncGenerator<string> {
export async function* readRecursive(dir: string, directoryPlugins: string[] = []): AsyncGenerator<[string, string[]]> {
const files = await readdir(dir, { withFileTypes: true });
const pluginFile = files.find(file => file.isFile() && file.name.startsWith('!plugins')) as Dirent;
for (const file of files) {
const fullPath = path.posix.join(dir, file.name);
const plugins = pluginFile ? [...directoryPlugins, path.posix.join(dir, pluginFile.name) ] : directoryPlugins
if (file.isDirectory()) {
if (!file.name.startsWith('!')) {
yield* readRecursive(fullPath);
yield* readRecursive(fullPath, plugins);
}
} else if (!file.name.startsWith('!')) {
yield "file:///"+path.resolve(fullPath);
yield ["file:///"+path.resolve(fullPath), plugins];
}
}
}

View File

@@ -17,7 +17,8 @@ export default async function(dir: string, deps : UnpackedDependencies) {
// https://observablehq.com/@ehouais/multiple-promises-as-an-async-generator
// possibly optimize to concurrently import modules
for await (const path of Files.readRecursive(dir)) {
for await (const [path, directoryPlugins] of Files.readRecursive(dir)) {
console.log(path, directoryPlugins)
let { module } = await Files.importModule<Module>(path);
const validType = module.type >= CommandType.Text && module.type <= CommandType.ChannelSelect;
if(!validType) {

View File

@@ -6,7 +6,7 @@ import { fileURLToPath } from "url";
export const registerTasks = async (tasksPath: string, deps: UnpackedDependencies) => {
const taskManager = deps['@sern/scheduler']
for await (const f of Files.readRecursive(tasksPath)) {
for await (const [f, _] of Files.readRecursive(tasksPath)) {
let { module } = await Files.importModule<ScheduledTask>(f);
//module.name is assigned by Files.importModule<>
// the id created for the task is unique

View File

@@ -20,7 +20,8 @@ const intoDispatcher = (deps: UnpackedDependencies) =>
export default async function(deps: UnpackedDependencies, eventDir: string) {
const eventModules: EventModule[] = [];
for await (const path of Files.readRecursive(eventDir)) {
for await (const [path, _] of Files.readRecursive(eventDir)) {
console.log(path, _)
let { module } = await Files.importModule<Module>(path);
await callInitPlugins(module, deps)
eventModules.push(module as EventModule);

View File

@@ -107,7 +107,7 @@ export interface ModalSubmitCommand extends Module {
export interface AutocompleteCommand {
onEvent?: ControlPlugin[];
execute: (ctx: AutocompleteInteraction) => Awaitable<unknown>;
execute: (ctx: AutocompleteInteraction, tbd: SDT) => Awaitable<unknown>;
}
export interface DiscordEventCommand<T extends keyof ClientEvents = keyof ClientEvents>