@arox/framework 0.1.0 → 0.1.2-beta.1

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,74 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "CommandBuilder", {
6
- enumerable: true,
7
- get: function() {
8
- return CommandBuilder;
9
- }
10
- });
11
- const _Argument = require("./Argument");
12
- const _context = require("../context");
13
- class CommandBuilder {
14
- client;
15
- logger;
16
- name;
17
- description;
18
- aliases;
19
- options;
20
- _supportsSlash;
21
- _supportsPrefix;
22
- _onMessage;
23
- _onInteraction;
24
- get supportsSlash() {
25
- return this._supportsSlash && this._onInteraction;
26
- }
27
- get supportsPrefix() {
28
- return this._supportsPrefix && this._onMessage;
29
- }
30
- constructor(options){
31
- const client = _context.currentClient;
32
- if (!client) throw new Error("Client is not defined");
33
- this.client = client;
34
- this.logger = client.logger;
35
- this.name = options.name;
36
- this.description = options.description;
37
- this.aliases = options.aliases ?? [];
38
- this.options = (options.options ?? []).map((opt)=>{
39
- return opt instanceof _Argument.Argument ? opt.toJSON() : opt;
40
- });
41
- this._supportsPrefix = options.prefix ?? false;
42
- this._supportsSlash = options.slash ?? false;
43
- if (!this._supportsPrefix && !this._supportsSlash) {
44
- throw new Error(`Command ${this.name} must support either slash or prefix commands.`);
45
- }
46
- if (this.client.commands.has(this.name)) throw new Error(`Command name "${this.name}" is already registered.`);
47
- const existingAliasOwner = this.client.aliases.findKey((aliases)=>aliases.has(this.name));
48
- if (existingAliasOwner) {
49
- throw new Error(`Command name "${this.name}" is already registered as an alias for command "${existingAliasOwner}".`);
50
- }
51
- for (const alias of this.aliases){
52
- if (this.client.commands.has(alias)) {
53
- throw new Error(`Alias "${alias}" is already registered as a command name.`);
54
- }
55
- const conflictingCommand = this.client.aliases.findKey((aliases)=>aliases.has(alias));
56
- if (conflictingCommand) {
57
- throw new Error(`Alias "${alias}" is already registered as an alias for command "${conflictingCommand}".`);
58
- }
59
- }
60
- this.client.commands.set(this.name, this);
61
- if (this.aliases.length > 0) {
62
- this.client.aliases.set(this.name, new Set(this.aliases));
63
- }
64
- this.logger.debug(`Loaded Command ${this.name}`);
65
- }
66
- onMessage(func) {
67
- this._onMessage = func;
68
- return this;
69
- }
70
- onInteraction(func) {
71
- this._onInteraction = func;
72
- return this;
73
- }
74
- }
@@ -1,56 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "Context", {
6
- enumerable: true,
7
- get: function() {
8
- return Context;
9
- }
10
- });
11
- const _discord = require("discord.js");
12
- class Context {
13
- client;
14
- args;
15
- data;
16
- constructor(client, payload){
17
- this.client = client;
18
- this.args = payload.args ?? [];
19
- if ("interaction" in payload) {
20
- this.data = payload.interaction;
21
- } else {
22
- this.data = payload.message;
23
- }
24
- }
25
- isInteraction() {
26
- return this.data instanceof _discord.ChatInputCommandInteraction;
27
- }
28
- isMessage() {
29
- return this.data instanceof _discord.Message;
30
- }
31
- get author() {
32
- if (this.isInteraction()) {
33
- return this.data.user;
34
- }
35
- if (this.isMessage()) {
36
- return this.data.author;
37
- }
38
- return null;
39
- }
40
- toJSON() {
41
- const { data, args, author } = this;
42
- if (this.isInteraction()) {
43
- return {
44
- kind: "interaction",
45
- interaction: data,
46
- author: author
47
- };
48
- }
49
- return {
50
- kind: "message",
51
- message: data,
52
- args: args,
53
- author: author
54
- };
55
- }
56
- }
@@ -1,53 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "EventBuilder", {
6
- enumerable: true,
7
- get: function() {
8
- return EventBuilder;
9
- }
10
- });
11
- const _context = require("../context");
12
- class EventBuilder {
13
- name;
14
- once;
15
- client;
16
- logger;
17
- handler;
18
- bound = false;
19
- listener = async (...args)=>{
20
- if (!this.handler) return;
21
- try {
22
- await this.handler(this, ...args);
23
- } catch (error) {
24
- this.client.logger.error(`Error executing event ${this.name} (${this.constructor.name}):`, error);
25
- }
26
- };
27
- constructor(name, once = false, _handler){
28
- this.name = name;
29
- this.once = once;
30
- if (!_context.currentClient) throw new Error("Client is not defined");
31
- this.client = _context.currentClient;
32
- this.logger = _context.currentClient.logger;
33
- if (_handler) {
34
- this.handler = _handler;
35
- this.register();
36
- }
37
- this.logger.debug(`Loaded Event ${String(this.name)}`);
38
- }
39
- register() {
40
- if (this.bound || !this.handler) return;
41
- if (this.once) {
42
- this.client.once(this.name, this.listener);
43
- } else {
44
- this.client.on(this.name, this.listener);
45
- }
46
- this.bound = true;
47
- }
48
- onExecute(func) {
49
- this.handler = func;
50
- this.register();
51
- return this;
52
- }
53
- }
@@ -1,47 +0,0 @@
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 getFiles () {
13
- return getFiles;
14
- },
15
- get getProjectRoot () {
16
- return getProjectRoot;
17
- }
18
- });
19
- const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
20
- const _fastglob = /*#__PURE__*/ _interop_require_default._(require("fast-glob"));
21
- const _path = /*#__PURE__*/ _interop_require_default._(require("path"));
22
- function getFiles(baseDir) {
23
- return _fastglob.default.sync([
24
- "**/*.ts",
25
- "**/*.js"
26
- ], {
27
- cwd: baseDir,
28
- absolute: true,
29
- ignore: [
30
- "**/*.d.ts",
31
- "node_modules/**",
32
- ".git/**",
33
- "dist/**",
34
- "lib/**",
35
- "out/**",
36
- "build/**",
37
- ".next/**",
38
- "coverage/**"
39
- ]
40
- });
41
- }
42
- function getProjectRoot() {
43
- if (!require.main?.filename) {
44
- return process.cwd();
45
- }
46
- return _path.default.dirname(require.main.filename);
47
- }
@@ -1,37 +0,0 @@
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
- }({});
@@ -1,361 +0,0 @@
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
- }({});
@@ -1,35 +0,0 @@
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
- }