mirror of
https://github.com/sern-handler/handler
synced 2026-06-19 06:12:13 +00:00
Compare commits
91 Commits
feat/direc
...
feat/v4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d1680e51fc | ||
|
|
c35337c3cf | ||
|
|
5d0260ab4e | ||
|
|
2014e0ea8e | ||
|
|
482105712b | ||
|
|
870972000d | ||
|
|
210aa41c7e | ||
|
|
c252854954 | ||
|
|
92ca9eb859 | ||
|
|
e0f631a8e2 | ||
|
|
3128b441c5 | ||
|
|
14e80016da | ||
|
|
908d584cc5 | ||
|
|
3e9b9229c8 | ||
|
|
1d8dbb8962 | ||
|
|
7c8e39defb | ||
|
|
90f5ea7bda | ||
|
|
2f778f4dc2 | ||
|
|
9c358e1928 | ||
|
|
c764de12ac | ||
|
|
19abb7cb22 | ||
|
|
30feb790b1 | ||
|
|
222ecd9b61 | ||
|
|
67bb4d4b9f | ||
|
|
bf071b7af4 | ||
|
|
45665292ae | ||
|
|
2120b18c4e | ||
|
|
898fdf52a3 | ||
|
|
c8230334f2 | ||
|
|
792015a64e | ||
|
|
fb418c0675 | ||
|
|
12a8f0c5d7 | ||
|
|
af0f909c44 | ||
|
|
76d9db7b98 | ||
|
|
86dd0cd842 | ||
|
|
1de21b8b37 | ||
|
|
327e56fc1c | ||
|
|
814fc4f01d | ||
|
|
7f4004e043 | ||
|
|
88598b0948 | ||
|
|
e700297bfc | ||
|
|
e0f6a4cd16 | ||
|
|
15511a4868 | ||
|
|
735a9e3816 | ||
|
|
0beeb4c064 | ||
|
|
699adf276c | ||
|
|
960f90c544 | ||
|
|
6717672722 | ||
|
|
ca9b84ba21 | ||
|
|
d3227e5ec1 | ||
|
|
44c072f401 | ||
|
|
203e8c8ecf | ||
|
|
d905f08993 | ||
|
|
0d82658fc5 | ||
|
|
16a84e85d1 | ||
|
|
ec45f80be6 | ||
|
|
eb8ba6799b | ||
|
|
a7aea4be1a | ||
|
|
880311f08c | ||
|
|
0a05cbba3f | ||
|
|
6e2f4b616f | ||
|
|
8554eeaef4 | ||
|
|
4d74e63dd3 | ||
|
|
ffb2872f8b | ||
|
|
08ef80522f | ||
|
|
f762033504 | ||
|
|
cd92b54839 | ||
|
|
b0e9d15fa7 | ||
|
|
545105e45b | ||
|
|
d7ebdb2edc | ||
|
|
d3245c8a0c | ||
|
|
219eda9bf7 | ||
|
|
0488f45677 | ||
|
|
e8cfcc2525 | ||
|
|
d6eedb1b4d | ||
|
|
5b33a9d1bb | ||
|
|
52d1b5a37a | ||
|
|
6c61ae7d6a | ||
|
|
87c5631e57 | ||
|
|
821de65b86 | ||
|
|
e6fba9d8b5 | ||
|
|
071d5eac49 | ||
|
|
68c5f09b46 | ||
|
|
6105f7b4ef | ||
|
|
9faae7eca7 | ||
|
|
f5136ba1ca | ||
|
|
76ee9c6edf | ||
|
|
3d10ee1c59 | ||
|
|
599a02c9df | ||
|
|
6228f53244 | ||
|
|
30230d49c3 |
19
CHANGELOG.md
19
CHANGELOG.md
@@ -1,24 +1,5 @@
|
|||||||
# Changelog
|
# 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)
|
|
||||||
|
|
||||||
|
|
||||||
### Features
|
|
||||||
|
|
||||||
* v4 ([#361](https://github.com/sern-handler/handler/issues/361)) ([9a8904f](https://github.com/sern-handler/handler/commit/9a8904f5aed4fa36b018ad73bbe58049bae33274))
|
|
||||||
|
|
||||||
|
|
||||||
### Miscellaneous Chores
|
|
||||||
|
|
||||||
* release 4.0.0 ([dda0e33](https://github.com/sern-handler/handler/commit/dda0e3395b6704862bfd3fda2a201e2cb9b45d2f))
|
|
||||||
|
|
||||||
## [3.3.4](https://github.com/sern-handler/handler/compare/v3.3.3...v3.3.4) (2024-03-18)
|
## [3.3.4](https://github.com/sern-handler/handler/compare/v3.3.3...v3.3.4) (2024-03-18)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
2
LICENSE
2
LICENSE
@@ -1,6 +1,6 @@
|
|||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2024 sern
|
Copyright (c) 2023 sern
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
- Unleash its full potential with a powerful CLI and awesome plugins.
|
- Unleash its full potential with a powerful CLI and awesome plugins.
|
||||||
|
|
||||||
## 📜 Installation
|
## 📜 Installation
|
||||||
[Start here!!](https://sern.dev/v4/reference/getting-started)
|
[Start here!!](https://sern.dev/docs/guide/walkthrough/new-project)
|
||||||
|
|
||||||
## 👶 Basic Usage
|
## 👶 Basic Usage
|
||||||
<details><summary>ping.ts</summary>
|
<details><summary>ping.ts</summary>
|
||||||
@@ -48,6 +48,7 @@ export default commandModule({
|
|||||||
- [Community Bot](https://github.com/sern-handler/sern-community), the community bot for our [discord server](https://sern.dev/discord).
|
- [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.
|
- [Vinci](https://github.com/SrIzan10/vinci), the bot for Mara Turing.
|
||||||
- [Bask](https://github.com/baskbotml/bask), Listen your favorite artists on Discord.
|
- [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:
|
- [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.
|
- [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.
|
- [SmokinWeed 💨](https://github.com/Peter-MJ-Parker/sern-bud), A fun bot for a small - but growing - server.
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@sern/handler",
|
"name": "@sern/handler",
|
||||||
"packageManager": "yarn@3.5.0",
|
"packageManager": "yarn@3.5.0",
|
||||||
"version": "4.0.1",
|
"version": "4.0.0",
|
||||||
"description": "A complete, customizable, typesafe, & reactive framework for discord bots.",
|
"description": "A complete, customizable, typesafe, & reactive framework for discord bots.",
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
"module": "./dist/index.js",
|
"module": "./dist/index.js",
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import { type Dirent, existsSync } from 'node:fs';
|
import { existsSync } from 'node:fs';
|
||||||
import { readdir } from 'fs/promises';
|
import { readdir } from 'fs/promises';
|
||||||
|
import assert from 'node:assert';
|
||||||
import * as Id from './id'
|
import * as Id from './id'
|
||||||
import { Module } from '../types/core-modules';
|
import { Module } from '../types/core-modules';
|
||||||
|
|
||||||
@@ -37,9 +38,8 @@ export async function importModule<T>(absPath: string) {
|
|||||||
let fileModule = await import(absPath);
|
let fileModule = await import(absPath);
|
||||||
|
|
||||||
let commandModule: Module = fileModule.default;
|
let commandModule: Module = fileModule.default;
|
||||||
if(!commandModule) {
|
|
||||||
throw Error(`No default export @ ${absPath}`);
|
assert(commandModule , `No default export @ ${absPath}`);
|
||||||
}
|
|
||||||
if ('default' in commandModule) {
|
if ('default' in commandModule) {
|
||||||
commandModule = commandModule.default as Module;
|
commandModule = commandModule.default as Module;
|
||||||
}
|
}
|
||||||
@@ -53,18 +53,16 @@ export async function importModule<T>(absPath: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export async function* readRecursive(dir: string, directoryPlugins: string[] = []): AsyncGenerator<[string, string[]]> {
|
export async function* readRecursive(dir: string): AsyncGenerator<string> {
|
||||||
const files = await readdir(dir, { withFileTypes: true });
|
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) {
|
for (const file of files) {
|
||||||
const fullPath = path.posix.join(dir, file.name);
|
const fullPath = path.posix.join(dir, file.name);
|
||||||
const plugins = pluginFile ? [...directoryPlugins, path.posix.join(dir, pluginFile.name) ] : directoryPlugins
|
|
||||||
if (file.isDirectory()) {
|
if (file.isDirectory()) {
|
||||||
if (!file.name.startsWith('!')) {
|
if (!file.name.startsWith('!')) {
|
||||||
yield* readRecursive(fullPath, plugins);
|
yield* readRecursive(fullPath);
|
||||||
}
|
}
|
||||||
} else if (!file.name.startsWith('!')) {
|
} else if (!file.name.startsWith('!')) {
|
||||||
yield ["file:///"+path.resolve(fullPath), plugins];
|
yield "file:///"+path.resolve(fullPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,8 +17,7 @@ export default async function(dir: string, deps : UnpackedDependencies) {
|
|||||||
|
|
||||||
// https://observablehq.com/@ehouais/multiple-promises-as-an-async-generator
|
// https://observablehq.com/@ehouais/multiple-promises-as-an-async-generator
|
||||||
// possibly optimize to concurrently import modules
|
// possibly optimize to concurrently import modules
|
||||||
for await (const [path, directoryPlugins] of Files.readRecursive(dir)) {
|
for await (const path of Files.readRecursive(dir)) {
|
||||||
console.log(path, directoryPlugins)
|
|
||||||
let { module } = await Files.importModule<Module>(path);
|
let { module } = await Files.importModule<Module>(path);
|
||||||
const validType = module.type >= CommandType.Text && module.type <= CommandType.ChannelSelect;
|
const validType = module.type >= CommandType.Text && module.type <= CommandType.ChannelSelect;
|
||||||
if(!validType) {
|
if(!validType) {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { fileURLToPath } from "url";
|
|||||||
|
|
||||||
export const registerTasks = async (tasksPath: string, deps: UnpackedDependencies) => {
|
export const registerTasks = async (tasksPath: string, deps: UnpackedDependencies) => {
|
||||||
const taskManager = deps['@sern/scheduler']
|
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);
|
let { module } = await Files.importModule<ScheduledTask>(f);
|
||||||
//module.name is assigned by Files.importModule<>
|
//module.name is assigned by Files.importModule<>
|
||||||
// the id created for the task is unique
|
// the id created for the task is unique
|
||||||
|
|||||||
@@ -20,8 +20,7 @@ const intoDispatcher = (deps: UnpackedDependencies) =>
|
|||||||
|
|
||||||
export default async function(deps: UnpackedDependencies, eventDir: string) {
|
export default async function(deps: UnpackedDependencies, eventDir: string) {
|
||||||
const eventModules: EventModule[] = [];
|
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);
|
let { module } = await Files.importModule<Module>(path);
|
||||||
await callInitPlugins(module, deps)
|
await callInitPlugins(module, deps)
|
||||||
eventModules.push(module as EventModule);
|
eventModules.push(module as EventModule);
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ export interface ModalSubmitCommand extends Module {
|
|||||||
|
|
||||||
export interface AutocompleteCommand {
|
export interface AutocompleteCommand {
|
||||||
onEvent?: ControlPlugin[];
|
onEvent?: ControlPlugin[];
|
||||||
execute: (ctx: AutocompleteInteraction, tbd: SDT) => Awaitable<unknown>;
|
execute: (ctx: AutocompleteInteraction) => Awaitable<unknown>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DiscordEventCommand<T extends keyof ClientEvents = keyof ClientEvents>
|
export interface DiscordEventCommand<T extends keyof ClientEvents = keyof ClientEvents>
|
||||||
|
|||||||
Reference in New Issue
Block a user