mirror of
https://github.com/sern-handler/handler
synced 2026-06-06 01:16:55 +00:00
refact,simplf
This commit is contained in:
@@ -37,6 +37,6 @@ export function CommandControlPlugin<I extends CommandType>(
|
||||
* The object passed into every plugin to control a command's behavior
|
||||
*/
|
||||
export const controller = {
|
||||
next: (val: unknown=undefined) => Ok(val),
|
||||
next: (val?: Record<string,unknown>) => Ok(val),
|
||||
stop: (val?: string) => Err(val),
|
||||
};
|
||||
|
||||
@@ -4,7 +4,7 @@ import { CommandType, EventType } from './structures/enums';
|
||||
const parseParams = (event: { customId: string }, id: string, append: string) => {
|
||||
const hasSlash = event.customId.indexOf('/')
|
||||
if(hasSlash === -1) {
|
||||
return { id:id+append };
|
||||
return { id:event.customId+append };
|
||||
}
|
||||
const baseid = event.customId.substring(0, hasSlash);
|
||||
const params = event.customId.substring(hasSlash+1);
|
||||
|
||||
@@ -6,7 +6,7 @@ import * as Id from './id'
|
||||
import { Module } from '../types/core-modules';
|
||||
|
||||
export const parseCallsite = (site: string) => {
|
||||
const pathobj = path.parse(site.replace(/file:\\?/, "")
|
||||
const pathobj = path.posix.parse(site.replace(/file:\\?/, "")
|
||||
.split(path.sep)
|
||||
.join(path.posix.sep))
|
||||
return { name: pathobj.name,
|
||||
|
||||
@@ -193,11 +193,11 @@ type CommandModuleNoPlugins = {
|
||||
[T in CommandType]: Omit<CommandModuleDefs[T], 'plugins' | 'onEvent' | 'meta'>;
|
||||
};
|
||||
type EventModulesNoPlugins = {
|
||||
[T in EventType]: Omit<EventModuleDefs[T], 'plugins' | 'onEvent' | 'meta'> & { once?: boolean };
|
||||
[T in EventType]: Omit<EventModuleDefs[T], 'plugins' | 'onEvent' | 'meta'> ;
|
||||
};
|
||||
|
||||
export type InputEvent = {
|
||||
[T in EventType]: EventModulesNoPlugins[T];
|
||||
[T in EventType]: EventModulesNoPlugins[T] & { once?: boolean };
|
||||
}[EventType];
|
||||
|
||||
export type InputCommand = {
|
||||
|
||||
@@ -10,15 +10,28 @@ describe('module-loading', () => {
|
||||
const callsiteinfo = Files.parseCallsite(fname)
|
||||
expect(callsiteinfo.name).toBe("ping")
|
||||
})
|
||||
it('should get the filename of the commandmodule (windows, cjs)', () => {
|
||||
const fname = "C:\\pooba\\Projects\\sern\\halibu\\dist\\commands\\ping.js"
|
||||
it('should get filename of commandmodule (linux, cjs)', () => {
|
||||
const fname = "file:///home/pooba/Projects/sern/halibu/dist/commands/ping.js"
|
||||
const callsiteinfo = Files.parseCallsite(fname)
|
||||
expect(callsiteinfo.name).toEqual("ping");
|
||||
expect(callsiteinfo.name).toBe("ping")
|
||||
|
||||
})
|
||||
it('should get the filename of the commandmodule (windows, cjs)', () => {
|
||||
//this test case is impossible on linux.
|
||||
if(process.platform == 'win32') {
|
||||
const fname = "C:\\pooba\\Projects\\sern\\halibu\\dist\\commands\\ping.js"
|
||||
const callsiteinfo = Files.parseCallsite(fname)
|
||||
expect(callsiteinfo.name).toEqual("ping");
|
||||
}
|
||||
})
|
||||
it('should get filename of commandmodule (windows, esm)', () => {
|
||||
const fname = "file:///C:\\pooba\\Projects\\sern\\halibu\\dist\\commands\\ping.js"
|
||||
const callsiteinfo = Files.parseCallsite(fname)
|
||||
expect(callsiteinfo.name).toEqual("ping");
|
||||
//this test case is impossible on linux.
|
||||
if(process.platform == 'win32') {
|
||||
const fname = "file:///C:\\pooba\\Projects\\sern\\halibu\\dist\\commands\\ping.js"
|
||||
const callsiteinfo = Files.parseCallsite(fname)
|
||||
expect(callsiteinfo.name).toEqual("ping");
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
it('should import a commandModule properly', async () => {
|
||||
|
||||
Reference in New Issue
Block a user