winston-discordjs 2.1.0 → 4.0.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/README.md +1 -1
- package/dist/DiscordTransport.js +17 -32
- package/dist/LogHandlers.js +23 -18
- package/package.json +31 -40
- package/dist/DiscordTransport.d.ts +0 -20
- package/dist/LogHandlers.d.ts +0 -8
- package/dist/LogLevels.d.ts +0 -3
- package/dist/index.d.ts +0 -2
package/README.md
CHANGED
package/dist/DiscordTransport.js
CHANGED
|
@@ -7,31 +7,25 @@ exports.DiscordTransport = void 0;
|
|
|
7
7
|
const discord_js_1 = require("discord.js");
|
|
8
8
|
const winston_transport_1 = __importDefault(require("winston-transport"));
|
|
9
9
|
const LogHandlers_1 = require("./LogHandlers");
|
|
10
|
-
const deprecationMessage = `Passing in a 'string' for { discordToken } is now deprecated, due to changes in Discord.js API. Please use a different initialization method.`;
|
|
11
10
|
class DiscordTransport extends winston_transport_1.default {
|
|
12
11
|
constructor(opts) {
|
|
13
12
|
super(opts);
|
|
14
13
|
if (opts) {
|
|
15
|
-
const { discordChannel, discordToken } = opts;
|
|
14
|
+
const { discordChannel, discordToken, intents = [] } = opts;
|
|
16
15
|
if (opts.discordClient) {
|
|
17
16
|
this.discordClient = opts.discordClient;
|
|
18
17
|
}
|
|
19
18
|
else {
|
|
20
19
|
if (discordToken) {
|
|
21
|
-
this.discordClient = new discord_js_1.Client();
|
|
20
|
+
this.discordClient = new discord_js_1.Client({ intents });
|
|
22
21
|
this.discordClient.on("error", (error) => {
|
|
23
22
|
this.emit("warn", error);
|
|
24
23
|
});
|
|
25
24
|
this.discordClient.login(discordToken);
|
|
26
25
|
}
|
|
27
26
|
}
|
|
28
|
-
if (discordChannel) {
|
|
29
|
-
|
|
30
|
-
this.discordChannel = discordChannel;
|
|
31
|
-
}
|
|
32
|
-
else if (this.discordClient && typeof discordChannel === "string") {
|
|
33
|
-
this.emit("warn", deprecationMessage);
|
|
34
|
-
}
|
|
27
|
+
if (discordChannel && discordChannel instanceof discord_js_1.TextChannel) {
|
|
28
|
+
this.discordChannel = discordChannel;
|
|
35
29
|
}
|
|
36
30
|
}
|
|
37
31
|
}
|
|
@@ -40,29 +34,20 @@ class DiscordTransport extends winston_transport_1.default {
|
|
|
40
34
|
this.emit("logged", info);
|
|
41
35
|
});
|
|
42
36
|
if (!this.silent && info) {
|
|
43
|
-
const logMessage = LogHandlers_1.handleInfo(info, this.format, this.level);
|
|
44
|
-
if (!this.discordChannel && this.discordClient && this.discordChannelId) {
|
|
45
|
-
this.emit("warn", deprecationMessage);
|
|
46
|
-
this.discordClient.channels
|
|
47
|
-
.fetch(this.discordChannelId)
|
|
48
|
-
.then((channel) => {
|
|
49
|
-
if (channel instanceof discord_js_1.TextChannel) {
|
|
50
|
-
this.discordChannel = channel;
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
this.emit("warn", `DiscordTransport received unexpected type of channel. Expected <${typeof discord_js_1.TextChannel}>, received: <${typeof channel}>`);
|
|
54
|
-
}
|
|
55
|
-
})
|
|
56
|
-
.catch((error) => {
|
|
57
|
-
this.emit("warn", `DiscordTransport.log failed to initialize DiscordChannel with <${this.discordChannelId}>: ${error}`);
|
|
58
|
-
});
|
|
59
|
-
}
|
|
37
|
+
const logMessage = (0, LogHandlers_1.handleInfo)(info, this.format, this.level);
|
|
60
38
|
if (this.discordChannel && logMessage) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
39
|
+
let messagePromise;
|
|
40
|
+
if (Array.isArray(logMessage)) {
|
|
41
|
+
const content = logMessage[0];
|
|
42
|
+
const embed = logMessage[1];
|
|
43
|
+
messagePromise = this.discordChannel.send({
|
|
44
|
+
content,
|
|
45
|
+
embeds: [embed],
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
messagePromise = this.discordChannel.send(logMessage);
|
|
50
|
+
}
|
|
66
51
|
messagePromise.catch((error) => {
|
|
67
52
|
this.emit("warn", error);
|
|
68
53
|
});
|
package/dist/LogHandlers.js
CHANGED
|
@@ -4,9 +4,10 @@ exports.handleInfo = exports.handleObject = exports.handleLogform = exports.hand
|
|
|
4
4
|
const utility_types_1 = require("utility-types");
|
|
5
5
|
const discord_js_1 = require("discord.js");
|
|
6
6
|
const LogLevels_1 = require("./LogLevels");
|
|
7
|
-
|
|
7
|
+
const isTransformableInfo = (info) => {
|
|
8
8
|
return Boolean(info && "level" in info && "message" in info);
|
|
9
9
|
};
|
|
10
|
+
exports.isTransformableInfo = isTransformableInfo;
|
|
10
11
|
const sortFields = (fields) => {
|
|
11
12
|
const sortedFields = [];
|
|
12
13
|
const timestampIndex = fields.findIndex((value) => value === "timestamp");
|
|
@@ -28,7 +29,7 @@ const sortFields = (fields) => {
|
|
|
28
29
|
}
|
|
29
30
|
return sortedFields;
|
|
30
31
|
};
|
|
31
|
-
|
|
32
|
+
const handlePrimitive = (info) => {
|
|
32
33
|
switch (typeof info) {
|
|
33
34
|
case "string": {
|
|
34
35
|
return info;
|
|
@@ -38,13 +39,14 @@ exports.handlePrimitive = (info) => {
|
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
41
|
};
|
|
41
|
-
exports.
|
|
42
|
-
|
|
42
|
+
exports.handlePrimitive = handlePrimitive;
|
|
43
|
+
const handleLogform = (info, level) => {
|
|
43
44
|
if ((level && level === info.level) || !level) {
|
|
44
45
|
const messageEmbed = new discord_js_1.MessageEmbed();
|
|
45
46
|
let logMessageString = "";
|
|
46
47
|
const color = level
|
|
47
|
-
?
|
|
48
|
+
? LogLevels_1.LogLevelToColor[level] ?? "DEFAULT"
|
|
49
|
+
: "DEFAULT";
|
|
48
50
|
messageEmbed.setColor(color);
|
|
49
51
|
const fields = sortFields(Object.keys(info));
|
|
50
52
|
for (const field of fields) {
|
|
@@ -57,32 +59,33 @@ exports.handleLogform = (info, level) => {
|
|
|
57
59
|
const capitalizedField = capitalize(field);
|
|
58
60
|
const value = info[field];
|
|
59
61
|
logMessageString += `${capitalizedField}: ${value}`;
|
|
60
|
-
messageEmbed.addField(capitalizedField, value, true);
|
|
62
|
+
messageEmbed.addField(capitalizedField, value.toString(), true);
|
|
61
63
|
}
|
|
62
64
|
}
|
|
63
65
|
return [logMessageString, messageEmbed];
|
|
64
66
|
}
|
|
65
67
|
return undefined;
|
|
66
68
|
};
|
|
67
|
-
exports.
|
|
68
|
-
|
|
69
|
+
exports.handleLogform = handleLogform;
|
|
70
|
+
const handleObject = (info, format, level) => {
|
|
71
|
+
if ((0, exports.isTransformableInfo)(info)) {
|
|
69
72
|
if (format) {
|
|
70
73
|
const formattedInfo = format.transform(info);
|
|
71
|
-
if (exports.isTransformableInfo(formattedInfo)) {
|
|
72
|
-
return exports.handleLogform(formattedInfo, level);
|
|
74
|
+
if ((0, exports.isTransformableInfo)(formattedInfo)) {
|
|
75
|
+
return (0, exports.handleLogform)(formattedInfo, level);
|
|
73
76
|
}
|
|
74
77
|
else {
|
|
75
|
-
return exports.handlePrimitive(formattedInfo);
|
|
78
|
+
return (0, exports.handlePrimitive)(formattedInfo);
|
|
76
79
|
}
|
|
77
80
|
}
|
|
78
81
|
else {
|
|
79
|
-
return exports.handleLogform(info, level);
|
|
82
|
+
return (0, exports.handleLogform)(info, level);
|
|
80
83
|
}
|
|
81
84
|
}
|
|
82
85
|
else if (info instanceof Error && info.stack) {
|
|
83
86
|
return info.stack;
|
|
84
87
|
}
|
|
85
|
-
else if (typeof
|
|
88
|
+
else if (typeof info?.toString === "function" &&
|
|
86
89
|
info.toString !== Object.toString) {
|
|
87
90
|
return info.toString();
|
|
88
91
|
}
|
|
@@ -91,14 +94,16 @@ exports.handleObject = (info, format, level) => {
|
|
|
91
94
|
return JSON.stringify(info);
|
|
92
95
|
}
|
|
93
96
|
};
|
|
94
|
-
exports.
|
|
95
|
-
|
|
96
|
-
|
|
97
|
+
exports.handleObject = handleObject;
|
|
98
|
+
const handleInfo = (info, format, level) => {
|
|
99
|
+
if ((0, utility_types_1.isPrimitive)(info)) {
|
|
100
|
+
return (0, exports.handlePrimitive)(info);
|
|
97
101
|
}
|
|
98
102
|
else if (typeof info === "function") {
|
|
99
|
-
return exports.handleInfo(info(), format, level);
|
|
103
|
+
return (0, exports.handleInfo)(info(), format, level);
|
|
100
104
|
}
|
|
101
105
|
else {
|
|
102
|
-
return exports.handleObject(info, format, level);
|
|
106
|
+
return (0, exports.handleObject)(info, format, level);
|
|
103
107
|
}
|
|
104
108
|
};
|
|
109
|
+
exports.handleInfo = handleInfo;
|
package/package.json
CHANGED
|
@@ -2,48 +2,44 @@
|
|
|
2
2
|
"author": "Robert Smieja",
|
|
3
3
|
"bugs": "https://github.com/robbot-discord/winston-discordjs/issues",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@types/ws": "^
|
|
6
|
-
"
|
|
7
|
-
"logform": "^2.1.2",
|
|
5
|
+
"@types/ws": "^8.5.3",
|
|
6
|
+
"logform": "^2.4.2",
|
|
8
7
|
"utility-types": "^3.10.0",
|
|
9
|
-
"winston": "^
|
|
10
|
-
|
|
8
|
+
"winston-transport": "^4.5.0"
|
|
9
|
+
},
|
|
10
|
+
"peerDependencies": {
|
|
11
|
+
"discord.js": "^13.8.1"
|
|
11
12
|
},
|
|
12
13
|
"description": "Winston Transport using Discord.js",
|
|
13
14
|
"devDependencies": {
|
|
14
|
-
"@babel/core": "^7.
|
|
15
|
-
"@babel/preset-env": "^7.
|
|
16
|
-
"@babel/preset-typescript": "^7.
|
|
17
|
-
"@
|
|
18
|
-
"@types/
|
|
19
|
-
"@
|
|
20
|
-
"@typescript-eslint/
|
|
21
|
-
"eslint": "^
|
|
22
|
-
"eslint
|
|
23
|
-
"eslint-
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
15
|
+
"@babel/core": "^7.18.6",
|
|
16
|
+
"@babel/preset-env": "^7.18.6",
|
|
17
|
+
"@babel/preset-typescript": "^7.18.6",
|
|
18
|
+
"@tsconfig/node16": "^1.0.3",
|
|
19
|
+
"@types/jest": "^28.1.4",
|
|
20
|
+
"@types/node": "^18.0.3",
|
|
21
|
+
"@typescript-eslint/eslint-plugin": "^5.30.6",
|
|
22
|
+
"@typescript-eslint/parser": "^5.30.6",
|
|
23
|
+
"eslint": "^8.19.0",
|
|
24
|
+
"eslint-config-prettier": "^8.5.0",
|
|
25
|
+
"eslint-plugin-jest": "^26.5.3",
|
|
26
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
27
|
+
"husky": "^8.0.1",
|
|
28
|
+
"jest": "^28.1.2",
|
|
29
|
+
"lint-staged": "^13.0.3",
|
|
27
30
|
"npm-run-all": "^4.1.5",
|
|
28
|
-
"prettier": "^2.
|
|
31
|
+
"prettier": "^2.7.1",
|
|
29
32
|
"rimraf": "^3.0.2",
|
|
30
|
-
"ts-jest": "
|
|
31
|
-
"typescript": "^
|
|
33
|
+
"ts-jest": "28.0.5",
|
|
34
|
+
"typescript": "^4.7.4"
|
|
32
35
|
},
|
|
33
36
|
"engines": {
|
|
34
|
-
"node": ">=
|
|
35
|
-
"npm": ">=
|
|
37
|
+
"node": ">=16.6",
|
|
38
|
+
"npm": ">=8"
|
|
36
39
|
},
|
|
37
40
|
"files": [
|
|
38
41
|
"dist"
|
|
39
42
|
],
|
|
40
|
-
"husky": {
|
|
41
|
-
"hooks": {
|
|
42
|
-
"pre-commit": [
|
|
43
|
-
"lint-staged"
|
|
44
|
-
]
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
43
|
"keywords": [
|
|
48
44
|
"typescript",
|
|
49
45
|
"nodejs",
|
|
@@ -54,14 +50,6 @@
|
|
|
54
50
|
"transport"
|
|
55
51
|
],
|
|
56
52
|
"license": "MIT",
|
|
57
|
-
"lint-staged": {
|
|
58
|
-
"*.{js,ts,jsx,tsx,json,md}": [
|
|
59
|
-
"prettier --write"
|
|
60
|
-
],
|
|
61
|
-
"src/*.{js,ts,jsx,tsx}": [
|
|
62
|
-
"eslint --fix"
|
|
63
|
-
]
|
|
64
|
-
},
|
|
65
53
|
"main": "dist/index.js",
|
|
66
54
|
"name": "winston-discordjs",
|
|
67
55
|
"private": false,
|
|
@@ -70,6 +58,7 @@
|
|
|
70
58
|
"build": "npm-run-all --parallel build:js lint",
|
|
71
59
|
"build:js": "tsc",
|
|
72
60
|
"clean": "rimraf dist/",
|
|
61
|
+
"check": "npm-run-all --parallel lint typecheck",
|
|
73
62
|
"lint": "eslint ./src/**/*",
|
|
74
63
|
"lint:fix": "eslint --fix ./src/**/*",
|
|
75
64
|
"lint:staged": "lint-staged",
|
|
@@ -78,8 +67,10 @@
|
|
|
78
67
|
"prepublishOnly": "npm-run-all --parallel test lint",
|
|
79
68
|
"prettier": "prettier --write '*.{js,ts,jsx,tsx,json,md}'",
|
|
80
69
|
"test": "jest",
|
|
81
|
-
"
|
|
70
|
+
"typecheck": "tsc --noEmit",
|
|
71
|
+
"version": "npm run lint:fix && git add -A src",
|
|
72
|
+
"prepare": "husky install"
|
|
82
73
|
},
|
|
83
74
|
"types": "dist/index.d.ts",
|
|
84
|
-
"version": "
|
|
75
|
+
"version": "4.0.0"
|
|
85
76
|
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import Transport from "winston-transport";
|
|
2
|
-
import { TextChannel, Client } from "discord.js";
|
|
3
|
-
import TransportStream from "winston-transport";
|
|
4
|
-
export interface DiscordTransportStreamOptions extends Transport.TransportStreamOptions {
|
|
5
|
-
discordClient?: Client;
|
|
6
|
-
discordToken?: string;
|
|
7
|
-
discordChannel?: string | TextChannel;
|
|
8
|
-
}
|
|
9
|
-
export declare class DiscordTransport extends TransportStream {
|
|
10
|
-
discordChannel?: TextChannel;
|
|
11
|
-
discordClient?: Client;
|
|
12
|
-
/**
|
|
13
|
-
* @deprecated This is a new field to assist in deprecating discordChannel gracefully. Will be removed in the next major version
|
|
14
|
-
*/
|
|
15
|
-
discordChannelId?: string;
|
|
16
|
-
constructor(opts?: DiscordTransportStreamOptions);
|
|
17
|
-
log(info: any, callback?: () => void): void;
|
|
18
|
-
close(): void;
|
|
19
|
-
}
|
|
20
|
-
export default DiscordTransport;
|
package/dist/LogHandlers.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { TransformableInfo, Format } from "logform";
|
|
2
|
-
import { Primitive } from "utility-types";
|
|
3
|
-
import { MessageEmbed } from "discord.js";
|
|
4
|
-
export declare const isTransformableInfo: (info: any) => info is TransformableInfo;
|
|
5
|
-
export declare const handlePrimitive: (info: Primitive) => string;
|
|
6
|
-
export declare const handleLogform: (info: TransformableInfo, level?: string | undefined) => [string, MessageEmbed] | undefined;
|
|
7
|
-
export declare const handleObject: (info: Exclude<any, Primitive>, format?: Format | undefined, level?: string | undefined) => string | [string, MessageEmbed] | undefined;
|
|
8
|
-
export declare const handleInfo: (info: any, format?: Format | undefined, level?: string | undefined) => string | [string, MessageEmbed] | undefined;
|
package/dist/LogLevels.d.ts
DELETED
package/dist/index.d.ts
DELETED