virello 0.1.0 → 0.1.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.
- package/BREAKING_CHANGES.md +19 -0
- package/README.md +15 -15
- package/docs/console-logging.md +25 -25
- package/docs/engine.md +8 -8
- package/docs/sharding-recovery.md +3 -3
- package/docs/sharding-scaling.md +2 -2
- package/docs/sharding-stats.md +3 -3
- package/examples/README.md +12 -12
- package/examples/bot.ts +2 -2
- package/examples/client.ts +4 -4
- package/examples/commands/ping.ts +1 -1
- package/examples/commands/shard.ts +2 -2
- package/examples/commands/stats.ts +2 -2
- package/examples/config.ts +1 -1
- package/examples/contracts.ts +1 -1
- package/examples/coordinator.ts +1 -1
- package/examples/engine/live.ts +3 -3
- package/examples/engine/offline.ts +2 -2
- package/examples/host.ts +1 -1
- package/examples/listeners/ready.ts +2 -2
- package/examples/logging.ts +1 -1
- package/examples/offline.ts +2 -2
- package/examples/registration.ts +2 -2
- package/examples/shutdown.ts +1 -1
- package/examples/stats.ts +1 -1
- package/package.json +2 -2
- package/src/commands/checks/containers/Entry.ts +3 -3
- package/src/commands/registration/computeDifferences/option/channelTypes.ts +1 -1
- package/src/commands/registration/computeDifferences/option/type.ts +2 -2
- package/src/commands/registration/computeDifferences/options.ts +3 -3
- package/src/commands/types.ts +1 -1
- package/src/core/Container.ts +5 -5
- package/src/core/client/{RiloClient.ts → VirelloClient.ts} +24 -19
- package/src/core/config/extensions.ts +1 -1
- package/src/core/index.ts +1 -1
- package/src/core/lifecycle/Extension.ts +5 -5
- package/src/core/loading/constants.ts +1 -1
- package/src/core/logging/LoggerLike.ts +5 -5
- package/src/core/logging/console.ts +9 -9
- package/src/core/logging/format.ts +3 -3
- package/src/core/runtime.ts +1 -1
- package/src/engine/gateway/GatewayShard.ts +2 -2
- package/src/engine/rest/RestClient.ts +2 -1
- package/src/events/events.ts +74 -59
- package/src/extensions/localisation/extension.ts +2 -2
- package/src/extensions/patternCommands/extension.ts +2 -2
- package/src/extensions/scheduledTasks/backends/RedisBackend.ts +1 -1
- package/src/extensions/scheduledTasks/extension.ts +2 -2
- package/src/extensions/scheduledTasks/types/TaskTypes.ts +1 -1
- package/src/extensions/services/extension.ts +2 -2
- package/src/extensions/subcommands/extension.ts +2 -2
- package/src/index.ts +1 -1
- package/src/public/client.ts +2 -2
- package/src/sharding/client/Link.ts +5 -5
- package/src/sharding/client/gateway.ts +1 -1
- package/src/sharding/coordinator/Coordinator.ts +4 -4
- package/src/sharding/manager/Manager.ts +6 -6
- package/src/sharding/stats.ts +1 -1
- package/src/sharding/types.ts +3 -3
- package/src/utilities/collections/bitfield/BitField.ts +1 -1
- package/src/utilities/decorators/module-decorators.ts +1 -1
- package/src/utilities/discord/pagination/PaginatedMessage.ts +10 -10
- package/src/utilities/discord/pagination/Pagination.ts +1 -1
- package/src/utilities/discord/snowflake/Snowflake.ts +5 -5
- package/src/utilities/parsing/strategies/FlagUnorderedStrategy.ts +1 -1
- package/src/utilities/result/Option.ts +2 -2
- package/src/utilities/result/Result.ts +3 -3
|
@@ -22,7 +22,7 @@ import type { IPreconditionContainer } from "./Container";
|
|
|
22
22
|
|
|
23
23
|
/** Defines the simple options for the {@link PreconditionContainerSingle}, where only the name of the precondition can be defined. */
|
|
24
24
|
export interface SimplePreconditionSingleResolvableDetails {
|
|
25
|
-
/** The name of the precondition to retrieve from {@link
|
|
25
|
+
/** The name of the precondition to retrieve from {@link VirelloClient.preconditions}. */
|
|
26
26
|
name: SimplePreconditionKeys;
|
|
27
27
|
}
|
|
28
28
|
|
|
@@ -30,7 +30,7 @@ export interface SimplePreconditionSingleResolvableDetails {
|
|
|
30
30
|
export interface PreconditionSingleResolvableDetails<
|
|
31
31
|
K extends PreconditionKeys = PreconditionKeys,
|
|
32
32
|
> {
|
|
33
|
-
/** The name of the precondition to retrieve from {@link
|
|
33
|
+
/** The name of the precondition to retrieve from {@link VirelloClient.preconditions}. */
|
|
34
34
|
name: K;
|
|
35
35
|
|
|
36
36
|
/** The context to be set at {@link PreconditionContainerSingle.context}. */
|
|
@@ -43,7 +43,7 @@ export type PreconditionSingleResolvable =
|
|
|
43
43
|
| SimplePreconditionSingleResolvableDetails
|
|
44
44
|
| PreconditionSingleResolvableDetails;
|
|
45
45
|
|
|
46
|
-
/** An {@link IPreconditionContainer} which runs a single precondition from {@link
|
|
46
|
+
/** An {@link IPreconditionContainer} which runs a single precondition from {@link VirelloClient.preconditions}. */
|
|
47
47
|
export class PreconditionContainerSingle implements IPreconditionContainer {
|
|
48
48
|
/** Context passed to the precondition. String entries get an empty object. */
|
|
49
49
|
public readonly context: Record<PropertyKey, unknown>;
|
|
@@ -26,7 +26,7 @@ const channelTypeToPrettyName: Record<
|
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
const unknownChannelType = (type: number): string =>
|
|
29
|
-
`unknown channel type (${type}); please contact
|
|
29
|
+
`unknown channel type (${type}); please contact Virello developers about this!`;
|
|
30
30
|
|
|
31
31
|
function getChannelTypePrettyName(
|
|
32
32
|
type: keyof typeof channelTypeToPrettyName,
|
|
@@ -12,14 +12,14 @@ export function* checkOptionType({
|
|
|
12
12
|
}): Generator<CommandDifference> {
|
|
13
13
|
const expectedTypeString =
|
|
14
14
|
optionTypeToPrettyName.get(expectedType) ??
|
|
15
|
-
`unknown (${expectedType}); please contact
|
|
15
|
+
`unknown (${expectedType}); please contact Virello developers about this!`;
|
|
16
16
|
|
|
17
17
|
if (originalType !== expectedType) {
|
|
18
18
|
yield {
|
|
19
19
|
key,
|
|
20
20
|
original:
|
|
21
21
|
optionTypeToPrettyName.get(originalType) ??
|
|
22
|
-
`unknown (${originalType}); please contact
|
|
22
|
+
`unknown (${originalType}); please contact Virello developers about this!`,
|
|
23
23
|
expected: expectedTypeString,
|
|
24
24
|
};
|
|
25
25
|
}
|
|
@@ -62,7 +62,7 @@ export function* checkOptions(
|
|
|
62
62
|
while ((option = existingOptions![index]) !== undefined) {
|
|
63
63
|
const expectedType =
|
|
64
64
|
optionTypeToPrettyName.get(option.type) ??
|
|
65
|
-
`unknown (${option.type}); please contact
|
|
65
|
+
`unknown (${option.type}); please contact Virello developers about this!`;
|
|
66
66
|
|
|
67
67
|
yield {
|
|
68
68
|
key: `existing command option at index ${index}`,
|
|
@@ -91,7 +91,7 @@ function* reportOptionDifferences({
|
|
|
91
91
|
if (!existingOption) {
|
|
92
92
|
const expectedType =
|
|
93
93
|
optionTypeToPrettyName.get(option.type) ??
|
|
94
|
-
`unknown (${option.type}); please contact
|
|
94
|
+
`unknown (${option.type}); please contact Virello developers about this!`;
|
|
95
95
|
|
|
96
96
|
yield {
|
|
97
97
|
key: keyPath(currentIndex),
|
|
@@ -295,7 +295,7 @@ function* handleSubcommandOptions({
|
|
|
295
295
|
while ((option = existingOptions![processedIndex]) !== undefined) {
|
|
296
296
|
const expectedType =
|
|
297
297
|
optionTypeToPrettyName.get(option.type) ??
|
|
298
|
-
`unknown (${option.type}); please contact
|
|
298
|
+
`unknown (${option.type}); please contact Virello developers about this!`;
|
|
299
299
|
|
|
300
300
|
yield {
|
|
301
301
|
key: `existing command option at path ${keyPath(currentIndex)}.options[${processedIndex}]`,
|
package/src/commands/types.ts
CHANGED
|
@@ -18,7 +18,7 @@ import type { ApplicationCommandRegistry } from "./registration/Registry";
|
|
|
18
18
|
export type DetailedDescriptionCommand =
|
|
19
19
|
string | DetailedDescriptionCommandObject;
|
|
20
20
|
|
|
21
|
-
/** Augmentable shape for application-specific command help data.
|
|
21
|
+
/** Augmentable shape for application-specific command help data. Virello stores it without interpreting its fields. */
|
|
22
22
|
export interface DetailedDescriptionCommandObject {}
|
|
23
23
|
|
|
24
24
|
/** The allowed values for {@link CommandOptions.runIn}. */
|
package/src/core/Container.ts
CHANGED
|
@@ -3,16 +3,16 @@ import type { LocaleManager } from "../extensions/localisation/LocaleManager";
|
|
|
3
3
|
import type { TaskScheduler } from "../extensions/scheduledTasks/TaskScheduler";
|
|
4
4
|
import type { Services } from "../extensions/services/Services";
|
|
5
5
|
import type { ShardLink } from "../sharding/client/Link";
|
|
6
|
-
import type {
|
|
6
|
+
import type { VirelloClient } from "./client/VirelloClient";
|
|
7
7
|
import type { LoggerLike } from "./logging/LoggerLike";
|
|
8
8
|
import { ModuleRegistry } from "./modules/ModuleRegistry";
|
|
9
9
|
|
|
10
|
-
/** Shared client services. Add your own properties by augmenting
|
|
10
|
+
/** Shared client services. Add your own properties by augmenting virello. */
|
|
11
11
|
export interface Container {
|
|
12
12
|
/** The current module registry; initialized even before a client is created. */
|
|
13
13
|
modules: ModuleRegistry;
|
|
14
|
-
/** The active
|
|
15
|
-
client:
|
|
14
|
+
/** The active VirelloClient. Available after construction and removed on shutdown. */
|
|
15
|
+
client: VirelloClient;
|
|
16
16
|
/** The active client's shard messaging and live stats API. */
|
|
17
17
|
readonly sharding: ShardLink;
|
|
18
18
|
/** The active client’s logger. Assigned during client construction. */
|
|
@@ -30,7 +30,7 @@ export interface Container {
|
|
|
30
30
|
services: Services;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
/** Shared framework services. Client-specific entries are populated by
|
|
33
|
+
/** Shared framework services. Client-specific entries are populated by VirelloClient and enabled extensions. */
|
|
34
34
|
export const container = {
|
|
35
35
|
/** Initial shared registry, replaced by the active client’s module registry. */
|
|
36
36
|
modules: new ModuleRegistry(),
|
|
@@ -50,8 +50,8 @@ export type Prefix = string | readonly string[] | null;
|
|
|
50
50
|
*/
|
|
51
51
|
export type PrefixHook = (message: Message) => Awaitable<Prefix>;
|
|
52
52
|
|
|
53
|
-
/**
|
|
54
|
-
export interface
|
|
53
|
+
/** Virello options added to discord.js ClientOptions. */
|
|
54
|
+
export interface VirelloClientOptions {
|
|
55
55
|
/** Configure built-in features and custom extensions. Built-ins run first, in the documented extension order. */
|
|
56
56
|
extensions?: ExtensionOptions;
|
|
57
57
|
/** Base directory for module patterns. Defaults to cwd. */
|
|
@@ -73,7 +73,7 @@ export interface RiloClientOptions {
|
|
|
73
73
|
/** The regex prefix, an alternative to a mention or regular prefix to allow creating natural language command messages */
|
|
74
74
|
regexPrefix?: RegExp;
|
|
75
75
|
|
|
76
|
-
/** The prefix hook, by default it is a callback function that returns {@link
|
|
76
|
+
/** The prefix hook, by default it is a callback function that returns {@link VirelloClientOptions.defaultPrefix}.
|
|
77
77
|
* @default () => client.options.defaultPrefix */
|
|
78
78
|
fetchPrefix?: PrefixHook;
|
|
79
79
|
|
|
@@ -82,7 +82,7 @@ export interface RiloClientOptions {
|
|
|
82
82
|
|
|
83
83
|
/** Supply your logger instance directly. Its identity and settings are preserved. */
|
|
84
84
|
logger?: LoggerLike;
|
|
85
|
-
/** Used only when
|
|
85
|
+
/** Used only when Virello creates its own logger. */
|
|
86
86
|
loggerOptions?: Partial<LoggerOptions>;
|
|
87
87
|
/** Formatting for the framework-created console logger. Supplied loggers are untouched. */
|
|
88
88
|
logging?: ConsoleLogOptions;
|
|
@@ -125,10 +125,12 @@ interface FeatureState {
|
|
|
125
125
|
restoreProperties: () => void;
|
|
126
126
|
active: boolean;
|
|
127
127
|
}
|
|
128
|
-
const clientState: { active?:
|
|
128
|
+
const clientState: { active?: VirelloClient } = {};
|
|
129
129
|
|
|
130
130
|
/** One active Discord client owns the shared services. */
|
|
131
|
-
export class
|
|
131
|
+
export class VirelloClient<
|
|
132
|
+
Ready extends boolean = boolean,
|
|
133
|
+
> extends Client<Ready> {
|
|
132
134
|
/** Bot user ID used for mention prefixes, or null before it is known. */
|
|
133
135
|
public override id: Snowflake | null = null;
|
|
134
136
|
/** Resolve prefixes for each message. Defaults to returning options.defaultPrefix or null. */
|
|
@@ -161,8 +163,8 @@ export class RiloClient<Ready extends boolean = boolean> extends Client<Ready> {
|
|
|
161
163
|
|
|
162
164
|
/**
|
|
163
165
|
* Create the shared client, register stores, and run synchronous extension setup. Discord connects at login.
|
|
164
|
-
* @param options - Discord client options, including intents and
|
|
165
|
-
* @throws If options are invalid, another
|
|
166
|
+
* @param options - Discord client options, including intents and Virello settings.
|
|
167
|
+
* @throws If options are invalid, another VirelloClient is active, or required setup fails. Managed children reject
|
|
166
168
|
* conflicting shard options.
|
|
167
169
|
*/
|
|
168
170
|
public constructor(options: ClientOptions) {
|
|
@@ -197,7 +199,7 @@ export class RiloClient<Ready extends boolean = boolean> extends Client<Ready> {
|
|
|
197
199
|
])
|
|
198
200
|
if (key in options)
|
|
199
201
|
throw new TypeError(
|
|
200
|
-
`
|
|
202
|
+
`Virello no longer supports "${key}". See BREAKING_CHANGES.md.`,
|
|
201
203
|
);
|
|
202
204
|
const extensions = resolveExtensions(options.extensions);
|
|
203
205
|
if (options.extensions?.scheduledtasks)
|
|
@@ -236,14 +238,14 @@ export class RiloClient<Ready extends boolean = boolean> extends Client<Ready> {
|
|
|
236
238
|
);
|
|
237
239
|
if (clientState.active)
|
|
238
240
|
throw new Error(
|
|
239
|
-
"Only one
|
|
241
|
+
"Only one VirelloClient can be active. Await client.destroy() before creating another.",
|
|
240
242
|
);
|
|
241
243
|
super(options);
|
|
242
244
|
this.extensions = extensions;
|
|
243
245
|
this.logger =
|
|
244
246
|
options.logger ??
|
|
245
247
|
(this.ownedLogger = createConsoleLogger(
|
|
246
|
-
"
|
|
248
|
+
"Virello",
|
|
247
249
|
options.loggerOptions,
|
|
248
250
|
options.logging,
|
|
249
251
|
));
|
|
@@ -350,7 +352,7 @@ export class RiloClient<Ready extends boolean = boolean> extends Client<Ready> {
|
|
|
350
352
|
*/
|
|
351
353
|
public load(): Promise<void> {
|
|
352
354
|
if (this.closed)
|
|
353
|
-
return Promise.reject(new Error("This
|
|
355
|
+
return Promise.reject(new Error("This VirelloClient is closed."));
|
|
354
356
|
return this.modules.load();
|
|
355
357
|
}
|
|
356
358
|
|
|
@@ -362,7 +364,7 @@ export class RiloClient<Ready extends boolean = boolean> extends Client<Ready> {
|
|
|
362
364
|
*/
|
|
363
365
|
public override login(token?: string): Promise<string> {
|
|
364
366
|
if (this.closed)
|
|
365
|
-
return Promise.reject(new Error("This
|
|
367
|
+
return Promise.reject(new Error("This VirelloClient is closed."));
|
|
366
368
|
this.loginPromise ??= this.connect(token);
|
|
367
369
|
return this.loginPromise;
|
|
368
370
|
}
|
|
@@ -592,11 +594,14 @@ export class RiloClient<Ready extends boolean = boolean> extends Client<Ready> {
|
|
|
592
594
|
}
|
|
593
595
|
if (clientState.active === this) clientState.active = undefined;
|
|
594
596
|
if (errors.length)
|
|
595
|
-
throw new AggregateError(
|
|
597
|
+
throw new AggregateError(
|
|
598
|
+
errors,
|
|
599
|
+
"Some Virello features could not close.",
|
|
600
|
+
);
|
|
596
601
|
}
|
|
597
602
|
|
|
598
603
|
private assertOpen(): void {
|
|
599
|
-
if (this.closed) throw new Error("This
|
|
604
|
+
if (this.closed) throw new Error("This VirelloClient is closed.");
|
|
600
605
|
}
|
|
601
606
|
}
|
|
602
607
|
|
|
@@ -614,9 +619,9 @@ export interface CooldownOptions {
|
|
|
614
619
|
filteredCommands?: string[];
|
|
615
620
|
}
|
|
616
621
|
|
|
617
|
-
/** Add
|
|
622
|
+
/** Add Virello client properties and options to discord.js types. */
|
|
618
623
|
declare module "discord.js" {
|
|
619
|
-
/** Framework services available on a
|
|
624
|
+
/** Framework services available on a VirelloClient. */
|
|
620
625
|
interface Client {
|
|
621
626
|
/** Bot user ID used for mention prefixes, or null before it is known. */
|
|
622
627
|
id: Snowflake | null;
|
|
@@ -628,8 +633,8 @@ declare module "discord.js" {
|
|
|
628
633
|
fetchPrefix: PrefixHook;
|
|
629
634
|
}
|
|
630
635
|
|
|
631
|
-
/** Discord client options with
|
|
632
|
-
interface ClientOptions extends
|
|
636
|
+
/** Discord client options with Virello configuration. */
|
|
637
|
+
interface ClientOptions extends VirelloClientOptions {
|
|
633
638
|
/** Configure built-in features and custom extensions. */
|
|
634
639
|
extensions?: ExtensionOptions;
|
|
635
640
|
}
|
|
@@ -5,7 +5,7 @@ import { TasksExtension } from "../../extensions/scheduledTasks/extension";
|
|
|
5
5
|
import type { TaskSchedulerOptions } from "../../extensions/scheduledTasks/types/TaskTypes";
|
|
6
6
|
import { ServicesExtension } from "../../extensions/services/extension";
|
|
7
7
|
import { SubcommandsExtension } from "../../extensions/subcommands/extension";
|
|
8
|
-
import type { CooldownOptions } from "../client/
|
|
8
|
+
import type { CooldownOptions } from "../client/VirelloClient";
|
|
9
9
|
import { Extension } from "../lifecycle/Extension";
|
|
10
10
|
|
|
11
11
|
/** Settings for subcommand handling. */
|
package/src/core/index.ts
CHANGED
|
@@ -38,7 +38,7 @@ export * from "../events/listenerModuleLoader";
|
|
|
38
38
|
export * from "../events/listenerStore";
|
|
39
39
|
export type { Awaitable } from "../utilities/index";
|
|
40
40
|
export * from "../utilities/result/index";
|
|
41
|
-
export * from "./client/
|
|
41
|
+
export * from "./client/VirelloClient";
|
|
42
42
|
export * from "./lifecycle/Extension";
|
|
43
43
|
export * from "./logging/index";
|
|
44
44
|
export * from "./logging/LoggerLike";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Awaitable } from "../../utilities/index";
|
|
2
|
-
import type {
|
|
2
|
+
import type { VirelloClient } from "../client/VirelloClient";
|
|
3
3
|
|
|
4
|
-
/** Base class for client features. Override static hooks;
|
|
4
|
+
/** Base class for client features. Override static hooks; Virello uses the class without constructing it. */
|
|
5
5
|
export abstract class Extension {
|
|
6
6
|
/** Fail client startup when a hook fails if true. Otherwise disable this feature and clean up its registrations. Defaults to false. */
|
|
7
7
|
static readonly critical: boolean = false;
|
|
@@ -9,17 +9,17 @@ export abstract class Extension {
|
|
|
9
9
|
* Register stores, modules, and resources synchronously during client construction.
|
|
10
10
|
* @param _client - Client being configured. Use addDisposer for owned resources.
|
|
11
11
|
*/
|
|
12
|
-
static setup(_client:
|
|
12
|
+
static setup(_client: VirelloClient): void {}
|
|
13
13
|
/**
|
|
14
14
|
* Prepare services after modules and managed sharding load, before Discord login. Hooks run in extension order.
|
|
15
15
|
* @param _client - Client being started.
|
|
16
16
|
* @returns Completion of this phase.
|
|
17
17
|
*/
|
|
18
|
-
static beforeLogin(_client:
|
|
18
|
+
static beforeLogin(_client: VirelloClient): Awaitable<void> {}
|
|
19
19
|
/**
|
|
20
20
|
* Start work after Discord login finishes. Hooks run in extension order.
|
|
21
21
|
* @param _client - Connected client.
|
|
22
22
|
* @returns Completion of this phase.
|
|
23
23
|
*/
|
|
24
|
-
static afterLogin(_client:
|
|
24
|
+
static afterLogin(_client: VirelloClient): Awaitable<void> {}
|
|
25
25
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const VirtualPath = "::virtual::";
|
|
2
|
-
export const RegisteredModules = Symbol("
|
|
2
|
+
export const RegisteredModules = Symbol("virello:registeredModules");
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
/** The four methods
|
|
1
|
+
/** The four methods Virello uses. Existing logger instances stay untouched. */
|
|
2
2
|
export interface LoggerLike {
|
|
3
3
|
/**
|
|
4
4
|
* Write diagnostic detail.
|
|
5
5
|
* @param value - Log value.
|
|
6
|
-
* @returns The logger’s own result;
|
|
6
|
+
* @returns The logger’s own result; Virello ignores it.
|
|
7
7
|
*/
|
|
8
8
|
debug(value: unknown): unknown;
|
|
9
9
|
/**
|
|
10
10
|
* Write an informational notice.
|
|
11
11
|
* @param value - Log value.
|
|
12
|
-
* @returns The logger’s own result;
|
|
12
|
+
* @returns The logger’s own result; Virello ignores it.
|
|
13
13
|
*/
|
|
14
14
|
notif(value: unknown): unknown;
|
|
15
15
|
/**
|
|
16
16
|
* Write a warning.
|
|
17
17
|
* @param value - Log value.
|
|
18
|
-
* @returns The logger’s own result;
|
|
18
|
+
* @returns The logger’s own result; Virello ignores it.
|
|
19
19
|
*/
|
|
20
20
|
alert(value: unknown): unknown;
|
|
21
21
|
/**
|
|
22
22
|
* Write a failure.
|
|
23
23
|
* @param value - Log value, usually an Error.
|
|
24
|
-
* @returns The logger’s own result;
|
|
24
|
+
* @returns The logger’s own result; Virello ignores it.
|
|
25
25
|
*/
|
|
26
26
|
error(value: unknown): unknown;
|
|
27
27
|
}
|
|
@@ -59,7 +59,7 @@ function widthFor(settings: Settings, level: LogLevel): number {
|
|
|
59
59
|
return textWidth(
|
|
60
60
|
settings.output.width ??
|
|
61
61
|
settings.options.box?.width ??
|
|
62
|
-
Number(process.env.
|
|
62
|
+
Number(process.env.VIRELLO_LOG_WIDTH),
|
|
63
63
|
detected,
|
|
64
64
|
);
|
|
65
65
|
}
|
|
@@ -138,18 +138,18 @@ function serialize(
|
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
/**
|
|
141
|
-
* Create a logger with
|
|
142
|
-
* @param name - Logger name; defaults to
|
|
141
|
+
* Create a logger with Virello console formatting and the native logger’s streams, filters, and file lifecycle.
|
|
142
|
+
* @param name - Logger name; defaults to Virello.
|
|
143
143
|
* @param options - Native logger settings.
|
|
144
144
|
* @param output - Console formatting and redaction settings.
|
|
145
145
|
* @returns A new logger. Await close() when its resources are no longer needed.
|
|
146
146
|
*/
|
|
147
147
|
export function createConsoleLogger(
|
|
148
|
-
name = "
|
|
148
|
+
name = "Virello",
|
|
149
149
|
options: Partial<LoggerOptions> = {},
|
|
150
150
|
output: ConsoleLogOptions = {},
|
|
151
151
|
): Logger {
|
|
152
|
-
const requestedLevel = process.env.
|
|
152
|
+
const requestedLevel = process.env.VIRELLO_LOG_LEVEL?.toLowerCase() ?? "info";
|
|
153
153
|
const level =
|
|
154
154
|
options.level ??
|
|
155
155
|
(Object.hasOwn(levels, requestedLevel) ? levels[requestedLevel] : "NOTIF");
|
|
@@ -161,15 +161,15 @@ export function createConsoleLogger(
|
|
|
161
161
|
options.relativePaths !== undefined
|
|
162
162
|
)
|
|
163
163
|
return new Logger({ name, level, ...options });
|
|
164
|
-
const layout = options.layout ?? process.env.
|
|
165
|
-
const detail = output.detail ?? process.env.
|
|
166
|
-
const stackSetting = output.stacks ?? process.env.
|
|
164
|
+
const layout = options.layout ?? process.env.VIRELLO_LOG_LAYOUT;
|
|
165
|
+
const detail = output.detail ?? process.env.VIRELLO_LOG_DETAIL;
|
|
166
|
+
const stackSetting = output.stacks ?? process.env.VIRELLO_LOG_STACKS;
|
|
167
167
|
const settings: Settings = {
|
|
168
168
|
options,
|
|
169
169
|
output,
|
|
170
170
|
format:
|
|
171
171
|
output.format ??
|
|
172
|
-
(process.env.
|
|
172
|
+
(process.env.VIRELLO_LOG_FORMAT === "json" ? "json" : "text"),
|
|
173
173
|
stacks:
|
|
174
174
|
stackSetting === "off" || stackSetting === "full"
|
|
175
175
|
? stackSetting
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { LogLevel } from "@lilsnibbi/logger";
|
|
2
2
|
import { dataProperty, safeContext, safeText } from "./redact";
|
|
3
3
|
|
|
4
|
-
/** Console output settings used when
|
|
4
|
+
/** Console output settings used when Virello creates a logger. */
|
|
5
5
|
export interface ConsoleLogOptions {
|
|
6
|
-
/** Overrides
|
|
6
|
+
/** Overrides VIRELLO_LOG_FORMAT. Default: text. */
|
|
7
7
|
format?: "text" | "json";
|
|
8
|
-
/** Overrides
|
|
8
|
+
/** Overrides VIRELLO_LOG_STACKS. Default: short (three source locations). */
|
|
9
9
|
stacks?: "off" | "short" | "full";
|
|
10
10
|
/** Additional credential values to scrub. Values shorter than six characters are ignored. */
|
|
11
11
|
redact?: readonly string[];
|
package/src/core/runtime.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
if (typeof Bun === "undefined")
|
|
2
|
-
throw new Error("
|
|
2
|
+
throw new Error("Virello runs on Bun. Start your bot with bun.");
|
|
@@ -273,7 +273,8 @@ export class RestClient {
|
|
|
273
273
|
);
|
|
274
274
|
try {
|
|
275
275
|
const headers = new Headers({
|
|
276
|
-
"User-Agent":
|
|
276
|
+
"User-Agent":
|
|
277
|
+
"VirelloEngine (https://discord.com/developers/docs, 0.1.0)",
|
|
277
278
|
});
|
|
278
279
|
if (request.auth !== false)
|
|
279
280
|
headers.set("Authorization", `Bot ${this.#token}`);
|