generator-discord 1.3.1 → 1.3.3
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/app/index.d.ts.map +1 -1
- package/app/index.js +4 -3
- package/app/index.js.map +1 -1
- package/package.json +8 -7
- package/src/index.ts +6 -3
- package/templates/javascript/package.json +1 -1
- package/templates/python/main.py +2 -1
- package/templates/typescript/package.json +1 -1
- package/test/templates.test.ts +105 -0
- package/test/generator.test.ts +0 -108
package/app/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,OAAO,SAAS,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,OAAO,SAAS,MAAM,kBAAkB,CAAC;AAazC,KAAK,OAAO,GAAG,YAAY,GAAG,YAAY,GAAG,QAAQ,GAAG,MAAM,CAAC;AAE/D,UAAU,OAAO;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,OAAO,CAAC;CACtB;AA6BD,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,SAAS;IACtD,OAAO,CAAC,OAAO,CAA0B;gBAE7B,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAI/D,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAgDhC,IAAI,IAAI,IAAI;IAYZ,OAAO,IAAI,IAAI;IAsBT,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAoBxB,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;IAyB1B,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM;CAWjE"}
|
package/app/index.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import Generator from 'yeoman-generator';
|
|
2
2
|
import path from 'path';
|
|
3
|
+
import url from 'url';
|
|
3
4
|
const TEMPLATE_DIR = '../templates/';
|
|
4
5
|
const USER_DIR = '.';
|
|
5
6
|
const BOT_NAME = /<%= bot-name %>/g;
|
|
6
7
|
const BOT_TOKEN = /<%= bot-token %>/g;
|
|
7
8
|
// needed for rust
|
|
8
9
|
const BOT_NAME_RUST = /bot_name/g;
|
|
10
|
+
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
|
|
9
11
|
const botNameValidation = {
|
|
10
12
|
typescript: {
|
|
11
13
|
regex: new RegExp('^(?:@[a-z0-9-*~][a-z0-9-*._~]*/)?[a-z0-9-~][a-z0-9-._~]*$'),
|
|
@@ -83,9 +85,8 @@ export default class DiscordGenerator extends Generator {
|
|
|
83
85
|
this.log('\x1b[0m');
|
|
84
86
|
}
|
|
85
87
|
writing() {
|
|
86
|
-
const currentUrl = new URL('.', import.meta.url).pathname;
|
|
87
88
|
const paths = ['.'];
|
|
88
|
-
this.sourceRoot(path.join(
|
|
89
|
+
this.sourceRoot(path.join(__dirname, TEMPLATE_DIR, this.answers.botType));
|
|
89
90
|
// iterate over all files
|
|
90
91
|
for (let i = 0, len = paths.length; i < len; i++) {
|
|
91
92
|
const path = paths[i];
|
|
@@ -107,7 +108,7 @@ export default class DiscordGenerator extends Generator {
|
|
|
107
108
|
await this.spawn('npm', ['run', 'build'], options);
|
|
108
109
|
}
|
|
109
110
|
}
|
|
110
|
-
this.log('Your Discord Bot \
|
|
111
|
+
this.log('Your Discord Bot \x1b[32m' + this.answers.botName + '\x1b[0m has been created!');
|
|
111
112
|
}
|
|
112
113
|
async end() {
|
|
113
114
|
const answer = await this.prompt({
|
package/app/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.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ClC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,eAAe,CACvC,QAAQ,EACR,IAAI,CAAC,OAAO,CAAC,OAAO,CACpB,CAAC,CAAC,CAAC;SACJ;IACF,CAAC;IAED,aAAa,CAAC,OAAwB,EAAE,OAAgB;QACvD,IAAI,OAAO,CAAC,OAAO,KAAK,MAAM,EAAE;YAC/B,OAAO,OAAO,CAAC,QAAQ,EAAE;iBACvB,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,QAAQ,CAAC;iBACpC,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;SAC1C;QAED,OAAO,OAAO,CAAC,QAAQ,EAAE;aACvB,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,QAAQ,CAAC;aACpC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IACtC,CAAC;CACD"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "generator-discord",
|
|
3
3
|
"displayName": "Generator-Discord",
|
|
4
|
-
"version": "1.3.
|
|
4
|
+
"version": "1.3.3",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": "./app/index.js",
|
|
7
|
-
"description": "
|
|
7
|
+
"description": "Create a basic Discord-Bot, supporting many programming languages.",
|
|
8
8
|
"engines": {
|
|
9
9
|
"node": ">=16.0.0"
|
|
10
10
|
},
|
|
@@ -40,14 +40,15 @@
|
|
|
40
40
|
},
|
|
41
41
|
"homepage": "https://github.com/emilkrebs/Generator-Discord",
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"yeoman-generator": "^7.
|
|
43
|
+
"yeoman-generator": "^7.1.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
47
|
-
"@typescript-eslint/parser": "^6.
|
|
48
|
-
"
|
|
46
|
+
"@typescript-eslint/eslint-plugin": "^6.11.0",
|
|
47
|
+
"@typescript-eslint/parser": "^6.11.0",
|
|
48
|
+
"dotenv": "^16.3.1",
|
|
49
|
+
"eslint": "^8.53.0",
|
|
49
50
|
"typescript": "^5.2.2",
|
|
50
51
|
"vitest": "^0.34.6",
|
|
51
|
-
"yeoman-test": "^8.
|
|
52
|
+
"yeoman-test": "^8.2.0"
|
|
52
53
|
}
|
|
53
54
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import Generator from 'yeoman-generator';
|
|
2
2
|
import path from 'path';
|
|
3
|
+
import url from 'url';
|
|
3
4
|
|
|
4
5
|
const TEMPLATE_DIR = '../templates/';
|
|
5
6
|
const USER_DIR = '.';
|
|
@@ -24,6 +25,7 @@ interface BotNameValidation {
|
|
|
24
25
|
errorMessage: string;
|
|
25
26
|
}
|
|
26
27
|
|
|
28
|
+
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
|
|
27
29
|
const botNameValidation: Record<BotType, BotNameValidation> = {
|
|
28
30
|
typescript: {
|
|
29
31
|
regex: new RegExp('^(?:@[a-z0-9-*~][a-z0-9-*._~]*/)?[a-z0-9-~][a-z0-9-._~]*$'),
|
|
@@ -43,6 +45,8 @@ const botNameValidation: Record<BotType, BotNameValidation> = {
|
|
|
43
45
|
}
|
|
44
46
|
};
|
|
45
47
|
|
|
48
|
+
|
|
49
|
+
|
|
46
50
|
export default class DiscordGenerator extends Generator {
|
|
47
51
|
private answers: Answers = {} as Answers;
|
|
48
52
|
|
|
@@ -111,10 +115,9 @@ export default class DiscordGenerator extends Generator {
|
|
|
111
115
|
}
|
|
112
116
|
|
|
113
117
|
writing(): void {
|
|
114
|
-
const currentUrl = new URL('.', import.meta.url).pathname;
|
|
115
118
|
const paths = ['.'];
|
|
116
119
|
|
|
117
|
-
this.sourceRoot(path.join(
|
|
120
|
+
this.sourceRoot(path.join(__dirname, TEMPLATE_DIR, this.answers.botType));
|
|
118
121
|
|
|
119
122
|
// iterate over all files
|
|
120
123
|
for (let i = 0, len = paths.length; i < len; i++) {
|
|
@@ -149,7 +152,7 @@ export default class DiscordGenerator extends Generator {
|
|
|
149
152
|
}
|
|
150
153
|
}
|
|
151
154
|
|
|
152
|
-
this.log('Your Discord Bot \
|
|
155
|
+
this.log('Your Discord Bot \x1b[32m' + this.answers.botName + '\x1b[0m has been created!');
|
|
153
156
|
|
|
154
157
|
}
|
|
155
158
|
|
package/templates/python/main.py
CHANGED
|
@@ -17,4 +17,5 @@ async def on_message(message):
|
|
|
17
17
|
if message.content.startswith('!ping'):
|
|
18
18
|
await message.channel.send('Pong!')
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
# 'log_handler=None' is used to disable the default logging handler. Remove it if you want to use the default logging handler.
|
|
21
|
+
client.run('<%= bot-token %>', log_handler=None)
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { describe, expect, test } from 'vitest';
|
|
2
|
+
import { createHelpers } from 'yeoman-test';
|
|
3
|
+
import { spawn, exec } from 'child_process';
|
|
4
|
+
import * as dotenv from 'dotenv';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
import url from 'url';
|
|
7
|
+
|
|
8
|
+
const __dirname = url.fileURLToPath(new URL('../', import.meta.url));
|
|
9
|
+
const TIMEOUT = 30_000; // 30 seconds
|
|
10
|
+
|
|
11
|
+
dotenv.config();
|
|
12
|
+
|
|
13
|
+
const { BOT_TOKEN } = process.env;
|
|
14
|
+
if (!BOT_TOKEN) {
|
|
15
|
+
throw new Error('You must specify a valid bot token in the BOT_TOKEN environment variable');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const defaultAnswers = {
|
|
19
|
+
botName: 'test-run-bot',
|
|
20
|
+
botType: 'typescript',
|
|
21
|
+
botToken: BOT_TOKEN,
|
|
22
|
+
openWithCode: false,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
describe('Check if the templates work', () => {
|
|
26
|
+
const targetRoot = path.join(__dirname, 'test-temp');
|
|
27
|
+
const moduleRoot = path.join(__dirname, 'app');
|
|
28
|
+
const resultRoot = path.join(targetRoot, defaultAnswers.botName);
|
|
29
|
+
|
|
30
|
+
test('Should generate and run TypeScript Discord Bot', async () => {
|
|
31
|
+
const context = createHelpers({}).run(moduleRoot);
|
|
32
|
+
|
|
33
|
+
context.targetDirectory = targetRoot;
|
|
34
|
+
context.cleanTestDirectory(true);
|
|
35
|
+
await context
|
|
36
|
+
.onGenerator(generator => {
|
|
37
|
+
generator.destinationRoot(targetRoot);
|
|
38
|
+
})
|
|
39
|
+
.withAnswers(defaultAnswers)
|
|
40
|
+
.then(async () => {
|
|
41
|
+
const result = await runBot('node', ['./dist/src/index.js'], resultRoot);
|
|
42
|
+
expect(result).toContain(BOT_OUTPUT_START);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
context.cleanup();
|
|
46
|
+
}, 120_000);
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
test.skip('Should generate and run Python Discord Bot', async () => {
|
|
50
|
+
const context = createHelpers({}).run(moduleRoot);
|
|
51
|
+
|
|
52
|
+
context.targetDirectory = targetRoot;
|
|
53
|
+
context.cleanTestDirectory(true);
|
|
54
|
+
await context
|
|
55
|
+
.onGenerator(generator => {
|
|
56
|
+
generator.destinationRoot(targetRoot);
|
|
57
|
+
})
|
|
58
|
+
.withAnswers({...defaultAnswers, botType: 'python' })
|
|
59
|
+
.then(async () => {
|
|
60
|
+
// install dependencies
|
|
61
|
+
await exec('pip3 install -r requirements.txt', { cwd: resultRoot });
|
|
62
|
+
|
|
63
|
+
const result = await runBot('python', ['main.py'], resultRoot);
|
|
64
|
+
expect(result).toContain(BOT_OUTPUT_START);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
context.cleanup();
|
|
68
|
+
}, 120_000);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
async function runBot(command: string, args: string[], root: string): Promise<string> {
|
|
73
|
+
const childProcess = spawn(command, args, { cwd: root, stdio: 'pipe', timeout: TIMEOUT });
|
|
74
|
+
|
|
75
|
+
const result = await new Promise<string>((resolve) => {
|
|
76
|
+
// timeout
|
|
77
|
+
const timeout = setTimeout(() => {
|
|
78
|
+
resolve('TIMEOUT');
|
|
79
|
+
}, TIMEOUT);
|
|
80
|
+
|
|
81
|
+
// output
|
|
82
|
+
childProcess.stdout.on('data', (data) => {
|
|
83
|
+
clearTimeout(timeout);
|
|
84
|
+
|
|
85
|
+
resolve(data.toString());
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
childProcess.stderr.on('data', (data) => {
|
|
89
|
+
clearTimeout(timeout);
|
|
90
|
+
|
|
91
|
+
resolve(data.toString());
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
childProcess.on('close', () => {
|
|
95
|
+
clearTimeout(timeout);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
childProcess.kill('SIGINT');
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
const BOT_OUTPUT_START = 'Bot is logged in as';
|
package/test/generator.test.ts
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { describe, test } from 'vitest';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { createHelpers } from 'yeoman-test';
|
|
4
|
-
|
|
5
|
-
const currentUrl = new URL('../', import.meta.url).pathname;
|
|
6
|
-
|
|
7
|
-
const defaultAnswers = {
|
|
8
|
-
botName: 'test-bot',
|
|
9
|
-
botType: 'typescript',
|
|
10
|
-
botToken: 'xxx',
|
|
11
|
-
openWithCode: false,
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
describe('Check yeoman generator works', () => {
|
|
15
|
-
const targetRoot = path.join(currentUrl, defaultAnswers.botName) + '/';
|
|
16
|
-
|
|
17
|
-
test('Should produce TypeScript files', async () => {
|
|
18
|
-
const context = createHelpers({}).run(path.join(currentUrl, './app'));
|
|
19
|
-
context.targetDirectory = targetRoot;
|
|
20
|
-
context.cleanTestDirectory(true);
|
|
21
|
-
await context
|
|
22
|
-
.withAnswers(defaultAnswers)
|
|
23
|
-
.withArguments(['skip-install', 'skip-build'])
|
|
24
|
-
.then((result) => {
|
|
25
|
-
const files = [
|
|
26
|
-
targetRoot + 'config.json',
|
|
27
|
-
targetRoot + 'src/index.ts',
|
|
28
|
-
targetRoot + 'tsconfig.json',
|
|
29
|
-
targetRoot + 'package.json',
|
|
30
|
-
];
|
|
31
|
-
result.assertFile(files);
|
|
32
|
-
result.assertJsonFileContent(targetRoot + 'config.json', CONFIG_JSON_EXPECTED);
|
|
33
|
-
});
|
|
34
|
-
context.cleanup();
|
|
35
|
-
}, 120_000);
|
|
36
|
-
|
|
37
|
-
test('Should produce Python files', async () => {
|
|
38
|
-
const context = createHelpers({}).run(path.join(currentUrl, './app'));
|
|
39
|
-
context.targetDirectory = targetRoot;
|
|
40
|
-
context.cleanTestDirectory(true);
|
|
41
|
-
await context
|
|
42
|
-
.withAnswers({...defaultAnswers, botType: 'python'})
|
|
43
|
-
.then((result) => {
|
|
44
|
-
const files = [
|
|
45
|
-
targetRoot + 'main.py',
|
|
46
|
-
targetRoot + 'requirements.txt',
|
|
47
|
-
];
|
|
48
|
-
result.assertFile(files);
|
|
49
|
-
result.assertFileContent(targetRoot + 'main.py', PYTHON_BOT_EXPECTED);
|
|
50
|
-
});
|
|
51
|
-
context.cleanup();
|
|
52
|
-
}, 120_000);
|
|
53
|
-
|
|
54
|
-
test('Should produce Rust files', async () => {
|
|
55
|
-
const context = createHelpers({}).run(path.join(currentUrl, './app'));
|
|
56
|
-
context.targetDirectory = targetRoot;
|
|
57
|
-
context.cleanTestDirectory(true);
|
|
58
|
-
await context
|
|
59
|
-
.withAnswers({...defaultAnswers, botType: 'rust'})
|
|
60
|
-
.then((result) => {
|
|
61
|
-
const files = [
|
|
62
|
-
targetRoot + 'src/main.rs',
|
|
63
|
-
targetRoot + 'Cargo.toml',
|
|
64
|
-
];
|
|
65
|
-
result.assertFile(files);
|
|
66
|
-
result.assertFileContent(targetRoot + 'Cargo.toml', CARGO_TOML_EXPECTED);
|
|
67
|
-
});
|
|
68
|
-
context.cleanup();
|
|
69
|
-
}, 120_000);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
const CONFIG_JSON_EXPECTED: Record<string, string> = {
|
|
73
|
-
'token':'xxx'
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
const PYTHON_BOT_EXPECTED = `import discord
|
|
77
|
-
|
|
78
|
-
intents = discord.Intents.default()
|
|
79
|
-
intents.message_content = True
|
|
80
|
-
|
|
81
|
-
client = discord.Client(intents=intents)
|
|
82
|
-
|
|
83
|
-
@client.event
|
|
84
|
-
async def on_ready():
|
|
85
|
-
print(f'Bot is logged in as {client.user}')
|
|
86
|
-
|
|
87
|
-
@client.event
|
|
88
|
-
async def on_message(message):
|
|
89
|
-
if message.author == client.user:
|
|
90
|
-
return
|
|
91
|
-
|
|
92
|
-
if message.content.startswith('!ping'):
|
|
93
|
-
await message.channel.send('Pong!')
|
|
94
|
-
|
|
95
|
-
client.run('xxx')
|
|
96
|
-
`;
|
|
97
|
-
|
|
98
|
-
const CARGO_TOML_EXPECTED = `[package]
|
|
99
|
-
name = "test-bot"
|
|
100
|
-
version = "0.1.0"
|
|
101
|
-
edition = "2021"
|
|
102
|
-
|
|
103
|
-
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
104
|
-
|
|
105
|
-
[dependencies]
|
|
106
|
-
serenity = { version = "0.11.6", default-features = false, features = ["client", "gateway", "rustls_backend", "model"] }
|
|
107
|
-
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
|
|
108
|
-
`;
|