cleaning up client merging

This commit is contained in:
2025-11-03 10:28:44 -06:00
parent 5beda9328b
commit 8b1eecd823
3 changed files with 35 additions and 27 deletions
-19
View File
@@ -71,26 +71,8 @@ export class Unicord {
}
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);
// TODO: inherit event listeners too
return this;
}
@@ -117,7 +99,6 @@ export class Unicord {
return this;
}
// TODO: should have a different signature for events that are not commands
onEvent(event: string, handler: UnicordEventHandler): this {
this.__onEvent(UnicordEventType.SystemEvent, event, handler);
return this;
+31 -3
View File
@@ -1,14 +1,17 @@
import { UnicordCommandContext } from "../context";
import { UnicordCommandContext } from '../context';
export type Primitive = string | number | boolean | null;
export interface UnicordConfig {
application_id?: string;
token?: string;
prefix?: string;
intents?: Intent[];
}
export interface UnicordConfigWithDefaults extends UnicordConfig {
application_id: string;
token: string;
intents: Intent[];
}
@@ -16,6 +19,13 @@ export type Brand<T, K> = T & { __brand: K };
export type EventName = Brand<string, 'event-name'>;
export enum UnicordApplicationCommandType {
Chat = 1,
User = 2,
Message = 3,
PrimaryEntryPoint = 4,
}
export enum UnicordArgumentType {
SubCommand = 1,
SubCommandGroup = 2,
@@ -30,6 +40,23 @@ export enum UnicordArgumentType {
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
// export type ApplicationCommandOption = {
// type: ApplicationCommandOptionType;
@@ -96,8 +123,8 @@ export type ArgumentTypeFromOptions<T extends readonly UnicordArgumentDefinition
? U
: U | undefined
: Definition['required'] extends true // If required, keep as is; otherwise, make optional
? DefinitionTypeMap[Definition['type']]
: DefinitionTypeMap[Definition['type']] | undefined
? DefinitionTypeMap[Definition['type']]
: DefinitionTypeMap[Definition['type']] | undefined
: unknown;
};
@@ -106,6 +133,7 @@ export type UnicordCommandHandler<Options extends UnicordCommandOptions> = (
args: ArgumentTypeFromOptions<Options['args']>,
) => any;
// TODO: Fill out signature
export type UnicordEventHandler = (context: UnicordEventContext, payload: any) => any;
export type UnicordHandler<Options extends UnicordCommandOptions> =
+3 -4
View File
@@ -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
// 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';
const DISCORD_APPLICATION_ID = process.env.APPLICATION_ID!;
const DISCORD_CLIENT_TOKEN = process.env.BOT_TOKEN!;
// Create a new client instance
// Most usage will be via chaining methods off the client instance
const client = new Unicord({
token: process.env.BOT_TOKEN!,
application_id: DISCORD_APPLICATION_ID,
token: DISCORD_CLIENT_TOKEN,
})
.registerChatCommand(
'ping',
@@ -73,8 +74,6 @@ const client = new Unicord({
console.log(`Logged in as ${payload.user.username}`);
});
// client.login(DISCORD_CLIENT_TOKEN);
// Allow use of "child" instances inside parent instance
const etc = new Unicord().registerChatCommand(
'zing',