Skip to content

Commit

Permalink
feat: import context in each file
Browse files Browse the repository at this point in the history
 (not use overload func)
  • Loading branch information
mouse484 committed Oct 27, 2022
1 parent 25004fa commit 2ee0f34
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 43 deletions.
4 changes: 2 additions & 2 deletions src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
GatewayIntentBits,
IntentsBitField,
} from 'discord.js';
import { context } from 'ecstar/context';
import { eventContext } from 'ecstar/context/event';
import { CommandStore } from 'ecstar/store/CommandStore';
import { EventStore } from 'ecstar/store/EventStore';

Expand Down Expand Up @@ -37,7 +37,7 @@ export class Client extends DiscordClient {
emit(name: string, ...args: unknown[]): boolean {
const events = this.events.get(name);
if (events) {
const ctx = context(this, name);
const ctx = eventContext(this, name);

events.forEach((event) => {
event.run(ctx, args);
Expand Down
5 changes: 3 additions & 2 deletions src/core/events/CommandHandler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { context, event } from 'ecstar';
import { event } from 'ecstar';
import { Events } from 'discord.js';
import { getCommandName } from 'ecstar/utils/getCommandName';
import { commandContext } from 'ecstar/context/command';

export default event(() => ({
name: Events.MessageCreate,
Expand All @@ -16,7 +17,7 @@ export default event(() => ({

const command = client.commands.get(name);

const ctx = context(client, message);
const ctx = commandContext(client, message);

if (command?.guildOnly && !message.guild) {
return message.channel.send('Can only be used with guild');
Expand Down
2 changes: 0 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@ export { Client, EcstarClientOptions } from './Client';

export { command, commandOptions } from './lib/structures/command';
export { event, eventOptions } from './lib/structures/event';

export { context } from './lib/context';
2 changes: 1 addition & 1 deletion src/lib/context/argument.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Client } from 'ecstar';
import { ContextBase } from 'ecstar/context';
import { ContextBase } from 'ecstar/context/base';

export interface ArgumentContext extends ContextBase {
type: 'argument';
Expand Down
10 changes: 10 additions & 0 deletions src/lib/context/base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Client } from 'ecstar';
import { Structures } from 'ecstar/structures';

type ContextType = keyof Structures | string | 'unknown';

export interface ContextBase {
name: string;
type: ContextType;
client: Client;
}
2 changes: 1 addition & 1 deletion src/lib/context/command.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Client } from 'ecstar';
import { Message, Snowflake, TextChannel, User } from 'discord.js';

import { ContextBase } from 'ecstar/context';
import { ContextBase } from 'ecstar/context/base';
import { parser, parsed } from 'ecstar/utils/argumentParser';
import { getArgs, argsType, TypeList } from 'ecstar/utils/getArgs';

Expand Down
2 changes: 1 addition & 1 deletion src/lib/context/event.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Message, Snowflake, TextChannel } from 'discord.js';
import { Client } from 'ecstar';
import { ContextBase } from 'ecstar/context';
import { ContextBase } from 'ecstar/context/base';

export interface EventContext extends ContextBase {
type: 'event';
Expand Down
33 changes: 0 additions & 33 deletions src/lib/context/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/lib/context/slashCommand.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Interaction, Message, Snowflake, TextChannel } from 'discord.js';
import { Client } from 'ecstar';
import { ContextBase } from 'ecstar/context';
import { ContextBase } from 'ecstar/context/base';

export interface SlashCommandContext extends ContextBase {
type: 'slashCommand';
Expand Down

0 comments on commit 2ee0f34

Please sign in to comment.