generator-discord 1.2.4 → 1.2.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  <div id="logo" align="center">
2
2
  <a href="https://github.com/emilkrebs/Generator-Discord" target="_blank" rel="noopener noreferrer">
3
- <img width="256" alt="Generator-Discord Logo" src="https://raw.githubusercontent.com/emilkrebs/Generator-Discord/main/assets/icon.svg">
4
- </a>
3
+ <img width="256" alt="Generator-Discord Logo" src="./assets/icon.svg">
4
+ </a>
5
5
  <h3>
6
6
  Yeoman Generator for Discord.js
7
7
  </h3>
@@ -10,11 +10,10 @@
10
10
  <div id="badges" align="center">
11
11
 
12
12
  [![Build](https://github.com/emilkrebs/generator-discord/actions/workflows/build.yml/badge.svg)](https://github.com/emilkrebs/generator-discord/actions/workflows/build.yml)
13
- [![Tests](https://github.com/emilkrebs/generator-discord/actions/workflows/test.yml/badge.svg)](https://github.com/emilkrebs/generator-discord/actions/workflows/test.yml)
13
+ [![Tests](https://github.com/emilkrebs/generator-discord/actions/workflows/test.yml/badge.svg)](https://github.com/emilkrebs/generator-discord/actions/workflows/test.yml)
14
14
  [![downloads](https://img.shields.io/npm/dw/generator-discord?color=orange)](https://www.npmjs.com/package/generator-discord)
15
- [![version](https://img.shields.io/npm/v/generator-discord)](https://www.npmjs.com/package/generator-discord)
15
+ [![version](https://img.shields.io/npm/v/generator-discord)](https://www.npmjs.com/package/generator-discord)
16
16
 
17
-
18
17
  </div>
19
18
 
20
19
  <hr>
@@ -22,6 +21,7 @@
22
21
  Generate a basic starter project for a new Discord-bot in your favorite programming language.
23
22
 
24
23
  ### Supported programming languages
24
+
25
25
  - TypeScript
26
26
  - JavaScript
27
27
  - Python
@@ -33,20 +33,24 @@ Generate a basic starter project for a new Discord-bot in your favorite programm
33
33
 
34
34
  # Installing the Generator
35
35
 
36
- Install Yeoman using
36
+ Install Yeoman using
37
+
37
38
  ```bash
38
39
  npm install -g yo
39
40
  ```
40
- Install this Generator using
41
+
42
+ Install this Generator using
43
+
41
44
  ```bash
42
45
  npm install -g generator-discord
43
46
  ```
47
+
44
48
  # Run using yo
49
+
45
50
  ```bash
46
51
  yo discord
47
52
  ```
48
53
 
49
-
50
54
  [![Example](https://user-images.githubusercontent.com/68400102/175165919-473536d8-c7c0-4881-a438-d11dc8001ee1.png)](https://github.com/emilkrebs/Sound-Bot)
51
55
 
52
56
  ## Known Issues
package/app/index.js CHANGED
@@ -18,10 +18,12 @@ const TEMPLATE_DIR = '../templates/';
18
18
  const USER_DIR = '.';
19
19
  const BOT_NAME = /<%= bot-name %>/g;
20
20
  const BOT_TOKEN = /<%= bot-token %>/g;
21
+ // needed for rust
21
22
  const BOT_NAME_RUST = /bot_name/g;
22
23
  class DiscordGenerator extends yeoman_generator_1.default {
23
24
  constructor(args, options) {
24
25
  super(args, options);
26
+ this.answers = {};
25
27
  }
26
28
  prompting() {
27
29
  return __awaiter(this, void 0, void 0, function* () {
@@ -32,7 +34,7 @@ class DiscordGenerator extends yeoman_generator_1.default {
32
34
  name: 'botName',
33
35
  message: 'Your Discord Bot name:',
34
36
  default: 'my-bot',
35
- validate: (input) => new RegExp("^(?:@[a-z0-9-*~][a-z0-9-*._~]*/)?[a-z0-9-~][a-z0-9-._~]*$").test(input)
37
+ validate: (input) => new RegExp('^(?:@[a-z0-9-*~][a-z0-9-*._~]*/)?[a-z0-9-~][a-z0-9-._~]*$').test(input)
36
38
  ? true
37
39
  : 'Invalid bot name. Please use only lowercase letters, numbers, and hyphens. Must start with a letter.'
38
40
  },
@@ -69,35 +71,40 @@ class DiscordGenerator extends yeoman_generator_1.default {
69
71
  });
70
72
  }
71
73
  logo() {
72
- this.log(" \x1b[36m_____ _ _ \x1b[31m_ ");
73
- this.log(" \x1b[36m| __ \\(_) | | \x1b[31m(_) ");
74
- this.log(" \x1b[36m| | | |_ ___ ___ ___ _ __ __| | \x1b[33m_ ___ ");
75
- this.log(" \x1b[36m| | | | / __|/ __/ _ \\| '__/ _` | \x1b[33m| / __|");
76
- this.log(" \x1b[36m| |__| | \\__ \\ (_| (_) | | | (_| |\x1b[37m_\x1b[32m| \\__ \\");
77
- this.log(" \x1b[36m|_____/|_|___/\\___\\___/|_| \\__,_\x1b[37m(_) \x1b[32m|___/");
78
- this.log(" \x1b[34m_/ | ");
79
- this.log(" \x1b[35m|__/ ");
80
- this.log("\x1b[0m");
74
+ this.log(' \x1b[36m_____ _ _ \x1b[31m_');
75
+ this.log(' \x1b[36m| __ \\(_) | | \x1b[31m(_)');
76
+ this.log(' \x1b[36m| | | |_ ___ ___ ___ _ __ __| | \x1b[33m_ ___');
77
+ this.log(' \x1b[36m| | | | / __|/ __/ _ \\| \'__/ _` | \x1b[33m| / __|');
78
+ this.log(' \x1b[36m| |__| | \\__ \\ (_| (_) | | | (_| |\x1b[37m_\x1b[32m| \\__ \\');
79
+ this.log(' \x1b[36m|_____/|_|___/\\___\\___/|_| \\__,_\x1b[37m(_) \x1b[32m|___/');
80
+ this.log(' \x1b[34m_/ |');
81
+ this.log(' \x1b[35m|__/');
82
+ this.log('\x1b[0m');
81
83
  }
82
84
  writing() {
83
85
  this.sourceRoot(path_1.default.join(__dirname, TEMPLATE_DIR + this.answers.botType));
84
- ['.'].forEach((path) => {
86
+ const paths = ['.'];
87
+ // iterate over all files
88
+ for (let i = 0, len = paths.length; i < len; i++) {
89
+ const path = paths[i];
85
90
  this.fs.copy(this.templatePath(path), this.destinationPath(USER_DIR, this.answers.botName, path), {
86
91
  process: (content) => this._replaceWords(content, this.answers)
87
92
  });
88
- });
93
+ }
89
94
  }
90
95
  install() {
91
96
  return __awaiter(this, void 0, void 0, function* () {
92
97
  this.log('');
93
98
  if (this.answers.botType === 'typescript' || this.answers.botType === 'javascript') {
94
99
  const options = { cwd: this.destinationPath(USER_DIR, this.answers.botName) };
100
+ this.log('Installing dependencies...');
95
101
  this.spawnCommandSync('npm', ['install'], options);
96
102
  if (this.answers.botType === 'typescript') {
103
+ this.log('Building your Discord Bot...');
97
104
  this.spawnCommandSync('npm', ['run', 'build'], options);
98
105
  }
99
106
  }
100
- this.log('Your Discord Bot ' + this.answers.botName + ' has been created!');
107
+ this.log('Your Discord Bot \'\x1b[32m' + this.answers.botName + '\x1b[0m\' has been created!');
101
108
  });
102
109
  }
103
110
  end() {
@@ -105,7 +112,7 @@ class DiscordGenerator extends yeoman_generator_1.default {
105
112
  const answer = yield this.prompt({
106
113
  type: 'list',
107
114
  name: 'openWithCode',
108
- message: 'Do you want to open your Discord Bot with Visual Studio Code?',
115
+ message: 'Do you want to open your Discord Bot with \x1b[36mVisual Studio Code\x1b[0m?',
109
116
  choices: [
110
117
  {
111
118
  name: 'open with `code`',
package/app/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,wEAAyC;AACzC,gDAAwB;AAExB,MAAM,YAAY,GAAG,eAAe,CAAC;AACrC,MAAM,QAAQ,GAAG,GAAG,CAAC;AAErB,MAAM,QAAQ,GAAG,kBAAkB,CAAC;AACpC,MAAM,SAAS,GAAG,mBAAmB,CAAC;AAEtC,MAAM,aAAa,GAAG,WAAW,CAAC;AAYlC,MAAqB,gBAAiB,SAAQ,0BAAS;IAGnD,YAAY,IAAuB,EAAE,OAAmC;QACpE,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACzB,CAAC;IAEK,SAAS;;YACX,IAAI,CAAC,IAAI,EAAE,CAAC;YACZ,IAAI,CAAC,OAAO,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC;gBAC7B;oBACI,IAAI,EAAE,OAAO;oBACb,IAAI,EAAE,SAAS;oBACf,OAAO,EAAE,wBAAwB;oBACjC,OAAO,EAAE,QAAQ;oBACjB,QAAQ,EAAE,CAAC,KAAa,EAAoB,EAAE,CAC1C,IAAI,MAAM,CAAC,2DAA2D,CAAC,CAAC,IAAI,CAAC,KA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,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;AA3ID,mCA2IC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "generator-discord",
3
3
  "displayName": "Generator-Discord",
4
- "version": "1.2.4",
4
+ "version": "1.2.6",
5
5
  "main": "./app/index.js",
6
6
  "description": "Yeoman generator for Discord.js",
7
7
  "keywords": [
@@ -14,6 +14,7 @@
14
14
  "build": "tsc",
15
15
  "watch": "tsc -w",
16
16
  "test": "vitest run",
17
+ "lint": "eslint src test --ext .ts",
17
18
  "debug": "npx --node-arg=--inspect yo discord",
18
19
  "clean": "npx rimraf app && npx rimraf node_modules"
19
20
  },
@@ -38,8 +39,11 @@
38
39
  "yeoman-generator": "^5.9.0"
39
40
  },
40
41
  "devDependencies": {
41
- "vitest": "^0.34.3",
42
+ "@typescript-eslint/eslint-plugin": "^6.7.2",
43
+ "@typescript-eslint/parser": "^6.7.2",
44
+ "eslint": "^8.49.0",
42
45
  "typescript": "^5.2.2",
46
+ "vitest": "^0.34.4",
43
47
  "yeoman-test": "^7.4.0"
44
48
  }
45
49
  }
package/src/index.ts CHANGED
@@ -7,149 +7,156 @@ const USER_DIR = '.';
7
7
  const BOT_NAME = /<%= bot-name %>/g;
8
8
  const BOT_TOKEN = /<%= bot-token %>/g;
9
9
 
10
+ // needed for rust
10
11
  const BOT_NAME_RUST = /bot_name/g;
11
12
 
12
13
  type BotType = 'typescript' | 'javascript' | 'python' | 'rust';
13
14
 
14
15
  interface Answers {
15
- botName: string;
16
- botType: BotType;
17
- botToken: string;
18
- openWithCode: boolean;
16
+ botName: string;
17
+ botType: BotType;
18
+ botToken: string;
19
+ openWithCode: boolean;
19
20
  }
20
21
 
21
22
 
22
23
  export default class DiscordGenerator extends Generator {
23
- private answers: Answers;
24
-
25
- constructor(args: string | string[], options: Generator.GeneratorOptions) {
26
- super(args, options);
27
- }
28
-
29
- async prompting(): Promise<void> {
30
- this.logo();
31
- this.answers = await this.prompt([
32
- {
33
- type: 'input',
34
- name: 'botName',
35
- message: 'Your Discord Bot name:',
36
- default: 'my-bot',
37
- validate: (input: string): boolean | string =>
38
- new RegExp("^(?:@[a-z0-9-*~][a-z0-9-*._~]*/)?[a-z0-9-~][a-z0-9-._~]*$").test(input)
39
- ? true
40
- : 'Invalid bot name. Please use only lowercase letters, numbers, and hyphens. Must start with a letter.'
41
- },
42
- {
43
- type: 'list',
44
- name: 'botType',
45
- message: 'The type of Discord Bot you want to create.',
46
- choices: [
47
- {
48
- name: 'New Discord Bot (TypeScript)',
49
- value: 'typescript'
50
- },
51
- {
52
- name: 'New Discord Bot (JavaScript)',
53
- value: 'javascript'
54
- },
55
- {
56
- name: 'New Discord Bot (Python)',
57
- value: 'python'
58
- },
59
- {
60
- name: 'New Discord Bot (Rust)',
61
- value: 'rust'
62
- },
63
- ]
64
- },
65
- {
66
- type: 'input',
67
- name: 'botToken',
68
- message: 'Your Discord Bot Token. (Enter to leave blank)',
69
- default: 'your-bot-token'
70
- }
71
- ]);
72
- }
73
-
74
- logo(): void {
75
- this.log(" \x1b[36m_____ _ _ \x1b[31m_ ");
76
- this.log(" \x1b[36m| __ \\(_) | | \x1b[31m(_) ");
77
- this.log(" \x1b[36m| | | |_ ___ ___ ___ _ __ __| | \x1b[33m_ ___ ");
78
- this.log(" \x1b[36m| | | | / __|/ __/ _ \\| '__/ _` | \x1b[33m| / __|");
79
- this.log(" \x1b[36m| |__| | \\__ \\ (_| (_) | | | (_| |\x1b[37m_\x1b[32m| \\__ \\");
80
- this.log(" \x1b[36m|_____/|_|___/\\___\\___/|_| \\__,_\x1b[37m(_) \x1b[32m|___/");
81
- this.log(" \x1b[34m_/ | ");
82
- this.log(" \x1b[35m|__/ ");
83
- this.log("\x1b[0m");
84
- }
85
-
86
- writing(): void {
87
- this.sourceRoot(path.join(__dirname, TEMPLATE_DIR + this.answers.botType));
88
- ['.'].forEach(
89
- (path: string) => {
90
- this.fs.copy(
91
- this.templatePath(path),
92
- this.destinationPath(
93
- USER_DIR,
94
- this.answers.botName,
95
- path
96
- ),
97
- {
98
- process: (content: Buffer) => this._replaceWords(content, this.answers)
99
- }
100
- );
101
- }
102
- );
103
- }
104
-
105
- async install(): Promise<void> {
106
- this.log('');
107
- if (this.answers.botType === 'typescript' || this.answers.botType === 'javascript') {
108
- const options = { cwd: this.destinationPath(USER_DIR, this.answers.botName) };
109
- this.spawnCommandSync('npm', ['install'], options);
110
- if(this.answers.botType === 'typescript') {
111
- this.spawnCommandSync('npm', ['run', 'build'], options);
112
- }
113
- }
114
-
115
- this.log('Your Discord Bot ' + this.answers.botName + ' has been created!');
116
-
117
- }
118
-
119
- async end(): Promise<void> {
120
- const answer = await this.prompt({
121
- type: 'list',
122
- name: 'openWithCode',
123
- message: 'Do you want to open your Discord Bot with Visual Studio Code?',
124
- choices: [
125
- {
126
- name: 'open with `code`',
127
- value: true
128
- },
129
- {
130
- name: 'skip',
131
- value: false
132
- }
133
- ]
134
- });
135
- this.log('');
136
- if (answer && answer.openWithCode) {
137
- this.spawnCommand('code', [this.destinationPath(
138
- USER_DIR,
139
- this.answers.botName
140
- )]);
141
- }
142
- }
143
-
144
- _replaceWords(content: Buffer, answers: Answers): string {
145
- if(answers.botType === 'rust') {
146
- return content.toString()
147
- .replace(BOT_TOKEN, answers.botToken)
148
- .replace(BOT_NAME_RUST, answers.botName);
149
- }
150
-
151
- return content.toString()
152
- .replace(BOT_TOKEN,answers.botToken)
153
- .replace(BOT_NAME, answers.botName);
154
- }
24
+ private answers: Answers = {} as Answers;
25
+
26
+ constructor(args: string | string[], options: Generator.GeneratorOptions) {
27
+ super(args, options);
28
+ }
29
+
30
+ async prompting(): Promise<void> {
31
+ this.logo();
32
+ this.answers = await this.prompt([
33
+ {
34
+ type: 'input',
35
+ name: 'botName',
36
+ message: 'Your Discord Bot name:',
37
+ default: 'my-bot',
38
+ validate: (input: string): boolean | string =>
39
+ new RegExp('^(?:@[a-z0-9-*~][a-z0-9-*._~]*/)?[a-z0-9-~][a-z0-9-._~]*$').test(input)
40
+ ? true
41
+ : 'Invalid bot name. Please use only lowercase letters, numbers, and hyphens. Must start with a letter.'
42
+ },
43
+ {
44
+ type: 'list',
45
+ name: 'botType',
46
+ message: 'The type of Discord Bot you want to create.',
47
+ choices: [
48
+ {
49
+ name: 'New Discord Bot (TypeScript)',
50
+ value: 'typescript'
51
+ },
52
+ {
53
+ name: 'New Discord Bot (JavaScript)',
54
+ value: 'javascript'
55
+ },
56
+ {
57
+ name: 'New Discord Bot (Python)',
58
+ value: 'python'
59
+ },
60
+ {
61
+ name: 'New Discord Bot (Rust)',
62
+ value: 'rust'
63
+ },
64
+ ]
65
+ },
66
+ {
67
+ type: 'input',
68
+ name: 'botToken',
69
+ message: 'Your Discord Bot Token. (Enter to leave blank)',
70
+ default: 'your-bot-token'
71
+ }
72
+ ]);
73
+ }
74
+
75
+ logo(): void {
76
+ this.log(' \x1b[36m_____ _ _ \x1b[31m_');
77
+ this.log(' \x1b[36m| __ \\(_) | | \x1b[31m(_)');
78
+ this.log(' \x1b[36m| | | |_ ___ ___ ___ _ __ __| | \x1b[33m_ ___');
79
+ this.log(' \x1b[36m| | | | / __|/ __/ _ \\| \'__/ _` | \x1b[33m| / __|');
80
+ this.log(' \x1b[36m| |__| | \\__ \\ (_| (_) | | | (_| |\x1b[37m_\x1b[32m| \\__ \\');
81
+ this.log(' \x1b[36m|_____/|_|___/\\___\\___/|_| \\__,_\x1b[37m(_) \x1b[32m|___/');
82
+ this.log(' \x1b[34m_/ |');
83
+ this.log(' \x1b[35m|__/');
84
+ this.log('\x1b[0m');
85
+ }
86
+
87
+ writing(): void {
88
+ this.sourceRoot(path.join(__dirname, TEMPLATE_DIR + this.answers.botType));
89
+ const paths = ['.'];
90
+
91
+ // iterate over all files
92
+ for (let i = 0, len = paths.length; i < len; i++) {
93
+ const path = paths[i];
94
+ this.fs.copy(
95
+ this.templatePath(path),
96
+ this.destinationPath(
97
+ USER_DIR,
98
+ this.answers.botName,
99
+ path
100
+ ),
101
+ {
102
+ process: (content) => this._replaceWords(content, this.answers)
103
+ }
104
+ );
105
+ }
106
+ }
107
+
108
+ async install(): Promise<void> {
109
+ this.log('');
110
+ if (this.answers.botType === 'typescript' || this.answers.botType === 'javascript') {
111
+ const options = { cwd: this.destinationPath(USER_DIR, this.answers.botName) };
112
+
113
+ this.log('Installing dependencies...');
114
+ this.spawnCommandSync('npm', ['install'], options);
115
+
116
+ if (this.answers.botType === 'typescript') {
117
+ this.log('Building your Discord Bot...');
118
+ this.spawnCommandSync('npm', ['run', 'build'], options);
119
+ }
120
+ }
121
+
122
+ this.log('Your Discord Bot \'\x1b[32m' + this.answers.botName + '\x1b[0m\' has been created!');
123
+
124
+ }
125
+
126
+ async end(): Promise<void> {
127
+ const answer = await this.prompt({
128
+ type: 'list',
129
+ name: 'openWithCode',
130
+ message: 'Do you want to open your Discord Bot with \x1b[36mVisual Studio Code\x1b[0m?',
131
+ choices: [
132
+ {
133
+ name: 'open with `code`',
134
+ value: true
135
+ },
136
+ {
137
+ name: 'skip',
138
+ value: false
139
+ }
140
+ ]
141
+ });
142
+ this.log('');
143
+ if (answer && answer.openWithCode) {
144
+ this.spawnCommand('code', [this.destinationPath(
145
+ USER_DIR,
146
+ this.answers.botName
147
+ )]);
148
+ }
149
+ }
150
+
151
+ _replaceWords(content: Buffer, answers: Answers): string {
152
+ if (answers.botType === 'rust') {
153
+ return content.toString()
154
+ .replace(BOT_TOKEN, answers.botToken)
155
+ .replace(BOT_NAME_RUST, answers.botName);
156
+ }
157
+
158
+ return content.toString()
159
+ .replace(BOT_TOKEN, answers.botToken)
160
+ .replace(BOT_NAME, answers.botName);
161
+ }
155
162
  }
@@ -7,32 +7,32 @@ const prefix = '!';
7
7
 
8
8
  // Run this code when the client is ready. This event will only trigger one time after logging in
9
9
  client.once('ready', () => {
10
- console.log(`Bot is logged in as ${client.user.tag}.`);
10
+ console.log(`Bot is logged in as ${client.user.tag}.`);
11
11
  });
12
12
 
13
13
 
14
14
  // Listen for messages
15
15
  client.on('messageCreate', async message => {
16
- // Ignore messages that don't start with the prefix or are from a bot
17
- if (!message.content.startsWith(prefix) || message.author.bot) return;
18
-
19
- // Split the message into command and arguments
20
- const args = message.content.slice(prefix.length).trim().split(/ +/);
21
- const command = args.shift()?.toLowerCase();
22
-
23
- // ping - bot will reply with Pong!
24
- if (command === 'ping') {
25
- await message.reply('Pong!');
26
- }
27
- // say <message> - bot will send the message
28
- else if (command === 'say') {
29
- if (!args.length) {
30
- await message.channel.send(`You didn't provide any arguments, ${message.author}!`);
31
- return;
32
- }
33
- await message.channel.send(args.join(' '));
34
- return;
35
- }
16
+ // Ignore messages that don't start with the prefix or are from a bot
17
+ if (!message.content.startsWith(prefix) || message.author.bot) return;
18
+
19
+ // Split the message into command and arguments
20
+ const args = message.content.slice(prefix.length).trim().split(/ +/);
21
+ const command = args.shift()?.toLowerCase();
22
+
23
+ // ping - bot will reply with Pong!
24
+ if (command === 'ping') {
25
+ await message.reply('Pong!');
26
+ }
27
+ // say <message> - bot will send the message
28
+ else if (command === 'say') {
29
+ if (!args.length) {
30
+ await message.channel.send(`You didn't provide any arguments, ${message.author}!`);
31
+ return;
32
+ }
33
+ await message.channel.send(args.join(' '));
34
+ return;
35
+ }
36
36
  });
37
37
 
38
38
 
@@ -7,32 +7,32 @@ const prefix = '!';
7
7
 
8
8
  // Run this code when the client is ready. This event will only trigger one time after logging in
9
9
  client.once('ready', () => {
10
- console.log(`Bot is logged in as ${client.user.tag}.`);
10
+ console.log(`Bot is logged in as ${client.user!.tag}.`);
11
11
  });
12
12
 
13
13
 
14
14
  // Listen for messages
15
15
  client.on('messageCreate', async message => {
16
- // Ignore messages that don't start with the prefix or are from a bot
17
- if(!message.content.startsWith(prefix) || message.author.bot) return;
16
+ // Ignore messages that don't start with the prefix or are from a bot
17
+ if(!message.content.startsWith(prefix) || message.author.bot) return;
18
18
 
19
- // Split the message into command and arguments
20
- const args = message.content.slice(prefix.length).trim().split(/ +/);
21
- const command = args.shift()?.toLowerCase();
19
+ // Split the message into command and arguments
20
+ const args = message.content.slice(prefix.length).trim().split(/ +/);
21
+ const command = args.shift()?.toLowerCase();
22
22
 
23
- // ping - bot will reply with Pong!
24
- if(command === 'ping') {
25
- await message.reply('Pong!');
26
- }
27
- // say <message> - bot will send the message
28
- else if(command === 'say') {
29
- if(!args.length) {
30
- await message.channel.send(`You didn't provide any arguments, ${message.author}!`);
31
- return;
32
- }
33
- await message.channel.send(args.join(' '));
34
- return;
35
- }
23
+ // ping - bot will reply with Pong!
24
+ if(command === 'ping') {
25
+ await message.reply('Pong!');
26
+ }
27
+ // say <message> - bot will send the message
28
+ else if(command === 'say') {
29
+ if(!args.length) {
30
+ await message.channel.send(`You didn't provide any arguments, ${message.author}!`);
31
+ return;
32
+ }
33
+ await message.channel.send(args.join(' '));
34
+ return;
35
+ }
36
36
  });
37
37
 
38
38
 
@@ -5,7 +5,7 @@
5
5
  "lib": ["ESNext"],
6
6
  "sourceMap": true,
7
7
  "outDir": "dist",
8
- "strict": false,
8
+ "strict": true,
9
9
  "noUnusedLocals": true,
10
10
  "noImplicitReturns": true,
11
11
  "moduleResolution": "node",
@@ -1,70 +1,70 @@
1
1
  import { describe, test } from 'vitest';
2
2
  import path from 'path';
3
3
  import { createHelpers } from 'yeoman-test';
4
- import {EOL} from 'os'
4
+ import {EOL} from 'os';
5
5
 
6
6
  const typescriptAnswers = {
7
- botName: 'typescript-bot',
8
- botType: 'typescript',
9
- botToken: 'xxx',
10
- openWithCode: false,
11
- }
7
+ botName: 'typescript-bot',
8
+ botType: 'typescript',
9
+ botToken: 'xxx',
10
+ openWithCode: false,
11
+ };
12
12
 
13
13
  const pythonAnswers = {
14
- botName: 'python-bot',
15
- botType: 'python',
16
- botToken: 'xxxx',
17
- openWithCode: false,
18
- }
14
+ botName: 'python-bot',
15
+ botType: 'python',
16
+ botToken: 'xxxx',
17
+ openWithCode: false,
18
+ };
19
19
 
20
20
  describe('Check if the generator works', () => {
21
- test('Should generate typescript files', async () => {
22
- const context = createHelpers({}).run(path.join(__dirname, '../app'));
23
- context.targetDirectory = path.join(__dirname, '../test-temp'); // generate in test-temp
24
- context.cleanTestDirectory(true); // clean-up test-temp
25
- await context.onGenerator(generator => generator.destinationRoot(context.targetDirectory, false))
26
- .withAnswers(typescriptAnswers)
27
- .then((result) => {
28
- result.assertFile([`${typescriptAnswers.botName}/package.json`]);
29
- result.assertFile([`${typescriptAnswers.botName}/config.json`]);
30
- result.assertFile([`${typescriptAnswers.botName}/src/index.ts`]);
31
- result.assertFileContent(`${typescriptAnswers.botName}/config.json`, CONFIG_JSON_EXPECTED);
32
- });
33
- context.cleanup(); // clean-up
34
- }, 120_000);
35
- test('Should generate python files', async () => {
36
- const context = createHelpers({}).run(path.join(__dirname, '../app'));
37
- context.targetDirectory = path.join(__dirname, '../test-temp'); // generate in test-temp
38
- context.cleanTestDirectory(true); // clean-up test-temp
39
- await context.onGenerator(generator => generator.destinationRoot(context.targetDirectory, false))
40
- .withAnswers(pythonAnswers)
41
- .then((result) => {
42
- result.assertFile([`${pythonAnswers.botName}/bot.py`]);
43
- result.assertFileContent(`${pythonAnswers.botName}/bot.py`, BOT_PY_EXPECTED);
44
- });
45
- context.cleanup(); // clean-up
46
- }, 120_000);
47
- test('Should generate rust files', async () => {
48
- const context = createHelpers({}).run(path.join(__dirname, '../app'));
49
- context.targetDirectory = path.join(__dirname, '../test-temp'); // generate in test-temp
50
- context.cleanTestDirectory(true); // clean-up test-temp
51
- await context.onGenerator(generator => generator.destinationRoot(context.targetDirectory, false))
52
- .withAnswers({
53
- ...pythonAnswers,
54
- botType: 'rust',
55
- })
56
- .then((result) => {
57
- result.assertFile([`${pythonAnswers.botName}/Cargo.toml`]);
58
- result.assertFile([`${pythonAnswers.botName}/src/main.rs`]);
59
- });
60
- context.cleanup(); // clean-up
61
- }
62
- , 120_000);
21
+ test('Should generate typescript files', async () => {
22
+ const context = createHelpers({}).run(path.join(__dirname, '../app'));
23
+ context.targetDirectory = path.join(__dirname, '../test-temp'); // generate in test-temp
24
+ context.cleanTestDirectory(true); // clean-up test-temp
25
+ await context.onGenerator(generator => generator.destinationRoot(context.targetDirectory, false))
26
+ .withAnswers(typescriptAnswers)
27
+ .then((result) => {
28
+ result.assertFile([`${typescriptAnswers.botName}/package.json`]);
29
+ result.assertFile([`${typescriptAnswers.botName}/config.json`]);
30
+ result.assertFile([`${typescriptAnswers.botName}/src/index.ts`]);
31
+ result.assertFileContent(`${typescriptAnswers.botName}/config.json`, CONFIG_JSON_EXPECTED);
32
+ });
33
+ context.cleanup(); // clean-up
34
+ }, 120_000);
35
+ test('Should generate python files', async () => {
36
+ const context = createHelpers({}).run(path.join(__dirname, '../app'));
37
+ context.targetDirectory = path.join(__dirname, '../test-temp'); // generate in test-temp
38
+ context.cleanTestDirectory(true); // clean-up test-temp
39
+ await context.onGenerator(generator => generator.destinationRoot(context.targetDirectory, false))
40
+ .withAnswers(pythonAnswers)
41
+ .then((result) => {
42
+ result.assertFile([`${pythonAnswers.botName}/bot.py`]);
43
+ result.assertFileContent(`${pythonAnswers.botName}/bot.py`, BOT_PY_EXPECTED);
44
+ });
45
+ context.cleanup(); // clean-up
46
+ }, 120_000);
47
+ test('Should generate rust files', async () => {
48
+ const context = createHelpers({}).run(path.join(__dirname, '../app'));
49
+ context.targetDirectory = path.join(__dirname, '../test-temp'); // generate in test-temp
50
+ context.cleanTestDirectory(true); // clean-up test-temp
51
+ await context.onGenerator(generator => generator.destinationRoot(context.targetDirectory, false))
52
+ .withAnswers({
53
+ ...pythonAnswers,
54
+ botType: 'rust',
55
+ })
56
+ .then((result) => {
57
+ result.assertFile([`${pythonAnswers.botName}/Cargo.toml`]);
58
+ result.assertFile([`${pythonAnswers.botName}/src/main.rs`]);
59
+ });
60
+ context.cleanup(); // clean-up
61
+ }
62
+ , 120_000);
63
63
  });
64
64
 
65
65
 
66
66
  function normilizeEOL(str: string) {
67
- return str.replace(/\r?\n/g, EOL);
67
+ return str.replace(/\r?\n/g, EOL);
68
68
  }
69
69
 
70
70
  // norminlize end of line