mirror of
https://github.com/sern-handler/handler
synced 2026-06-28 02:32:15 +00:00
plugin data reduction & args changes
This commit is contained in:
@@ -57,7 +57,6 @@ export async function importModule<T>(absPath: string) {
|
||||
|
||||
export async function* readRecursive(dir: string): AsyncGenerator<string> {
|
||||
const files = await readdir(dir, { withFileTypes: true });
|
||||
|
||||
for (const file of files) {
|
||||
const fullPath = path.posix.join(dir, file.name);
|
||||
if (file.isDirectory()) {
|
||||
@@ -65,7 +64,7 @@ export async function* readRecursive(dir: string): AsyncGenerator<string> {
|
||||
yield* readRecursive(fullPath);
|
||||
}
|
||||
} else if (!file.name.startsWith('!')) {
|
||||
yield fullPath;
|
||||
yield "file:///"+path.resolve(fullPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,21 +5,17 @@
|
||||
*/
|
||||
import {
|
||||
concatMap,
|
||||
defaultIfEmpty,
|
||||
EMPTY,
|
||||
every,
|
||||
fromEvent,
|
||||
Observable,
|
||||
of,
|
||||
OperatorFunction,
|
||||
pipe,
|
||||
share,
|
||||
} from 'rxjs';
|
||||
import type { Emitter, ErrorHandling, Logging } from './interfaces';
|
||||
import util from 'node:util';
|
||||
import type { PluginResult } from '../types/core-plugin';
|
||||
import { Result } from 'ts-results-es';
|
||||
import { VoidResult } from '../types/utility';
|
||||
import type { Result } from 'ts-results-es';
|
||||
|
||||
/**
|
||||
* if {src} is true, mapTo V, else ignore
|
||||
* @param item
|
||||
@@ -28,10 +24,6 @@ export function filterMapTo<V>(item: () => V): OperatorFunction<boolean, V> {
|
||||
return concatMap(keep => keep ? of(item()) : EMPTY);
|
||||
}
|
||||
|
||||
interface PluginExecutable {
|
||||
execute: (...args: unknown[]) => PluginResult;
|
||||
};
|
||||
|
||||
|
||||
export const arrayifySource = <T>(src: T) =>
|
||||
Array.isArray(src) ? src : [src];
|
||||
|
||||
@@ -13,6 +13,10 @@ import { Result, Ok, Err } from 'ts-results-es';
|
||||
import * as assert from 'assert';
|
||||
import { ReplyOptions } from '../../types/utility';
|
||||
|
||||
function fmt(msg: string, prefix?: string): string[] {
|
||||
if(!prefix) throw Error("Unable to parse message without prefix");
|
||||
return msg.slice(prefix.length).trim().split(/\s+/g);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
@@ -20,14 +24,25 @@ import { ReplyOptions } from '../../types/utility';
|
||||
* Message and ChatInputCommandInteraction
|
||||
*/
|
||||
export class Context extends CoreContext<Message, ChatInputCommandInteraction> {
|
||||
/*
|
||||
* @Experimental
|
||||
*/
|
||||
prefix: string|undefined;
|
||||
|
||||
get options() {
|
||||
return this.interaction.options;
|
||||
}
|
||||
protected constructor(protected ctx: Result<Message, ChatInputCommandInteraction>) {
|
||||
|
||||
args() {
|
||||
return {
|
||||
message: <T = string[]>() => {
|
||||
const [, ...rest] = fmt(this.message.content, this.prefix);
|
||||
return rest as T;
|
||||
},
|
||||
interaction: () => this.interaction.options
|
||||
}
|
||||
}
|
||||
|
||||
protected constructor(protected ctx: Result<Message, ChatInputCommandInteraction>, prefix?: string) {
|
||||
super(ctx);
|
||||
this.prefix = prefix
|
||||
}
|
||||
|
||||
public get id(): Snowflake {
|
||||
@@ -109,12 +124,12 @@ export class Context extends CoreContext<Message, ChatInputCommandInteraction> {
|
||||
);
|
||||
}
|
||||
|
||||
static override wrap(wrappable: BaseInteraction | Message): Context {
|
||||
static override wrap(wrappable: BaseInteraction | Message, prefix?: string): Context {
|
||||
if ('interaction' in wrappable) {
|
||||
return new Context(Ok(wrappable));
|
||||
return new Context(Ok(wrappable), prefix);
|
||||
}
|
||||
assert.ok(wrappable.isChatInputCommand(), "Context created with bad interaction.");
|
||||
return new Context(Err(wrappable));
|
||||
return new Context(Err(wrappable), prefix);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import type { LogPayload, Logging, ErrorHandling, Emitter } from '../interfaces';
|
||||
import { AnyFunction, UnpackedDependencies } from '../../types/utility';
|
||||
import cron from 'node-cron'
|
||||
import { EventEmitter } from 'events';
|
||||
import type { CronEventCommand, Module } from '../../types/core-modules'
|
||||
import { EventType } from './enums';
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user