@arox/framework 0.1.0-alpha.2 → 0.1.0
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.
- package/dist/context.d.ts +4 -0
- package/dist/context.js +28 -0
- package/dist/events/interaction.d.ts +1 -0
- package/dist/events/interaction.js +37 -0
- package/dist/events/message.d.ts +1 -0
- package/dist/events/message.js +37 -0
- package/dist/events/ready.d.ts +1 -0
- package/dist/events/ready.js +11 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +19 -1
- package/dist/structures/Argument.d.ts +22 -0
- package/dist/structures/Argument.js +33 -0
- package/dist/structures/Client.d.ts +17 -0
- package/dist/structures/Client.js +99 -0
- package/dist/structures/Command.d.ts +31 -0
- package/dist/structures/Command.js +74 -0
- package/dist/structures/Context.d.ts +32 -0
- package/dist/structures/Context.js +56 -0
- package/dist/structures/Event.d.ts +19 -0
- package/dist/structures/Event.js +53 -0
- package/dist/utils/Files.d.ts +2 -0
- package/dist/utils/Files.js +47 -0
- package/dist/utils/logger/ILogger.d.ts +76 -0
- package/dist/utils/logger/ILogger.js +37 -0
- package/dist/utils/logger/Logger.d.ts +142 -0
- package/dist/utils/logger/Logger.js +361 -0
- package/dist/utils/util.d.ts +4 -0
- package/dist/utils/util.js +35 -0
- package/package.json +15 -1
- package/types/client.d.ts +19 -0
- package/types/extra.d.ts +1 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The logger levels for the {@link ILogger}.
|
|
3
|
+
*/
|
|
4
|
+
export declare enum LogLevel {
|
|
5
|
+
/**
|
|
6
|
+
* The lowest log level, used when calling {@link ILogger.trace}.
|
|
7
|
+
*/
|
|
8
|
+
Trace = 10,
|
|
9
|
+
/**
|
|
10
|
+
* The debug level, used when calling {@link ILogger.debug}.
|
|
11
|
+
*/
|
|
12
|
+
Debug = 20,
|
|
13
|
+
/**
|
|
14
|
+
* The info level, used when calling {@link ILogger.info}.
|
|
15
|
+
*/
|
|
16
|
+
Info = 30,
|
|
17
|
+
/**
|
|
18
|
+
* The warning level, used when calling {@link ILogger.warn}.
|
|
19
|
+
*/
|
|
20
|
+
Warn = 40,
|
|
21
|
+
/**
|
|
22
|
+
* The error level, used when calling {@link ILogger.error}.
|
|
23
|
+
*/
|
|
24
|
+
Error = 50,
|
|
25
|
+
/**
|
|
26
|
+
* The critical level, used when calling {@link ILogger.fatal}.
|
|
27
|
+
*/
|
|
28
|
+
Fatal = 60,
|
|
29
|
+
/**
|
|
30
|
+
* An unknown or uncategorized level.
|
|
31
|
+
*/
|
|
32
|
+
None = 100
|
|
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
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
//https://github.com/sapphiredev/framework/tree/main/src/lib/utils/logger
|
|
2
|
+
/**
|
|
3
|
+
* The logger levels for the {@link ILogger}.
|
|
4
|
+
*/ "use strict";
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
Object.defineProperty(exports, "LogLevel", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function() {
|
|
11
|
+
return LogLevel;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
var LogLevel = /*#__PURE__*/ function(LogLevel) {
|
|
15
|
+
/**
|
|
16
|
+
* The lowest log level, used when calling {@link ILogger.trace}.
|
|
17
|
+
*/ LogLevel[LogLevel["Trace"] = 10] = "Trace";
|
|
18
|
+
/**
|
|
19
|
+
* The debug level, used when calling {@link ILogger.debug}.
|
|
20
|
+
*/ LogLevel[LogLevel["Debug"] = 20] = "Debug";
|
|
21
|
+
/**
|
|
22
|
+
* The info level, used when calling {@link ILogger.info}.
|
|
23
|
+
*/ LogLevel[LogLevel["Info"] = 30] = "Info";
|
|
24
|
+
/**
|
|
25
|
+
* The warning level, used when calling {@link ILogger.warn}.
|
|
26
|
+
*/ LogLevel[LogLevel["Warn"] = 40] = "Warn";
|
|
27
|
+
/**
|
|
28
|
+
* The error level, used when calling {@link ILogger.error}.
|
|
29
|
+
*/ LogLevel[LogLevel["Error"] = 50] = "Error";
|
|
30
|
+
/**
|
|
31
|
+
* The critical level, used when calling {@link ILogger.fatal}.
|
|
32
|
+
*/ LogLevel[LogLevel["Fatal"] = 60] = "Fatal";
|
|
33
|
+
/**
|
|
34
|
+
* An unknown or uncategorized level.
|
|
35
|
+
*/ LogLevel[LogLevel["None"] = 100] = "None";
|
|
36
|
+
return LogLevel;
|
|
37
|
+
}({});
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { Console } from "console";
|
|
2
|
+
import type { Color } from "colorette";
|
|
3
|
+
import { Timestamp } from "@sapphire/timestamp";
|
|
4
|
+
import type { ILogger } from "./ILogger";
|
|
5
|
+
import { LogLevel } from "./ILogger";
|
|
6
|
+
export declare class Logger implements ILogger {
|
|
7
|
+
level: LogLevel;
|
|
8
|
+
readonly formats: Map<LogLevel, LoggerLevel>;
|
|
9
|
+
readonly join: string;
|
|
10
|
+
readonly depth: number;
|
|
11
|
+
readonly console: Console;
|
|
12
|
+
private static instance;
|
|
13
|
+
private static readonly LOG_METHODS;
|
|
14
|
+
private static readonly DEFAULT_COLORS;
|
|
15
|
+
private static readonly DEFAULT_NAMES;
|
|
16
|
+
constructor(options?: LoggerOptions);
|
|
17
|
+
static getInstance(): Logger;
|
|
18
|
+
static get stylize(): boolean;
|
|
19
|
+
setLevel(level: LogLevel): void;
|
|
20
|
+
has(level: LogLevel): boolean;
|
|
21
|
+
trace(...values: readonly unknown[]): void;
|
|
22
|
+
debug(...values: readonly unknown[]): void;
|
|
23
|
+
info(...values: readonly unknown[]): void;
|
|
24
|
+
log(...values: readonly unknown[]): void;
|
|
25
|
+
warn(...values: readonly unknown[]): void;
|
|
26
|
+
error(...values: readonly unknown[]): void;
|
|
27
|
+
fatal(...values: readonly unknown[]): void;
|
|
28
|
+
write(level: LogLevel, ...values: readonly unknown[]): void;
|
|
29
|
+
protected preprocess(values: readonly unknown[]): string;
|
|
30
|
+
private createFormatMap;
|
|
31
|
+
private createDefaultLevel;
|
|
32
|
+
private getLevelKey;
|
|
33
|
+
}
|
|
34
|
+
export declare class LoggerStyle {
|
|
35
|
+
readonly style: Color;
|
|
36
|
+
constructor(resolvable?: LoggerStyleResolvable);
|
|
37
|
+
run(value: string | number): string;
|
|
38
|
+
private buildStyleArray;
|
|
39
|
+
private combineStyles;
|
|
40
|
+
}
|
|
41
|
+
export declare class LoggerTimestamp {
|
|
42
|
+
timestamp: Timestamp;
|
|
43
|
+
utc: boolean;
|
|
44
|
+
color: LoggerStyle | null;
|
|
45
|
+
formatter: LoggerTimestampFormatter;
|
|
46
|
+
constructor(options?: LoggerTimestampOptions);
|
|
47
|
+
run(): string;
|
|
48
|
+
}
|
|
49
|
+
export declare class LoggerLevel {
|
|
50
|
+
timestamp: LoggerTimestamp | null;
|
|
51
|
+
infix: string;
|
|
52
|
+
message: LoggerStyle | null;
|
|
53
|
+
constructor(options?: LoggerLevelOptions);
|
|
54
|
+
run(content: string): string;
|
|
55
|
+
}
|
|
56
|
+
declare const _default: Logger;
|
|
57
|
+
export default _default;
|
|
58
|
+
export interface LoggerOptions {
|
|
59
|
+
stdout?: NodeJS.WritableStream;
|
|
60
|
+
stderr?: NodeJS.WritableStream;
|
|
61
|
+
defaultFormat?: LoggerLevelOptions;
|
|
62
|
+
format?: LoggerFormatOptions;
|
|
63
|
+
level?: LogLevel;
|
|
64
|
+
join?: string;
|
|
65
|
+
depth?: number;
|
|
66
|
+
}
|
|
67
|
+
export interface LoggerFormatOptions {
|
|
68
|
+
trace?: LoggerLevelOptions;
|
|
69
|
+
debug?: LoggerLevelOptions;
|
|
70
|
+
info?: LoggerLevelOptions;
|
|
71
|
+
warn?: LoggerLevelOptions;
|
|
72
|
+
error?: LoggerLevelOptions;
|
|
73
|
+
fatal?: LoggerLevelOptions;
|
|
74
|
+
none?: LoggerLevelOptions;
|
|
75
|
+
}
|
|
76
|
+
export interface LoggerLevelOptions {
|
|
77
|
+
timestamp?: LoggerTimestampOptions | null;
|
|
78
|
+
infix?: string;
|
|
79
|
+
message?: LoggerStyleResolvable | null;
|
|
80
|
+
}
|
|
81
|
+
export interface LoggerTimestampOptions {
|
|
82
|
+
pattern?: string;
|
|
83
|
+
utc?: boolean;
|
|
84
|
+
color?: LoggerStyleResolvable | null;
|
|
85
|
+
formatter?: LoggerTimestampFormatter;
|
|
86
|
+
}
|
|
87
|
+
export interface LoggerTimestampFormatter {
|
|
88
|
+
(timestamp: string): string;
|
|
89
|
+
}
|
|
90
|
+
export interface LoggerStyleOptions {
|
|
91
|
+
effects?: LoggerStyleEffect[];
|
|
92
|
+
text?: LoggerStyleText;
|
|
93
|
+
background?: LoggerStyleBackground;
|
|
94
|
+
}
|
|
95
|
+
export type LoggerStyleResolvable = Color | LoggerStyleOptions;
|
|
96
|
+
export declare enum LoggerStyleEffect {
|
|
97
|
+
Reset = "reset",
|
|
98
|
+
Bold = "bold",
|
|
99
|
+
Dim = "dim",
|
|
100
|
+
Italic = "italic",
|
|
101
|
+
Underline = "underline",
|
|
102
|
+
Inverse = "inverse",
|
|
103
|
+
Hidden = "hidden",
|
|
104
|
+
Strikethrough = "strikethrough"
|
|
105
|
+
}
|
|
106
|
+
export declare enum LoggerStyleText {
|
|
107
|
+
Black = "black",
|
|
108
|
+
Red = "red",
|
|
109
|
+
Green = "green",
|
|
110
|
+
Yellow = "yellow",
|
|
111
|
+
Blue = "blue",
|
|
112
|
+
Magenta = "magenta",
|
|
113
|
+
Cyan = "cyan",
|
|
114
|
+
White = "white",
|
|
115
|
+
Gray = "gray",
|
|
116
|
+
BlackBright = "blackBright",
|
|
117
|
+
RedBright = "redBright",
|
|
118
|
+
GreenBright = "greenBright",
|
|
119
|
+
YellowBright = "yellowBright",
|
|
120
|
+
BlueBright = "blueBright",
|
|
121
|
+
MagentaBright = "magentaBright",
|
|
122
|
+
CyanBright = "cyanBright",
|
|
123
|
+
WhiteBright = "whiteBright"
|
|
124
|
+
}
|
|
125
|
+
export declare enum LoggerStyleBackground {
|
|
126
|
+
Black = "bgBlack",
|
|
127
|
+
Red = "bgRed",
|
|
128
|
+
Green = "bgGreen",
|
|
129
|
+
Yellow = "bgYellow",
|
|
130
|
+
Blue = "bgBlue",
|
|
131
|
+
Magenta = "bgMagenta",
|
|
132
|
+
Cyan = "bgCyan",
|
|
133
|
+
White = "bgWhite",
|
|
134
|
+
BlackBright = "bgBlackBright",
|
|
135
|
+
RedBright = "bgRedBright",
|
|
136
|
+
GreenBright = "bgGreenBright",
|
|
137
|
+
YellowBright = "bgYellowBright",
|
|
138
|
+
BlueBright = "bgBlueBright",
|
|
139
|
+
MagentaBright = "bgMagentaBright",
|
|
140
|
+
CyanBright = "bgCyanBright",
|
|
141
|
+
WhiteBright = "bgWhiteBright"
|
|
142
|
+
}
|
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
//https://github.com/sapphiredev/plugins/tree/main/packages/logger
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
function _export(target, all) {
|
|
7
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
_export(exports, {
|
|
13
|
+
get Logger () {
|
|
14
|
+
return Logger;
|
|
15
|
+
},
|
|
16
|
+
get LoggerLevel () {
|
|
17
|
+
return LoggerLevel;
|
|
18
|
+
},
|
|
19
|
+
get LoggerStyle () {
|
|
20
|
+
return LoggerStyle;
|
|
21
|
+
},
|
|
22
|
+
get LoggerStyleBackground () {
|
|
23
|
+
return LoggerStyleBackground;
|
|
24
|
+
},
|
|
25
|
+
get LoggerStyleEffect () {
|
|
26
|
+
return LoggerStyleEffect;
|
|
27
|
+
},
|
|
28
|
+
get LoggerStyleText () {
|
|
29
|
+
return LoggerStyleText;
|
|
30
|
+
},
|
|
31
|
+
get LoggerTimestamp () {
|
|
32
|
+
return LoggerTimestamp;
|
|
33
|
+
},
|
|
34
|
+
get default () {
|
|
35
|
+
return _default;
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
39
|
+
const _console = require("console");
|
|
40
|
+
const _util = require("util");
|
|
41
|
+
const _colorette = /*#__PURE__*/ _interop_require_wildcard._(require("colorette"));
|
|
42
|
+
const _timestamp = require("@sapphire/timestamp");
|
|
43
|
+
const _ILogger = require("./ILogger");
|
|
44
|
+
class Logger {
|
|
45
|
+
level;
|
|
46
|
+
formats;
|
|
47
|
+
join;
|
|
48
|
+
depth;
|
|
49
|
+
console;
|
|
50
|
+
static instance = null;
|
|
51
|
+
static LOG_METHODS = new Map([
|
|
52
|
+
[
|
|
53
|
+
_ILogger.LogLevel.Trace,
|
|
54
|
+
"trace"
|
|
55
|
+
],
|
|
56
|
+
[
|
|
57
|
+
_ILogger.LogLevel.Debug,
|
|
58
|
+
"debug"
|
|
59
|
+
],
|
|
60
|
+
[
|
|
61
|
+
_ILogger.LogLevel.Info,
|
|
62
|
+
"info"
|
|
63
|
+
],
|
|
64
|
+
[
|
|
65
|
+
_ILogger.LogLevel.Warn,
|
|
66
|
+
"warn"
|
|
67
|
+
],
|
|
68
|
+
[
|
|
69
|
+
_ILogger.LogLevel.Error,
|
|
70
|
+
"error"
|
|
71
|
+
],
|
|
72
|
+
[
|
|
73
|
+
_ILogger.LogLevel.Fatal,
|
|
74
|
+
"error"
|
|
75
|
+
]
|
|
76
|
+
]);
|
|
77
|
+
static DEFAULT_COLORS = new Map([
|
|
78
|
+
[
|
|
79
|
+
_ILogger.LogLevel.Trace,
|
|
80
|
+
_colorette.gray
|
|
81
|
+
],
|
|
82
|
+
[
|
|
83
|
+
_ILogger.LogLevel.Debug,
|
|
84
|
+
_colorette.magenta
|
|
85
|
+
],
|
|
86
|
+
[
|
|
87
|
+
_ILogger.LogLevel.Info,
|
|
88
|
+
_colorette.cyan
|
|
89
|
+
],
|
|
90
|
+
[
|
|
91
|
+
_ILogger.LogLevel.Warn,
|
|
92
|
+
_colorette.yellow
|
|
93
|
+
],
|
|
94
|
+
[
|
|
95
|
+
_ILogger.LogLevel.Error,
|
|
96
|
+
_colorette.red
|
|
97
|
+
],
|
|
98
|
+
[
|
|
99
|
+
_ILogger.LogLevel.Fatal,
|
|
100
|
+
_colorette.bgRed
|
|
101
|
+
],
|
|
102
|
+
[
|
|
103
|
+
_ILogger.LogLevel.None,
|
|
104
|
+
_colorette.white
|
|
105
|
+
]
|
|
106
|
+
]);
|
|
107
|
+
static DEFAULT_NAMES = new Map([
|
|
108
|
+
[
|
|
109
|
+
_ILogger.LogLevel.Trace,
|
|
110
|
+
"TRACE"
|
|
111
|
+
],
|
|
112
|
+
[
|
|
113
|
+
_ILogger.LogLevel.Debug,
|
|
114
|
+
"DEBUG"
|
|
115
|
+
],
|
|
116
|
+
[
|
|
117
|
+
_ILogger.LogLevel.Info,
|
|
118
|
+
"INFO"
|
|
119
|
+
],
|
|
120
|
+
[
|
|
121
|
+
_ILogger.LogLevel.Warn,
|
|
122
|
+
"WARN"
|
|
123
|
+
],
|
|
124
|
+
[
|
|
125
|
+
_ILogger.LogLevel.Error,
|
|
126
|
+
"ERROR"
|
|
127
|
+
],
|
|
128
|
+
[
|
|
129
|
+
_ILogger.LogLevel.Fatal,
|
|
130
|
+
"FATAL"
|
|
131
|
+
],
|
|
132
|
+
[
|
|
133
|
+
_ILogger.LogLevel.None,
|
|
134
|
+
""
|
|
135
|
+
]
|
|
136
|
+
]);
|
|
137
|
+
constructor(options = {}){
|
|
138
|
+
this.level = options.level ?? _ILogger.LogLevel.Info;
|
|
139
|
+
this.console = new _console.Console(options.stdout ?? process.stdout, options.stderr ?? process.stderr);
|
|
140
|
+
this.formats = this.createFormatMap(options.format, options.defaultFormat ?? options.format?.none ?? {});
|
|
141
|
+
this.join = options.join ?? " ";
|
|
142
|
+
this.depth = options.depth ?? 2;
|
|
143
|
+
}
|
|
144
|
+
static getInstance() {
|
|
145
|
+
if (!this.instance) {
|
|
146
|
+
this.instance = new Logger();
|
|
147
|
+
}
|
|
148
|
+
return this.instance;
|
|
149
|
+
}
|
|
150
|
+
static get stylize() {
|
|
151
|
+
return _colorette.isColorSupported;
|
|
152
|
+
}
|
|
153
|
+
setLevel(level) {
|
|
154
|
+
this.level = level;
|
|
155
|
+
}
|
|
156
|
+
has(level) {
|
|
157
|
+
return level >= this.level;
|
|
158
|
+
}
|
|
159
|
+
trace(...values) {
|
|
160
|
+
this.write(_ILogger.LogLevel.Trace, ...values);
|
|
161
|
+
}
|
|
162
|
+
debug(...values) {
|
|
163
|
+
this.write(_ILogger.LogLevel.Debug, ...values);
|
|
164
|
+
}
|
|
165
|
+
info(...values) {
|
|
166
|
+
this.write(_ILogger.LogLevel.Info, ...values);
|
|
167
|
+
}
|
|
168
|
+
log(...values) {
|
|
169
|
+
this.write(_ILogger.LogLevel.Info, ...values);
|
|
170
|
+
}
|
|
171
|
+
warn(...values) {
|
|
172
|
+
this.write(_ILogger.LogLevel.Warn, ...values);
|
|
173
|
+
}
|
|
174
|
+
error(...values) {
|
|
175
|
+
this.write(_ILogger.LogLevel.Error, ...values);
|
|
176
|
+
}
|
|
177
|
+
fatal(...values) {
|
|
178
|
+
this.write(_ILogger.LogLevel.Fatal, ...values);
|
|
179
|
+
}
|
|
180
|
+
write(level, ...values) {
|
|
181
|
+
if (level < this.level) return;
|
|
182
|
+
const method = Logger.LOG_METHODS.get(level);
|
|
183
|
+
const formatter = this.formats.get(level) ?? this.formats.get(_ILogger.LogLevel.None);
|
|
184
|
+
const message = formatter.run(this.preprocess(values));
|
|
185
|
+
switch(method){
|
|
186
|
+
case "trace":
|
|
187
|
+
this.console.trace(message);
|
|
188
|
+
break;
|
|
189
|
+
case "debug":
|
|
190
|
+
this.console.debug(message);
|
|
191
|
+
break;
|
|
192
|
+
case "info":
|
|
193
|
+
this.console.info(message);
|
|
194
|
+
break;
|
|
195
|
+
case "warn":
|
|
196
|
+
this.console.warn(message);
|
|
197
|
+
break;
|
|
198
|
+
case "error":
|
|
199
|
+
this.console.error(message);
|
|
200
|
+
break;
|
|
201
|
+
default:
|
|
202
|
+
this.console.log(message);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
preprocess(values) {
|
|
206
|
+
const inspectOptions = {
|
|
207
|
+
colors: _colorette.isColorSupported,
|
|
208
|
+
depth: this.depth
|
|
209
|
+
};
|
|
210
|
+
return values.map((value)=>typeof value === "string" ? value : (0, _util.inspect)(value, inspectOptions)).join(this.join);
|
|
211
|
+
}
|
|
212
|
+
createFormatMap(options = {}, defaults) {
|
|
213
|
+
const map = new Map();
|
|
214
|
+
for (const [level, color] of Logger.DEFAULT_COLORS){
|
|
215
|
+
const name = Logger.DEFAULT_NAMES.get(level);
|
|
216
|
+
const levelOptions = options[this.getLevelKey(level)] ?? this.createDefaultLevel(defaults, color, name ?? "");
|
|
217
|
+
map.set(level, levelOptions instanceof LoggerLevel ? levelOptions : new LoggerLevel(levelOptions));
|
|
218
|
+
}
|
|
219
|
+
return map;
|
|
220
|
+
}
|
|
221
|
+
createDefaultLevel(defaults, color, name) {
|
|
222
|
+
return new LoggerLevel({
|
|
223
|
+
...defaults,
|
|
224
|
+
timestamp: defaults.timestamp === null ? null : {
|
|
225
|
+
...defaults.timestamp,
|
|
226
|
+
color
|
|
227
|
+
},
|
|
228
|
+
infix: name.length ? `${color(name.padEnd(5, " "))} ` : ""
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
getLevelKey(level) {
|
|
232
|
+
const keys = {
|
|
233
|
+
[_ILogger.LogLevel.Trace]: "trace",
|
|
234
|
+
[_ILogger.LogLevel.Debug]: "debug",
|
|
235
|
+
[_ILogger.LogLevel.Info]: "info",
|
|
236
|
+
[_ILogger.LogLevel.Warn]: "warn",
|
|
237
|
+
[_ILogger.LogLevel.Error]: "error",
|
|
238
|
+
[_ILogger.LogLevel.Fatal]: "fatal",
|
|
239
|
+
[_ILogger.LogLevel.None]: "none"
|
|
240
|
+
};
|
|
241
|
+
return keys[level];
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
class LoggerStyle {
|
|
245
|
+
style;
|
|
246
|
+
constructor(resolvable = {}){
|
|
247
|
+
if (typeof resolvable === "function") {
|
|
248
|
+
this.style = resolvable;
|
|
249
|
+
} else {
|
|
250
|
+
const styles = this.buildStyleArray(resolvable);
|
|
251
|
+
this.style = this.combineStyles(styles);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
run(value) {
|
|
255
|
+
return this.style(String(value));
|
|
256
|
+
}
|
|
257
|
+
buildStyleArray(options) {
|
|
258
|
+
const styles = [];
|
|
259
|
+
if (options.effects) {
|
|
260
|
+
styles.push(...options.effects.map((effect)=>_colorette[effect]));
|
|
261
|
+
}
|
|
262
|
+
if (options.text) {
|
|
263
|
+
styles.push(_colorette[options.text]);
|
|
264
|
+
}
|
|
265
|
+
if (options.background) {
|
|
266
|
+
styles.push(_colorette[options.background]);
|
|
267
|
+
}
|
|
268
|
+
return styles;
|
|
269
|
+
}
|
|
270
|
+
combineStyles(styles) {
|
|
271
|
+
if (styles.length === 0) return _colorette.reset;
|
|
272
|
+
if (styles.length === 1) return styles[0];
|
|
273
|
+
return (text)=>styles.reduce((result, style)=>style(result), text);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
class LoggerTimestamp {
|
|
277
|
+
timestamp;
|
|
278
|
+
utc;
|
|
279
|
+
color;
|
|
280
|
+
formatter;
|
|
281
|
+
constructor(options = {}){
|
|
282
|
+
this.timestamp = new _timestamp.Timestamp(options.pattern ?? "YYYY-MM-DD HH:mm:ss");
|
|
283
|
+
this.utc = options.utc ?? false;
|
|
284
|
+
this.color = options.color === null ? null : new LoggerStyle(options.color);
|
|
285
|
+
this.formatter = options.formatter ?? ((timestamp)=>`${timestamp} `);
|
|
286
|
+
}
|
|
287
|
+
run() {
|
|
288
|
+
const date = new Date();
|
|
289
|
+
const result = this.utc ? this.timestamp.displayUTC(date) : this.timestamp.display(date);
|
|
290
|
+
return this.formatter(this.color ? this.color.run(result) : result);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
class LoggerLevel {
|
|
294
|
+
timestamp;
|
|
295
|
+
infix;
|
|
296
|
+
message;
|
|
297
|
+
constructor(options = {}){
|
|
298
|
+
this.timestamp = options.timestamp === null ? null : new LoggerTimestamp(options.timestamp);
|
|
299
|
+
this.infix = options.infix ?? "";
|
|
300
|
+
this.message = options.message === null ? null : new LoggerStyle(options.message);
|
|
301
|
+
}
|
|
302
|
+
run(content) {
|
|
303
|
+
const prefix = (this.timestamp?.run() ?? "") + this.infix;
|
|
304
|
+
if (prefix.length) {
|
|
305
|
+
const formatter = this.message ? (line)=>prefix + this.message?.run(line) : (line)=>prefix + line;
|
|
306
|
+
return content.split("\n").map(formatter).join("\n");
|
|
307
|
+
}
|
|
308
|
+
return this.message ? this.message.run(content) : content;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
const _default = Logger.getInstance();
|
|
312
|
+
var LoggerStyleEffect = /*#__PURE__*/ function(LoggerStyleEffect) {
|
|
313
|
+
LoggerStyleEffect["Reset"] = "reset";
|
|
314
|
+
LoggerStyleEffect["Bold"] = "bold";
|
|
315
|
+
LoggerStyleEffect["Dim"] = "dim";
|
|
316
|
+
LoggerStyleEffect["Italic"] = "italic";
|
|
317
|
+
LoggerStyleEffect["Underline"] = "underline";
|
|
318
|
+
LoggerStyleEffect["Inverse"] = "inverse";
|
|
319
|
+
LoggerStyleEffect["Hidden"] = "hidden";
|
|
320
|
+
LoggerStyleEffect["Strikethrough"] = "strikethrough";
|
|
321
|
+
return LoggerStyleEffect;
|
|
322
|
+
}({});
|
|
323
|
+
var LoggerStyleText = /*#__PURE__*/ function(LoggerStyleText) {
|
|
324
|
+
LoggerStyleText["Black"] = "black";
|
|
325
|
+
LoggerStyleText["Red"] = "red";
|
|
326
|
+
LoggerStyleText["Green"] = "green";
|
|
327
|
+
LoggerStyleText["Yellow"] = "yellow";
|
|
328
|
+
LoggerStyleText["Blue"] = "blue";
|
|
329
|
+
LoggerStyleText["Magenta"] = "magenta";
|
|
330
|
+
LoggerStyleText["Cyan"] = "cyan";
|
|
331
|
+
LoggerStyleText["White"] = "white";
|
|
332
|
+
LoggerStyleText["Gray"] = "gray";
|
|
333
|
+
LoggerStyleText["BlackBright"] = "blackBright";
|
|
334
|
+
LoggerStyleText["RedBright"] = "redBright";
|
|
335
|
+
LoggerStyleText["GreenBright"] = "greenBright";
|
|
336
|
+
LoggerStyleText["YellowBright"] = "yellowBright";
|
|
337
|
+
LoggerStyleText["BlueBright"] = "blueBright";
|
|
338
|
+
LoggerStyleText["MagentaBright"] = "magentaBright";
|
|
339
|
+
LoggerStyleText["CyanBright"] = "cyanBright";
|
|
340
|
+
LoggerStyleText["WhiteBright"] = "whiteBright";
|
|
341
|
+
return LoggerStyleText;
|
|
342
|
+
}({});
|
|
343
|
+
var LoggerStyleBackground = /*#__PURE__*/ function(LoggerStyleBackground) {
|
|
344
|
+
LoggerStyleBackground["Black"] = "bgBlack";
|
|
345
|
+
LoggerStyleBackground["Red"] = "bgRed";
|
|
346
|
+
LoggerStyleBackground["Green"] = "bgGreen";
|
|
347
|
+
LoggerStyleBackground["Yellow"] = "bgYellow";
|
|
348
|
+
LoggerStyleBackground["Blue"] = "bgBlue";
|
|
349
|
+
LoggerStyleBackground["Magenta"] = "bgMagenta";
|
|
350
|
+
LoggerStyleBackground["Cyan"] = "bgCyan";
|
|
351
|
+
LoggerStyleBackground["White"] = "bgWhite";
|
|
352
|
+
LoggerStyleBackground["BlackBright"] = "bgBlackBright";
|
|
353
|
+
LoggerStyleBackground["RedBright"] = "bgRedBright";
|
|
354
|
+
LoggerStyleBackground["GreenBright"] = "bgGreenBright";
|
|
355
|
+
LoggerStyleBackground["YellowBright"] = "bgYellowBright";
|
|
356
|
+
LoggerStyleBackground["BlueBright"] = "bgBlueBright";
|
|
357
|
+
LoggerStyleBackground["MagentaBright"] = "bgMagentaBright";
|
|
358
|
+
LoggerStyleBackground["CyanBright"] = "bgCyanBright";
|
|
359
|
+
LoggerStyleBackground["WhiteBright"] = "bgWhiteBright";
|
|
360
|
+
return LoggerStyleBackground;
|
|
361
|
+
}({});
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { PrefixOptions } from "#types/client.js";
|
|
2
|
+
import { InteractionResponse, Message } from "discord.js";
|
|
3
|
+
export declare function deleteMessage(message: Message | InteractionResponse, time?: number): Promise<void>;
|
|
4
|
+
export declare function getPrefix(opts: PrefixOptions): string | false;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
get deleteMessage () {
|
|
13
|
+
return deleteMessage;
|
|
14
|
+
},
|
|
15
|
+
get getPrefix () {
|
|
16
|
+
return getPrefix;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
function deleteMessage(message, time = 15_000) {
|
|
20
|
+
return new Promise((r)=>{
|
|
21
|
+
setTimeout(()=>{
|
|
22
|
+
message.delete().catch(()=>{});
|
|
23
|
+
r();
|
|
24
|
+
}, time);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
function getPrefix(opts) {
|
|
28
|
+
if (typeof opts === "string") {
|
|
29
|
+
return opts;
|
|
30
|
+
}
|
|
31
|
+
if (opts.enabled && opts.prefix) {
|
|
32
|
+
return opts.prefix;
|
|
33
|
+
}
|
|
34
|
+
return false;
|
|
35
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arox/framework",
|
|
3
|
-
"version": "0.1.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"discord.js",
|
|
@@ -19,6 +19,9 @@
|
|
|
19
19
|
"type": "commonjs",
|
|
20
20
|
"main": "dist/index.js",
|
|
21
21
|
"types": "dist/index.d.ts",
|
|
22
|
+
"imports": {
|
|
23
|
+
"#types/*": "./types/*"
|
|
24
|
+
},
|
|
22
25
|
"scripts": {
|
|
23
26
|
"prepare": "node scripts/prepareHusky.js",
|
|
24
27
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
@@ -30,8 +33,16 @@
|
|
|
30
33
|
"release:git": "node scripts/actions/github.js",
|
|
31
34
|
"release:npm": "node scripts/actions/npm.js"
|
|
32
35
|
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@sapphire/timestamp": "^1.0.5",
|
|
38
|
+
"@swc/helpers": "^0.5.18",
|
|
39
|
+
"colorette": "^2.0.20",
|
|
40
|
+
"fast-glob": "^3.3.3",
|
|
41
|
+
"lodash": "^4.17.21"
|
|
42
|
+
},
|
|
33
43
|
"devDependencies": {
|
|
34
44
|
"@swc/cli": "^0.7.10",
|
|
45
|
+
"@types/lodash": "^4.17.23",
|
|
35
46
|
"@types/node": "^25.0.8",
|
|
36
47
|
"husky": "^9.1.7",
|
|
37
48
|
"libnpmpack": "^9.0.12",
|
|
@@ -39,5 +50,8 @@
|
|
|
39
50
|
"oxlint": "^1.39.0",
|
|
40
51
|
"oxlint-tsgolint": "^0.11.0",
|
|
41
52
|
"typescript": "^5.9.3"
|
|
53
|
+
},
|
|
54
|
+
"peerDependencies": {
|
|
55
|
+
"discord.js": ">=14.25.1"
|
|
42
56
|
}
|
|
43
57
|
}
|