Skip to content

Commit 2c9d36e

Browse files
committed
perf: remove plugins
1 parent 4af1647 commit 2c9d36e

File tree

8 files changed

+16
-61
lines changed

8 files changed

+16
-61
lines changed

src/Client.ts

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
import consola from 'consola';
12
import {
23
Client as DiscordClient,
34
ClientOptions as DiscordClientOptions,
45
GatewayIntentBits,
56
IntentsBitField,
67
} from 'discord.js';
7-
import { plugin } from 'ecstar/plugin';
8-
import { plugins } from 'ecstar/plugins';
8+
import { context } from 'ecstar/context';
99
import { CommandStore } from 'ecstar/store/CommandStore';
1010
import { EventStore } from 'ecstar/store/EventStore';
1111

@@ -17,13 +17,12 @@ export type EcstarClientOptions = Omit<DiscordClientOptions, 'intents'> & {
1717
} & ExtendedOption;
1818

1919
export class Client extends DiscordClient {
20-
static plugins: plugin[] = [];
21-
2220
readonly commands = new CommandStore();
2321
readonly events = new EventStore();
2422
readonly options!: Omit<EcstarClientOptions, 'intents'> & {
2523
intents: IntentsBitField;
2624
}; // Intents is required in Discrod.js
25+
log = consola;
2726
constructor(options: EcstarClientOptions) {
2827
super({
2928
intents: [
@@ -33,12 +32,16 @@ export class Client extends DiscordClient {
3332
],
3433
...options,
3534
});
36-
37-
[...plugins, ...Client.plugins].forEach((plugin) => {
38-
plugin.run(this);
39-
});
4035
}
4136
emit(name: string, ...args: unknown[]): boolean {
42-
return super.emit('*', name, ...args);
37+
const events = this.events.get(name);
38+
if (events) {
39+
const ctx = context(this, name);
40+
41+
events.forEach((event) => {
42+
event.run(ctx, args);
43+
});
44+
}
45+
return true;
4346
}
4447
}

src/default/plugins/eventHandler.ts

-18
This file was deleted.

src/default/plugins/log.ts

-15
This file was deleted.

src/default/events/message/CommandHandler.ts renamed to src/lib/handler/CommandHandler.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default event(() => ({
3333
}
3434
}
3535

36-
if (command?.render) command.render(ctx);
36+
if (command?.render) command.render(ctx); // remove v6 majer
3737
else if (command?.run) command.run(ctx);
3838
},
3939
}));

src/lib/plugins.ts

-4
This file was deleted.

src/lib/store/EventStore.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import { Structures } from 'ecstar/structures';
22
import { StoreBase } from './StoreBase';
3+
import path from 'path';
34

45
export class EventStore extends StoreBase<'event', Structures['event'][]> {
56
constructor() {
67
super('events');
8+
// Core
9+
this.update(path.resolve(__dirname, '../handler/', 'CommandHandler'));
710
}
811
async update(path: string) {
912
const { default: file }: { default: Structures['event'] } = await import(

src/lib/store/StoreBase.ts

-8
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,6 @@ export class StoreBase<
1919
const directorypath = getDirectoryPath(storeDirectryName);
2020
if (!directorypath) return;
2121
watch(directorypath).on('add', (path) => this.update(path));
22-
23-
this.loadDefault(storeDirectryName);
24-
}
25-
loadDefault(directoryName: string) {
26-
watch(path.resolve(__dirname, '../../default', directoryName)).on(
27-
'add',
28-
(path: string) => this.update(path)
29-
);
3022
}
3123
async update(path: string) {
3224
const { default: file }: { default: X } = await import(path);

src/lib/structures/plugin.ts

-6
This file was deleted.

0 commit comments

Comments
 (0)