@arox/framework 0.1.2-beta.1 → 0.1.2-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,11 @@
1
1
  import { SlashCommandBuilder, RESTPostAPIChatInputApplicationCommandsJSONBody } from "discord.js";
2
- import { Client } from "../core";
2
+ import { Client } from "../core/index.js";
3
3
  export interface ApplicationJSONBody extends RESTPostAPIChatInputApplicationCommandsJSONBody {
4
4
  prefix_support: boolean;
5
5
  slash_support: boolean;
6
6
  aliases: string[];
7
7
  }
8
8
  export declare class ApplicationCommandBuilder extends SlashCommandBuilder {
9
- constructor();
10
9
  protected prefix_support: boolean;
11
10
  protected slash_support: boolean;
12
11
  protected aliases: string[];
@@ -1,21 +1,32 @@
1
- import { ChatInputCommandInteraction, Message } from "discord.js";
2
- import { Context, Client } from "../index";
3
- import { MaybePromise } from "#types/extra.js";
4
- import { Logger } from "../../utils/index";
5
- import { ApplicationCommandBuilder } from "./Builder";
6
- type MessageContext = NonNullable<ReturnType<Context<Message>["toJSON"]>>;
7
- type InteractionContext = NonNullable<ReturnType<Context<ChatInputCommandInteraction>["toJSON"]>>;
1
+ import { Client } from "../index.js";
2
+ import { Logger } from "../../utils/index.js";
3
+ import type { MaybePromise } from "#types/extra.js";
4
+ import { ApplicationCommandBuilder } from "../builder/Builder.js";
5
+ import type { InteractionContextJSON, MessageContextJSON } from "../builder/Context.js";
6
+ type MessageContext = MessageContextJSON;
7
+ type InteractionContext = InteractionContextJSON;
8
+ type CommandContext = MessageContext | InteractionContext;
8
9
  export declare class CommandBuilder {
9
10
  #private;
10
11
  readonly data: ApplicationCommandBuilder;
11
- readonly client: Client;
12
- readonly logger: Logger;
13
12
  _onMessage?: (ctx: MessageContext) => MaybePromise<void>;
14
13
  _onInteraction?: (ctx: InteractionContext) => MaybePromise<void>;
14
+ get client(): Client;
15
+ get logger(): Logger;
15
16
  get supportsSlash(): false | ((ctx: InteractionContext) => MaybePromise<void>) | undefined;
16
17
  get supportsPrefix(): false | ((ctx: MessageContext) => MaybePromise<void>) | undefined;
17
18
  constructor(data: ApplicationCommandBuilder);
19
+ attach(client: Client): this;
18
20
  onMessage(func: (ctx: MessageContext) => MaybePromise<void>): this;
19
21
  onInteraction(func: (ctx: InteractionContext) => MaybePromise<void>): this;
20
22
  }
23
+ export interface CommandOptions {
24
+ data: ApplicationCommandBuilder;
25
+ execute?: (ctx: CommandContext) => MaybePromise<void>;
26
+ onMessage?: (ctx: MessageContext) => MaybePromise<void>;
27
+ onInteraction?: (ctx: InteractionContext) => MaybePromise<void>;
28
+ }
29
+ export declare class Command extends CommandBuilder {
30
+ constructor(options: CommandOptions);
31
+ }
21
32
  export {};
@@ -1,6 +1,6 @@
1
- import { Message, User, ChatInputCommandInteraction, Locale } from "discord.js";
2
- import { Client } from "../index";
3
- import { TOptions } from "i18next";
1
+ import { ChatInputCommandInteraction, Locale, Message, User } from "discord.js";
2
+ import type { TOptions } from "i18next";
3
+ import type { Client } from "../index.js";
4
4
  type ContextPayload<T extends ChatInputCommandInteraction | Message> = T extends ChatInputCommandInteraction ? {
5
5
  interaction: T;
6
6
  args?: string[];
@@ -8,6 +8,22 @@ type ContextPayload<T extends ChatInputCommandInteraction | Message> = T extends
8
8
  message: T;
9
9
  args?: string[];
10
10
  };
11
+ type TranslateFn = (key: string, options?: TOptions & {
12
+ defaultValue?: string;
13
+ }) => string;
14
+ export interface InteractionContextJSON {
15
+ kind: "interaction";
16
+ interaction: ChatInputCommandInteraction;
17
+ author: User | null;
18
+ t: TranslateFn;
19
+ }
20
+ export interface MessageContextJSON {
21
+ kind: "message";
22
+ message: Message;
23
+ args: string[];
24
+ author: User | null;
25
+ t: TranslateFn;
26
+ }
11
27
  export declare class Context<T extends ChatInputCommandInteraction | Message> {
12
28
  readonly client: Client;
13
29
  readonly args: string[];
@@ -20,20 +36,7 @@ export declare class Context<T extends ChatInputCommandInteraction | Message> {
20
36
  t(key: string, options?: TOptions & {
21
37
  defaultValue?: string;
22
38
  }): string;
23
- toJSON(): {
24
- kind: "interaction";
25
- interaction: T;
26
- author: User | null;
27
- t: any;
28
- message?: undefined;
29
- args?: undefined;
30
- } | {
31
- kind: "message";
32
- message: Message;
33
- args: string[];
34
- author: User | null;
35
- t: any;
36
- interaction?: undefined;
37
- };
39
+ toJSON(this: Context<ChatInputCommandInteraction>): InteractionContextJSON;
40
+ toJSON(this: Context<Message>): MessageContextJSON;
38
41
  }
39
42
  export {};
@@ -1,16 +1,17 @@
1
1
  import { ClientEvents } from "discord.js";
2
- import { MaybePromise } from "#types/extra.js";
3
- import { Client } from "../index";
4
- import { Logger } from "../../utils/index";
2
+ import type { MaybePromise } from "#types/extra.js";
3
+ import { Client } from "../index.js";
4
+ import { Logger } from "../../utils/index.js";
5
5
  type EventArgs<K extends keyof ClientEvents> = ClientEvents[K];
6
6
  type EventHandler<K extends keyof ClientEvents> = (context: EventBuilder<K>, ...args: EventArgs<K>) => MaybePromise<void>;
7
7
  export declare class EventBuilder<K extends keyof ClientEvents> {
8
8
  #private;
9
9
  readonly name: K;
10
10
  readonly once: boolean;
11
- readonly client: Client;
12
- readonly logger: Logger;
11
+ get client(): Client;
12
+ get logger(): Logger;
13
13
  constructor(name: K, once?: boolean, _handler?: EventHandler<K>);
14
+ attach(client: Client): this;
14
15
  onExecute(func: EventHandler<K>): this;
15
16
  }
16
17
  export {};
@@ -1,4 +1,4 @@
1
- export * from "./Command";
2
- export * from "./Context";
3
- export * from "./Event";
4
- export * from "./Builder";
1
+ export * from "./Command.js";
2
+ export * from "./Context.js";
3
+ export * from "./Event.js";
4
+ export * from "./Builder.js";
@@ -1,14 +1,14 @@
1
1
  import { Client as DiscordClient, Collection, IntentsBitField } from "discord.js";
2
- import { CommandBuilder } from "../index";
3
- import { Logger } from "../../utils";
4
- import { FrameworkOptions } from "#types/client.js";
5
- import { i18n } from "i18next";
2
+ import type { i18n } from "i18next";
3
+ import type { FrameworkOptions, PrefixFn } from "#types/client.js";
4
+ import { Logger } from "../../utils/index.js";
5
+ import { CommandBuilder } from "../index.js";
6
6
  export declare class Client<Ready extends boolean = boolean> extends DiscordClient<Ready> {
7
7
  #private;
8
8
  readonly logger: Logger;
9
9
  commands: Collection<string, CommandBuilder>;
10
10
  aliases: Collection<string, Set<string>>;
11
- readonly prefix: string | false;
11
+ readonly prefix: PrefixFn;
12
12
  i18n: i18n | undefined;
13
13
  options: Omit<FrameworkOptions, "intents"> & {
14
14
  intents: IntentsBitField;
@@ -1 +1 @@
1
- export * from "./Client";
1
+ export * from "./Client.js";
@@ -1,2 +1,2 @@
1
- export * from "./core";
2
- export * from "./builder";
1
+ export * from "./core/index.js";
2
+ export * from "./builder/index.js";
@@ -1,3 +1,3 @@
1
- export * from "./util";
2
- export * from "./Files";
3
- export * from "./logger/Logger";
1
+ export * from "./util.js";
2
+ export * from "./Files.js";
3
+ export * from "./logger/Logger.js";
@@ -31,46 +31,4 @@ export declare enum LogLevel {
31
31
  */
32
32
  None = 100
33
33
  }
34
- export interface ILogger {
35
- /**
36
- * Checks whether a level is supported.
37
- * @param level The level to check.
38
- */
39
- has(level: LogLevel): boolean;
40
- /**
41
- * Alias of {@link ILogger.write} with {@link LogLevel.Trace} as level.
42
- * @param values The values to log.
43
- */
44
- trace(...values: readonly unknown[]): void;
45
- /**
46
- * Alias of {@link ILogger.write} with {@link LogLevel.Debug} as level.
47
- * @param values The values to log.
48
- */
49
- debug(...values: readonly unknown[]): void;
50
- /**
51
- * Alias of {@link ILogger.write} with {@link LogLevel.Info} as level.
52
- * @param values The values to log.
53
- */
54
- info(...values: readonly unknown[]): void;
55
- /**
56
- * Alias of {@link ILogger.write} with {@link LogLevel.Warn} as level.
57
- * @param values The values to log.
58
- */
59
- warn(...values: readonly unknown[]): void;
60
- /**
61
- * Alias of {@link ILogger.write} with {@link LogLevel.Error} as level.
62
- * @param values The values to log.
63
- */
64
- error(...values: readonly unknown[]): void;
65
- /**
66
- * Alias of {@link ILogger.write} with {@link LogLevel.Fatal} as level.
67
- * @param values The values to log.
68
- */
69
- fatal(...values: readonly unknown[]): void;
70
- /**
71
- * Writes the log message given a level and the value(s).
72
- * @param level The log level.
73
- * @param values The values to log.
74
- */
75
- write(level: LogLevel, ...values: readonly unknown[]): void;
76
- }
34
+ export type { ILogger } from "#types/logger.js";
@@ -1,10 +1,12 @@
1
1
  import { Console } from "console";
2
2
  import type { Color } from "colorette";
3
3
  import { Timestamp } from "@sapphire/timestamp";
4
- import type { ILogger } from "./ILogger";
5
- import { LogLevel } from "./ILogger";
6
- import { LoggerModule } from "i18next";
7
- export { LogLevel } from "./ILogger";
4
+ import type { ILogger } from "./ILogger.js";
5
+ import { LogLevel } from "./ILogger.js";
6
+ import type { LoggerLevelOptions, LoggerOptions, LoggerStyleResolvable, LoggerTimestampFormatter, LoggerTimestampOptions } from "#types/logger.js";
7
+ import type { LoggerModule } from "i18next";
8
+ export { LogLevel } from "./ILogger.js";
9
+ export type { LoggerFormatOptions, LoggerLevelOptions, LoggerOptions, LoggerStyleOptions, LoggerStyleResolvable, LoggerTimestampFormatter, LoggerTimestampOptions, } from "#types/logger.js";
8
10
  export declare class Logger implements ILogger {
9
11
  level: LogLevel;
10
12
  readonly formats: Map<LogLevel, LoggerLevel>;
@@ -57,44 +59,6 @@ export declare class LoggerLevel {
57
59
  }
58
60
  declare const _default: Logger;
59
61
  export default _default;
60
- export interface LoggerOptions {
61
- stdout?: NodeJS.WritableStream;
62
- stderr?: NodeJS.WritableStream;
63
- defaultFormat?: LoggerLevelOptions;
64
- format?: LoggerFormatOptions;
65
- level?: LogLevel;
66
- join?: string;
67
- depth?: number;
68
- }
69
- export interface LoggerFormatOptions {
70
- trace?: LoggerLevelOptions;
71
- debug?: LoggerLevelOptions;
72
- info?: LoggerLevelOptions;
73
- warn?: LoggerLevelOptions;
74
- error?: LoggerLevelOptions;
75
- fatal?: LoggerLevelOptions;
76
- none?: LoggerLevelOptions;
77
- }
78
- export interface LoggerLevelOptions {
79
- timestamp?: LoggerTimestampOptions | null;
80
- infix?: string;
81
- message?: LoggerStyleResolvable | null;
82
- }
83
- export interface LoggerTimestampOptions {
84
- pattern?: string;
85
- utc?: boolean;
86
- color?: LoggerStyleResolvable | null;
87
- formatter?: LoggerTimestampFormatter;
88
- }
89
- export interface LoggerTimestampFormatter {
90
- (timestamp: string): string;
91
- }
92
- export interface LoggerStyleOptions {
93
- effects?: LoggerStyleEffect[];
94
- text?: LoggerStyleText;
95
- background?: LoggerStyleBackground;
96
- }
97
- export type LoggerStyleResolvable = Color | LoggerStyleOptions;
98
62
  export declare enum LoggerStyleEffect {
99
63
  Reset = "reset",
100
64
  Bold = "bold",
@@ -1,4 +1,6 @@
1
- import { PrefixOptions } from "#types/client.js";
2
- import { InteractionResponse, Message } from "discord.js";
1
+ import { ChatInputCommandInteraction, InteractionResponse, Locale, Message } from "discord.js";
2
+ import type { Context } from "../structures/index.js";
3
+ export declare const allowedLocales: readonly ["id", "en-US", "en-GB", "bg", "zh-CN", "zh-TW", "hr", "cs", "da", "nl", "fi", "fr", "de", "el", "hi", "hu", "it", "ja", "ko", "lt", "no", "pl", "pt-BR", "ro", "ru", "es-ES", "es-419", "sv-SE", "th", "tr", "uk", "vi"];
3
4
  export declare function deleteMessageAfterSent(message: Message | InteractionResponse, time?: number): Promise<void>;
4
- export declare function getPrefix(opts: PrefixOptions): string | false;
5
+ export declare function toAllowedLocale(locale: string | null | undefined): `${Locale}` | undefined;
6
+ export declare function getDefaultLang(ctx: Context<ChatInputCommandInteraction | Message>): `${Locale}`;
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@arox/framework","version":"0.1.2-beta.1","description":"","keywords":["arox","discord.js","framework"],"homepage":"https://github.com/AroxBot/framework#readme","bugs":{"url":"https://github.com/AroxBot/framework/issues"},"license":"Apache-2.0","author":"vrdons","contributors":["fhyrox"],"repository":{"type":"git","url":"git+https://github.com/AroxBot/framework.git"},"type":"commonjs","main":"dist/index.js","types":"dist/index.d.ts","imports":{"#types/*":"./types/*"},"dependencies":{"@sapphire/timestamp":"^1.0.5","colorette":"^2.0.20","fast-glob":"^3.3.3","i18next":"^25.8.0"},"peerDependencies":{"discord.js":">=14.25.1"}}
1
+ {"name":"@arox/framework","version":"0.1.2-beta.2","description":"","keywords":["arox","discord.js","framework"],"homepage":"https://github.com/AroxBot/framework#readme","bugs":{"url":"https://github.com/AroxBot/framework/issues"},"license":"Apache-2.0","author":"vrdons","contributors":["fhyrox"],"repository":{"type":"git","url":"git+https://github.com/AroxBot/framework.git"},"type":"module","main":"dist/index.cjs","module":"dist/index.js","types":"dist/index.d.ts","imports":{"#types/*":"./types/*.d.ts"},"exports":{".":{"types":"./dist/index.d.ts","require":{"types":"./dist/index.d.cts","default":"./dist/index.cjs"},"import":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"default":"./dist/index.js"}},"dependencies":{"@sapphire/timestamp":"^1.0.5","colorette":"^2.0.20","fast-glob":"^3.3.3","i18next":"^25.8.0"},"peerDependencies":{"discord.js":">=14.25.1"}}
package/types/client.d.ts CHANGED
@@ -1,21 +1,22 @@
1
- import { ClientOptions } from "discord.js";
2
- import { LoggerOptions } from "../src/utils/logger/Logger";
1
+ import {
2
+ ChatInputCommandInteraction,
3
+ ClientOptions,
4
+ Locale,
5
+ Message,
6
+ } from "discord.js";
7
+ import type { LoggerOptions } from "./logger.js";
3
8
  import { i18n } from "i18next";
9
+ import type { Context } from "../src/structures/builder/Context.js";
4
10
 
5
- export interface FrameworkPaths {
6
- events?: string;
7
- commands?: string;
8
- locales?: string;
9
- }
10
-
11
- export type PrefixOptions =
12
- | { enabled: true; prefix: string }
13
- | { enabled: false }
14
- | string;
11
+ export type PrefixFn = (ctx: Context<Message>) => string | false;
12
+ export type GetDefaultLangFn = (
13
+ ctx: Context<ChatInputCommandInteraction | Message>
14
+ ) => `${Locale}` | undefined;
15
15
 
16
16
  export interface FrameworkOptions extends ClientOptions {
17
17
  logger?: LoggerOptions;
18
- prefix?: PrefixOptions;
18
+ prefix?: PrefixFn;
19
+ getDefaultLang?: GetDefaultLangFn;
19
20
  autoRegisterCommands?: boolean;
20
21
  includePaths: string[];
21
22
  i18n?: i18n;
@@ -0,0 +1,63 @@
1
+ import type { Color } from "colorette";
2
+ import type { LogLevel } from "../src/utils/logger/ILogger.js";
3
+ import type {
4
+ LoggerStyleBackground,
5
+ LoggerStyleEffect,
6
+ LoggerStyleText,
7
+ } from "../src/utils/logger/Logger.js";
8
+
9
+ export interface ILogger {
10
+ has(level: LogLevel): boolean;
11
+ trace(...values: readonly unknown[]): void;
12
+ debug(...values: readonly unknown[]): void;
13
+ info(...values: readonly unknown[]): void;
14
+ warn(...values: readonly unknown[]): void;
15
+ error(...values: readonly unknown[]): void;
16
+ fatal(...values: readonly unknown[]): void;
17
+ write(level: LogLevel, ...values: readonly unknown[]): void;
18
+ }
19
+
20
+ export interface LoggerOptions {
21
+ stdout?: NodeJS.WritableStream;
22
+ stderr?: NodeJS.WritableStream;
23
+ defaultFormat?: LoggerLevelOptions;
24
+ format?: LoggerFormatOptions;
25
+ level?: LogLevel;
26
+ join?: string;
27
+ depth?: number;
28
+ }
29
+
30
+ export interface LoggerFormatOptions {
31
+ trace?: LoggerLevelOptions;
32
+ debug?: LoggerLevelOptions;
33
+ info?: LoggerLevelOptions;
34
+ warn?: LoggerLevelOptions;
35
+ error?: LoggerLevelOptions;
36
+ fatal?: LoggerLevelOptions;
37
+ none?: LoggerLevelOptions;
38
+ }
39
+
40
+ export interface LoggerLevelOptions {
41
+ timestamp?: LoggerTimestampOptions | null;
42
+ infix?: string;
43
+ message?: LoggerStyleResolvable | null;
44
+ }
45
+
46
+ export interface LoggerTimestampOptions {
47
+ pattern?: string;
48
+ utc?: boolean;
49
+ color?: LoggerStyleResolvable | null;
50
+ formatter?: LoggerTimestampFormatter;
51
+ }
52
+
53
+ export interface LoggerTimestampFormatter {
54
+ (timestamp: string): string;
55
+ }
56
+
57
+ export interface LoggerStyleOptions {
58
+ effects?: LoggerStyleEffect[];
59
+ text?: LoggerStyleText;
60
+ background?: LoggerStyleBackground;
61
+ }
62
+
63
+ export type LoggerStyleResolvable = Color | LoggerStyleOptions;
package/dist/context.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import { Client } from "./structures";
2
- export declare let currentClient: Client | null;
3
- export declare function setClient(client: Client): void;
4
- export declare function clearClient(): void;