@serverkgg/bridge 0.1.6 → 0.1.7
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/package.json +1 -1
- package/src/bot/botCauses.test.ts +48 -0
- package/src/bot/botCauses.ts +7 -1
- package/src/bot/detect/corpus/anidiotsguide-guidebot.json +2 -1
- package/src/bot/detect/corpus/latand-tgbot_template_v3.json +2 -1
- package/src/bot/detect/corpus/nezdemkovski-telegram-bot-boilerplate.json +2 -1
- package/src/bot/detect/detect.test.ts +39 -0
- package/src/bot/detect/envExample.test.ts +8 -0
- package/src/bot/detect/envExample.ts +3 -1
package/package.json
CHANGED
|
@@ -13,6 +13,10 @@ const CASES: readonly {
|
|
|
13
13
|
line: "Error [TokenInvalid]: An invalid token was provided.",
|
|
14
14
|
cause: BridgeCrashCause.TokenInvalid,
|
|
15
15
|
},
|
|
16
|
+
{
|
|
17
|
+
line: "Error [TOKEN_INVALID]: An invalid token was provided.",
|
|
18
|
+
cause: BridgeCrashCause.TokenInvalid,
|
|
19
|
+
},
|
|
16
20
|
{
|
|
17
21
|
line: "discord.errors.LoginFailure: Improper token has been passed.",
|
|
18
22
|
cause: BridgeCrashCause.TokenInvalid,
|
|
@@ -45,6 +49,38 @@ const CASES: readonly {
|
|
|
45
49
|
line: "pyrogram.errors.exceptions.bad_request_400.AccessTokenExpired: Telegram says: [400 ACCESS_TOKEN_EXPIRED] - The bot token has expired",
|
|
46
50
|
cause: BridgeCrashCause.TokenInvalid,
|
|
47
51
|
},
|
|
52
|
+
{
|
|
53
|
+
line: "TypeError: expected token to be a str, received NoneType instead",
|
|
54
|
+
cause: BridgeCrashCause.TokenInvalid,
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
line: "TypeError: expected token to be a str, received <class 'NoneType'> instead",
|
|
58
|
+
cause: BridgeCrashCause.TokenInvalid,
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
line: "TypeError: token must be of type str, not NoneType",
|
|
62
|
+
cause: BridgeCrashCause.TokenInvalid,
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
line: "TypeError: token must be of type str, got NoneType instead",
|
|
66
|
+
cause: BridgeCrashCause.TokenInvalid,
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
line: "TypeError: The token provided was of type <class 'NoneType'> but was expected to be str",
|
|
70
|
+
cause: BridgeCrashCause.TokenInvalid,
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
line: "Error: Empty token!",
|
|
74
|
+
cause: BridgeCrashCause.TokenInvalid,
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
line: "aiogram.utils.token.TokenValidationError: Token is invalid!",
|
|
78
|
+
cause: BridgeCrashCause.TokenInvalid,
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
line: "aiogram.utils.token.TokenValidationError: Token is invalid! It must be 'str' type instead of <class 'NoneType'> type.",
|
|
82
|
+
cause: BridgeCrashCause.TokenInvalid,
|
|
83
|
+
},
|
|
48
84
|
{
|
|
49
85
|
line: "Error: Used disallowed intents",
|
|
50
86
|
cause: BridgeCrashCause.IntentsDisallowed,
|
|
@@ -53,6 +89,10 @@ const CASES: readonly {
|
|
|
53
89
|
line: "Error [DisallowedIntents]: Privileged intent provided is not enabled or whitelisted.",
|
|
54
90
|
cause: BridgeCrashCause.IntentsDisallowed,
|
|
55
91
|
},
|
|
92
|
+
{
|
|
93
|
+
line: "Error [DISALLOWED_INTENTS]: Privileged intent provided is not enabled or whitelisted.",
|
|
94
|
+
cause: BridgeCrashCause.IntentsDisallowed,
|
|
95
|
+
},
|
|
56
96
|
{
|
|
57
97
|
line: "discord.errors.PrivilegedIntentsRequired: Shard ID None is requesting privileged intents that have not been explicitly enabled in the developer portal.",
|
|
58
98
|
cause: BridgeCrashCause.IntentsDisallowed,
|
|
@@ -265,6 +305,14 @@ describe("BOT_CRASH_EVIDENCE", () => {
|
|
|
265
305
|
expect(ring.crash(recordOf())).toBe(BridgeCrashCause.Unknown);
|
|
266
306
|
});
|
|
267
307
|
|
|
308
|
+
it("leaves a TypeError about something other than the token unexplained", () => {
|
|
309
|
+
const { ring, print } = botRing();
|
|
310
|
+
|
|
311
|
+
print("TypeError: expected str, bytes or os.PathLike object, not NoneType");
|
|
312
|
+
|
|
313
|
+
expect(ring.crash(recordOf())).toBe(BridgeCrashCause.Unknown);
|
|
314
|
+
});
|
|
315
|
+
|
|
268
316
|
it("calls exit 137 out of memory only when the record carries the flag", () => {
|
|
269
317
|
const unflagged = botRing();
|
|
270
318
|
|
package/src/bot/botCauses.ts
CHANGED
|
@@ -13,7 +13,13 @@ export const BOT_CRASH_EVIDENCE: readonly BridgeEventPattern[] = [
|
|
|
13
13
|
emit: BridgeEventName.TokenInvalid,
|
|
14
14
|
},
|
|
15
15
|
{
|
|
16
|
-
match:
|
|
16
|
+
match:
|
|
17
|
+
/TypeError: (?:expected token to be a str, received|token must be of type str, (?:not|got) |The token provided was of type .+ but was expected to be str)|\bError: Empty token!|TokenValidationError: Token is invalid!/,
|
|
18
|
+
emit: BridgeEventName.TokenInvalid,
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
match:
|
|
22
|
+
/Used disallowed intents|\[DisallowedIntents\]|Privileged intent provided is not enabled or whitelisted|PrivilegedIntentsRequired|close code:? 4014\b/,
|
|
17
23
|
emit: BridgeEventName.IntentsDisallowed,
|
|
18
24
|
},
|
|
19
25
|
{
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"yarn.lock"
|
|
19
19
|
],
|
|
20
20
|
"contents": {
|
|
21
|
+
".env-example": "DISCORD_TOKEN=\nOWNER=",
|
|
21
22
|
"package.json": "{\n \"name\": \"guidebot\",\n \"version\": \"2.1.0\",\n \"description\": \"A boilerplate example bot with command handler and reloadable commands. Updated and Maintained by the Idiot's Guide Community\",\n \"main\": \"index.js\",\n \"scripts\": {\n \"start\": \"node index.js\"\n },\n \"engines\": {\n \"node\": \">=16\"\n },\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/AnIdiotsGuide/guidebot.git\"\n },\n \"author\": \"Evelyne Lachance <eslachance@gmail.com> (http://evie.codes)\",\n \"contributors\": [\n \"York (http://anidiots.guide)\"\n ],\n \"license\": \"MIT\",\n \"bugs\": {\n \"url\": \"https://github.com/AnIdiotsGuide/guidebot/issues\"\n },\n \"homepage\": \"https://github.com/AnIdiotsGuide/guidebot#readme\",\n \"dependencies\": {\n \"@discordjs/builders\": \"^0.2.0\",\n \"@sapphire/time-utilities\": \"^1.3.8\",\n \"colorette\": \"^1.3.0\",\n \"discord.js\": \"^13.0.1\",\n \"dotenv\": \"^10.0.0\",\n \"enmap\": \"^5.8.5\"\n },\n \"devDependencies\": {\n \"eslint\": \"^7.30.0\",\n \"eslint-config-airbnb-base\": \"^14.2.1\",\n \"eslint-config-standard\": \"^16.0.3\",\n \"eslint-plugin-import\": \"^2.23.4\",\n \"eslint-plugin-node\": \"^11.1.0\",\n \"eslint-plugin-promise\": \"^5.1.0\"\n }\n}\n"
|
|
22
23
|
},
|
|
23
24
|
"expected": {
|
|
@@ -30,7 +31,7 @@
|
|
|
30
31
|
"start": "node index.js",
|
|
31
32
|
"nodeVersion": "16",
|
|
32
33
|
"pythonVersion": null,
|
|
33
|
-
"tokenKey":
|
|
34
|
+
"tokenKey": "DISCORD_TOKEN",
|
|
34
35
|
"warnings": []
|
|
35
36
|
}
|
|
36
37
|
}
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"requirements.txt"
|
|
18
18
|
],
|
|
19
19
|
"contents": {
|
|
20
|
+
".env.dist": "BOT_TOKEN=123456:Your-TokEn_ExaMple\nADMINS=123456,654321\nUSE_REDIS=False\n\n#POSTGRES_USER=someusername\n#POSTGRES_PASSWORD=postgres_pass12345\n#POSTGRES_DB=bot\n#DB_HOST=pg_database\n\n# REDIS_HOST=redis_cache\n# REDIS_PORT=6388\n# REDIS_DB=1\n# REDIS_PASSWORD=someredispass\n\n\n#WEBHOOK_EXPOSE=8001\n#WEBHOOK_APP_NAME=webhook\n",
|
|
20
21
|
"requirements.txt": "aiogram~=3.0\nenvirons~=9.0\nredis\nbetterlogging\n\n# # For enabling api:\n# backoff\n# ujson\n# yarl\n\n# # For PostgreSQL sqlalchemy + alembic:\n# sqlalchemy~=2.0\n# alembic~=1.0\n# asyncpg\n"
|
|
21
22
|
},
|
|
22
23
|
"expected": {
|
|
@@ -29,7 +30,7 @@
|
|
|
29
30
|
"start": "python bot.py",
|
|
30
31
|
"nodeVersion": null,
|
|
31
32
|
"pythonVersion": null,
|
|
32
|
-
"tokenKey":
|
|
33
|
+
"tokenKey": "BOT_TOKEN",
|
|
33
34
|
"warnings": [
|
|
34
35
|
"unpinned-requirements"
|
|
35
36
|
]
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"tsconfig.json"
|
|
22
22
|
],
|
|
23
23
|
"contents": {
|
|
24
|
+
".env-sample": "BOT_TOKEN=\"\"\nUSERNAME=\"\"\nWEBHOOK_URL=\"\"\nPORT=\"3000\"\nNODE_ENV=\"development\"\n",
|
|
24
25
|
"package.json": "{\n \"name\": \"telegram-bot-boilerplate\",\n \"version\": \"1.0.0\",\n \"description\": \"Telegram Bot Boilerplate\",\n \"author\": \"Yuri Nezdemkovski <yuri@nezdemkovski.com> (https://nezdemkovski.com/)\",\n \"homepage\": \"https://github.com/nezdemkovski/telegram-bot-boilerplate\",\n \"license\": \"MIT\",\n \"engines\": {\n \"bun\": \">=1\"\n },\n \"dependencies\": {\n \"grammy\": \"^1.40.0\"\n },\n \"devDependencies\": {\n \"bun-types\": \"1.3.9\",\n \"eslint\": \"^10.0.1\",\n \"eslint-config-prettier\": \"^10.1.8\",\n \"prettier\": \"^3.8.1\",\n \"typescript\": \"^5.9.3\",\n \"typescript-eslint\": \"^8.56.0\"\n },\n \"scripts\": {\n \"dev\": \"bun --watch src/index.ts\",\n \"build\": \"bun build src/index.ts --outdir dist --target bun --minify\",\n \"start\": \"NODE_ENV=production bun dist/index.js\",\n \"typecheck\": \"tsc --noEmit\",\n \"lint\": \"eslint src\",\n \"format\": \"prettier --write 'src/**/*.ts'\"\n }\n}\n"
|
|
25
26
|
},
|
|
26
27
|
"expected": {
|
|
@@ -33,7 +34,7 @@
|
|
|
33
34
|
"start": "NODE_ENV=production bun dist/index.js",
|
|
34
35
|
"nodeVersion": null,
|
|
35
36
|
"pythonVersion": null,
|
|
36
|
-
"tokenKey":
|
|
37
|
+
"tokenKey": "BOT_TOKEN",
|
|
37
38
|
"warnings": []
|
|
38
39
|
}
|
|
39
40
|
}
|
|
@@ -813,6 +813,45 @@ describe("detect env suggestions", () => {
|
|
|
813
813
|
]);
|
|
814
814
|
});
|
|
815
815
|
|
|
816
|
+
const CASES: readonly {
|
|
817
|
+
file: string;
|
|
818
|
+
}[] = [
|
|
819
|
+
{
|
|
820
|
+
file: ".env-example",
|
|
821
|
+
},
|
|
822
|
+
{
|
|
823
|
+
file: ".env-sample",
|
|
824
|
+
},
|
|
825
|
+
{
|
|
826
|
+
file: ".env.dist",
|
|
827
|
+
},
|
|
828
|
+
];
|
|
829
|
+
|
|
830
|
+
for (const item of CASES) {
|
|
831
|
+
it(`reads ${item.file} the way it reads .env.example`, () => {
|
|
832
|
+
const result = project({
|
|
833
|
+
"package.json": "{}",
|
|
834
|
+
[item.file]: "DISCORD_TOKEN=\nOWNER=\n",
|
|
835
|
+
});
|
|
836
|
+
|
|
837
|
+
expect(result.env).toEqual([
|
|
838
|
+
{
|
|
839
|
+
key: "DISCORD_TOKEN",
|
|
840
|
+
sensitive: true,
|
|
841
|
+
source: item.file,
|
|
842
|
+
example: null,
|
|
843
|
+
},
|
|
844
|
+
{
|
|
845
|
+
key: "OWNER",
|
|
846
|
+
sensitive: false,
|
|
847
|
+
source: item.file,
|
|
848
|
+
example: null,
|
|
849
|
+
},
|
|
850
|
+
]);
|
|
851
|
+
expect(result.tokenKey).toBe("DISCORD_TOKEN");
|
|
852
|
+
});
|
|
853
|
+
}
|
|
854
|
+
|
|
816
855
|
it("suggests the keys of a skipped .env after the example files, never its values", () => {
|
|
817
856
|
const result = detect({
|
|
818
857
|
files: [
|
|
@@ -4,11 +4,13 @@ export const ENV_EXAMPLE_FILES: readonly string[] = [
|
|
|
4
4
|
".env.example",
|
|
5
5
|
".env.sample",
|
|
6
6
|
".env.template",
|
|
7
|
+
".env-example",
|
|
8
|
+
".env-sample",
|
|
9
|
+
".env.dist",
|
|
7
10
|
];
|
|
8
11
|
|
|
9
12
|
const ENV_TEMPLATE_FILES: ReadonlySet<string> = new Set([
|
|
10
13
|
...ENV_EXAMPLE_FILES,
|
|
11
|
-
".env.dist",
|
|
12
14
|
".env.defaults",
|
|
13
15
|
]);
|
|
14
16
|
|