mirror of
https://github.com/jaronpate/unicord.git
synced 2026-10-18 21:47:40 +00:00
cleaning up client merging
This commit is contained in:
@@ -71,26 +71,8 @@ export class Unicord {
|
|||||||
}
|
}
|
||||||
|
|
||||||
use(client: Unicord): this {
|
use(client: Unicord): this {
|
||||||
// const handlers = client.commandManager.all();
|
|
||||||
|
|
||||||
// for (const type in handlers) {
|
|
||||||
// const typeKey = type as UnicordEventType.ChatCommands | UnicordEventType.ApplicationCommands;
|
|
||||||
// for (const [event, definition] of handlers[typeKey]) {
|
|
||||||
// this.commandManager.register(
|
|
||||||
// typeKey,
|
|
||||||
// event,
|
|
||||||
// definition.handler.bind(this.commandManager),
|
|
||||||
// definition.options,
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// this.commandManager.registerDefaultHelpCommand();
|
|
||||||
|
|
||||||
this.commandManager.merge(client.commandManager);
|
this.commandManager.merge(client.commandManager);
|
||||||
|
|
||||||
// TODO: inherit event listeners too
|
// TODO: inherit event listeners too
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,7 +99,6 @@ export class Unicord {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: should have a different signature for events that are not commands
|
|
||||||
onEvent(event: string, handler: UnicordEventHandler): this {
|
onEvent(event: string, handler: UnicordEventHandler): this {
|
||||||
this.__onEvent(UnicordEventType.SystemEvent, event, handler);
|
this.__onEvent(UnicordEventType.SystemEvent, event, handler);
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
+31
-3
@@ -1,14 +1,17 @@
|
|||||||
import { UnicordCommandContext } from "../context";
|
import { UnicordCommandContext } from '../context';
|
||||||
|
|
||||||
export type Primitive = string | number | boolean | null;
|
export type Primitive = string | number | boolean | null;
|
||||||
|
|
||||||
export interface UnicordConfig {
|
export interface UnicordConfig {
|
||||||
|
application_id?: string;
|
||||||
token?: string;
|
token?: string;
|
||||||
prefix?: string;
|
prefix?: string;
|
||||||
intents?: Intent[];
|
intents?: Intent[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UnicordConfigWithDefaults extends UnicordConfig {
|
export interface UnicordConfigWithDefaults extends UnicordConfig {
|
||||||
|
application_id: string;
|
||||||
|
token: string;
|
||||||
intents: Intent[];
|
intents: Intent[];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -16,6 +19,13 @@ export type Brand<T, K> = T & { __brand: K };
|
|||||||
|
|
||||||
export type EventName = Brand<string, 'event-name'>;
|
export type EventName = Brand<string, 'event-name'>;
|
||||||
|
|
||||||
|
export enum UnicordApplicationCommandType {
|
||||||
|
Chat = 1,
|
||||||
|
User = 2,
|
||||||
|
Message = 3,
|
||||||
|
PrimaryEntryPoint = 4,
|
||||||
|
}
|
||||||
|
|
||||||
export enum UnicordArgumentType {
|
export enum UnicordArgumentType {
|
||||||
SubCommand = 1,
|
SubCommand = 1,
|
||||||
SubCommandGroup = 2,
|
SubCommandGroup = 2,
|
||||||
@@ -30,6 +40,23 @@ export enum UnicordArgumentType {
|
|||||||
Attachment = 11,
|
Attachment = 11,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum UnicordChannelType {
|
||||||
|
GuildText = 0,
|
||||||
|
DM = 1,
|
||||||
|
GuildVoice = 2,
|
||||||
|
GroupDm = 3,
|
||||||
|
GuildCategory = 4,
|
||||||
|
GuildNews = 5,
|
||||||
|
GuildStore = 6,
|
||||||
|
GuildNewsThread = 10,
|
||||||
|
GuildPublicThread = 11,
|
||||||
|
GuildPrivateThread = 12,
|
||||||
|
GuildStageVoice = 13,
|
||||||
|
GuildDirectory = 14,
|
||||||
|
GuildForum = 15,
|
||||||
|
GuildMedia = 16,
|
||||||
|
}
|
||||||
|
|
||||||
// Old type
|
// Old type
|
||||||
// export type ApplicationCommandOption = {
|
// export type ApplicationCommandOption = {
|
||||||
// type: ApplicationCommandOptionType;
|
// type: ApplicationCommandOptionType;
|
||||||
@@ -96,8 +123,8 @@ export type ArgumentTypeFromOptions<T extends readonly UnicordArgumentDefinition
|
|||||||
? U
|
? U
|
||||||
: U | undefined
|
: U | undefined
|
||||||
: Definition['required'] extends true // If required, keep as is; otherwise, make optional
|
: Definition['required'] extends true // If required, keep as is; otherwise, make optional
|
||||||
? DefinitionTypeMap[Definition['type']]
|
? DefinitionTypeMap[Definition['type']]
|
||||||
: DefinitionTypeMap[Definition['type']] | undefined
|
: DefinitionTypeMap[Definition['type']] | undefined
|
||||||
: unknown;
|
: unknown;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -106,6 +133,7 @@ export type UnicordCommandHandler<Options extends UnicordCommandOptions> = (
|
|||||||
args: ArgumentTypeFromOptions<Options['args']>,
|
args: ArgumentTypeFromOptions<Options['args']>,
|
||||||
) => any;
|
) => any;
|
||||||
|
|
||||||
|
// TODO: Fill out signature
|
||||||
export type UnicordEventHandler = (context: UnicordEventContext, payload: any) => any;
|
export type UnicordEventHandler = (context: UnicordEventContext, payload: any) => any;
|
||||||
|
|
||||||
export type UnicordHandler<Options extends UnicordCommandOptions> =
|
export type UnicordHandler<Options extends UnicordCommandOptions> =
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
// Here we are defining what we want the interface to look like so that there is a goal to work towards
|
// Here we are defining what we want the interface to look like so that there is a goal to work towards
|
||||||
// Things here are not necessarily implemented in the actual code but show what we want it to look like to use the library
|
// Things here are not necessarily implemented in the actual code but show what we want it to look like to use the library
|
||||||
|
|
||||||
// import { unicord, t } from 'unicord';
|
|
||||||
import { Expectation, Unicord, UnicordArgumentType } from '../rewrite/index.ts';
|
import { Expectation, Unicord, UnicordArgumentType } from '../rewrite/index.ts';
|
||||||
|
|
||||||
|
const DISCORD_APPLICATION_ID = process.env.APPLICATION_ID!;
|
||||||
const DISCORD_CLIENT_TOKEN = process.env.BOT_TOKEN!;
|
const DISCORD_CLIENT_TOKEN = process.env.BOT_TOKEN!;
|
||||||
|
|
||||||
// Create a new client instance
|
// Create a new client instance
|
||||||
// Most usage will be via chaining methods off the client instance
|
// Most usage will be via chaining methods off the client instance
|
||||||
const client = new Unicord({
|
const client = new Unicord({
|
||||||
token: process.env.BOT_TOKEN!,
|
application_id: DISCORD_APPLICATION_ID,
|
||||||
|
token: DISCORD_CLIENT_TOKEN,
|
||||||
})
|
})
|
||||||
.registerChatCommand(
|
.registerChatCommand(
|
||||||
'ping',
|
'ping',
|
||||||
@@ -73,8 +74,6 @@ const client = new Unicord({
|
|||||||
console.log(`Logged in as ${payload.user.username}`);
|
console.log(`Logged in as ${payload.user.username}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
// client.login(DISCORD_CLIENT_TOKEN);
|
|
||||||
|
|
||||||
// Allow use of "child" instances inside parent instance
|
// Allow use of "child" instances inside parent instance
|
||||||
const etc = new Unicord().registerChatCommand(
|
const etc = new Unicord().registerChatCommand(
|
||||||
'zing',
|
'zing',
|
||||||
|
|||||||
Reference in New Issue
Block a user