Skip to content

Commit

Permalink
refact,simplf
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoobes committed May 25, 2024
1 parent 12a8f0c commit fb418c0
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/core/create-plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};
2 changes: 1 addition & 1 deletion src/core/id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/core/module-loading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/types/core-modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
25 changes: 19 additions & 6 deletions test/core/module-loading.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit fb418c0

Please sign in to comment.