generator-discord 1.1.4 → 1.1.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/src/index.ts CHANGED
@@ -1,147 +1,158 @@
1
- import Generator from 'yeoman-generator';
2
- import path from 'path';
3
-
4
-
5
- const TEMPLATE_DIR = '../templates/';
6
- const USER_DIR = '.';
7
-
8
- const OPEN = '<%= ';
9
- const CLOSE = ' %>';
10
-
11
- const BOT_NAME = 'bot-name';
12
- const BOT_TOKEN = 'bot-token';
13
-
14
- interface Answers {
15
- botName: string;
16
- botType: string;
17
- botToken: string;
18
- openWithCode: boolean;
19
- }
20
-
21
-
22
- 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
- : 'Your Discord Bot name does not match the pattern of: ^(?:@[a-z0-9-*~][a-z0-9-*._~]*/)?[a-z0-9-~][a-z0-9-._~]*$',
41
-
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
- {
58
- name: 'New Discord Bot (Python)',
59
- value: 'python'
60
- }
61
- ]
62
- },
63
- {
64
- type: 'input',
65
- name: 'botToken',
66
- message: 'Your Discord Bot Token. (Enter to leave blank)',
67
- default: 'your-bot-token'
68
- }
69
- ]);
70
- }
71
-
72
- logo(): void {
73
- this.log(" \x1b[36m_____ _ _ \x1b[31m_ ");
74
- this.log(" \x1b[36m| __ \\(_) | | \x1b[31m(_) ");
75
- this.log(" \x1b[36m| | | |_ ___ ___ ___ _ __ __| | \x1b[33m_ ___ ");
76
- this.log(" \x1b[36m| | | | / __|/ __/ _ \\| '__/ _` | \x1b[33m| / __|");
77
- this.log(" \x1b[36m| |__| | \\__ \\ (_| (_) | | | (_| |\x1b[37m_\x1b[32m| \\__ \\");
78
- this.log(" \x1b[36m|_____/|_|___/\\___\\___/|_| \\__,_\x1b[37m(_) \x1b[32m|___/");
79
- this.log(" \x1b[34m_/ | ");
80
- this.log(" \x1b[35m|__/ ");
81
- this.log("\x1b[0m");
82
- }
83
-
84
- writing(): void {
85
- this.sourceRoot(path.join(__dirname, TEMPLATE_DIR + this.answers.botType));
86
- ['.'].forEach(
87
- (path: string) => {
88
- const replaceWords = (
89
- answers: Answers,
90
- content: Buffer
91
- ): string =>
92
- [
93
- [BOT_NAME, this.answers.botName],
94
- [BOT_TOKEN, this.answers.botToken]
95
- ].reduce(
96
- (acc: string, [templateWord, userAnswer]) =>
97
- acc.replace(
98
- new RegExp(
99
- `${OPEN}${templateWord}${CLOSE}`,
100
- 'g'
101
- ),
102
- userAnswer
103
- ),
104
- content.toString()
105
- );
106
- this.fs.copy(
107
- this.templatePath(path),
108
- this.destinationPath(
109
- USER_DIR,
110
- this.answers.botName,
111
- path
112
- ),
113
- {
114
- process: (content: Buffer) =>
115
- replaceWords(this.answers, content)
116
- }
117
- );
118
- }
119
- );
120
- }
121
- async install(): Promise<void> {
122
- this.log('');
123
- this.log('Your Discord Bot ' + this.answers.botName + ' has been created!');
124
- const answer = await this.prompt({
125
- type: 'list',
126
- name: 'openWithCode',
127
- message: 'Do you want to open your Discord Bot with Visual Studio Code?',
128
- choices: [
129
- {
130
- name: 'open with `code`',
131
- value: true
132
- },
133
- {
134
- name: 'skip',
135
- value: false
136
- }
137
- ]
138
- });
139
- this.log('');
140
- if (answer && answer.openWithCode) {
141
- this.spawnCommand('code', [this.destinationPath(
142
- USER_DIR,
143
- this.answers.botName
144
- )]);
145
- }
146
- }
147
- }
1
+ import Generator from 'yeoman-generator';
2
+ import path from 'path';
3
+
4
+
5
+ const TEMPLATE_DIR = '../templates/';
6
+ const USER_DIR = '.';
7
+
8
+ const OPEN = '<%= ';
9
+ const CLOSE = ' %>';
10
+
11
+ const BOT_NAME = 'bot-name';
12
+ const BOT_TOKEN = 'bot-token';
13
+
14
+ interface Answers {
15
+ botName: string;
16
+ botType: string;
17
+ botToken: string;
18
+ openWithCode: boolean;
19
+ }
20
+
21
+
22
+ 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
+ {
57
+ name: 'New Discord Bot (Python)',
58
+ value: 'python'
59
+ }
60
+ ]
61
+ },
62
+ {
63
+ type: 'input',
64
+ name: 'botToken',
65
+ message: 'Your Discord Bot Token. (Enter to leave blank)',
66
+ default: 'your-bot-token'
67
+ }
68
+ ]);
69
+ }
70
+
71
+ logo(): void {
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");
81
+ }
82
+
83
+ writing(): void {
84
+ this.sourceRoot(path.join(__dirname, TEMPLATE_DIR + this.answers.botType));
85
+ ['.'].forEach(
86
+ (path: string) => {
87
+ const replaceWords = (
88
+ answers: Answers,
89
+ content: Buffer
90
+ ): string =>
91
+ [
92
+ [BOT_NAME, this.answers.botName],
93
+ [BOT_TOKEN, this.answers.botToken]
94
+ ].reduce(
95
+ (acc: string, [templateWord, userAnswer]) =>
96
+ acc.replace(
97
+ new RegExp(
98
+ `${OPEN}${templateWord}${CLOSE}`,
99
+ 'g'
100
+ ),
101
+ userAnswer
102
+ ),
103
+ content.toString()
104
+ );
105
+ this.fs.copy(
106
+ this.templatePath(path),
107
+ this.destinationPath(
108
+ USER_DIR,
109
+ this.answers.botName,
110
+ path
111
+ ),
112
+ {
113
+ process: (content: Buffer) =>
114
+ replaceWords(this.answers, content)
115
+ }
116
+ );
117
+ }
118
+ );
119
+ }
120
+ async install(): Promise<void> {
121
+ this.log('');
122
+ if (this.answers.botType === 'typescript' || this.answers.botType === 'javascript') {
123
+ const options = { cwd: this.destinationPath(USER_DIR, this.answers.botName) };
124
+ this.spawnCommandSync('npm', ['install'], options);
125
+ if(this.answers.botType === 'typescript') {
126
+ this.spawnCommandSync('npm', ['run', 'build'], options);
127
+ }
128
+ }
129
+
130
+ this.log('Your Discord Bot ' + this.answers.botName + ' has been created!');
131
+
132
+ }
133
+
134
+ async end(): Promise<void> {
135
+ const answer = await this.prompt({
136
+ type: 'list',
137
+ name: 'openWithCode',
138
+ message: 'Do you want to open your Discord Bot with Visual Studio Code?',
139
+ choices: [
140
+ {
141
+ name: 'open with `code`',
142
+ value: true
143
+ },
144
+ {
145
+ name: 'skip',
146
+ value: false
147
+ }
148
+ ]
149
+ });
150
+ this.log('');
151
+ if (answer && answer.openWithCode) {
152
+ this.spawnCommand('code', [this.destinationPath(
153
+ USER_DIR,
154
+ this.answers.botName
155
+ )]);
156
+ }
157
+ }
158
+ }
@@ -1,3 +1,3 @@
1
- {
2
- "token":"<%= bot-token %>"
1
+ {
2
+ "token":"<%= bot-token %>"
3
3
  }
@@ -1,13 +1,13 @@
1
- {
2
- "name": "<%= bot-name %>",
3
- "displayName": "<%= bot-name %>",
4
- "description": "Please enter a brief description here",
5
- "version": "1.0.0",
6
- "main": "./src/index.js",
7
- "scripts": {
8
- "start": "node ./src/index.js"
9
- },
10
- "dependencies": {
11
- "discord.js": "^13.13.1"
12
- }
13
- }
1
+ {
2
+ "name": "<%= bot-name %>",
3
+ "displayName": "<%= bot-name %>",
4
+ "description": "Please enter a brief description here",
5
+ "version": "1.0.0",
6
+ "main": "./src/index.js",
7
+ "scripts": {
8
+ "start": "node ./src/index.js"
9
+ },
10
+ "dependencies": {
11
+ "discord.js": "^13.13.1"
12
+ }
13
+ }
@@ -1,26 +1,42 @@
1
- const { Client, Intents } = require('discord.js');
2
- const { token } = require('../config.json');
3
-
4
- // Create a new client instance with Intents that specify which privileged intents your bot requires
5
- const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
6
-
7
-
8
- // Run this code when the client is ready. This event will only trigger one time after logging in
9
- client.once('ready', () => {
10
- console.log(`Bot is logged in as ${client.user.tag}.`);
11
- });
12
-
13
- // Listen for messages
14
- client.on('messageCreate', async message => {
15
- const { content } = message;
16
- // Reply with "Pong!" when someone says "!ping"
17
- if (content === "!ping") {
18
- return await message.reply("Pong!");
19
- }
20
- });
21
-
22
-
23
- // Login to Discord with your app's token
24
- client.login(token);
25
-
26
- // For more information about the Discord.js library, visit https://discord.js.org/#/docs/main/stable/general/welcome
1
+ const { Client, Intents } = require('discord.js');
2
+ const { token } = require('../config.json');
3
+
4
+ // Create a new client instance with Intents that specify which privileged intents your bot requires
5
+ const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
6
+ const prefix = '!';
7
+
8
+ // Run this code when the client is ready. This event will only trigger one time after logging in
9
+ client.once('ready', () => {
10
+ console.log(`Bot is logged in as ${client.user.tag}.`);
11
+ });
12
+
13
+
14
+ // Listen for messages
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
+ }
36
+ });
37
+
38
+
39
+ // Login to Discord with your app's token
40
+ client.login(token);
41
+
42
+ // For more information about the Discord.js library, visit https://discord.js.org/#/docs/main/stable/general/welcome∏
@@ -1,21 +1,21 @@
1
- import discord
2
- from discord.ext import commands
3
-
4
- # Define bot prefix and create bot instance
5
- bot_prefix = "!"
6
- bot = commands.Bot(command_prefix=bot_prefix)
7
-
8
- # Define bot events
9
- @bot.event
10
- async def on_ready():
11
- print(f"Logged in as {bot.user.name} ({bot.user.id})")
12
-
13
- # Define bot commands
14
- @bot.command()
15
- async def ping(ctx):
16
- await ctx.send("Pong!")
17
-
18
- # Run bot with bot token
19
- bot.run("<%= bot-token %>")
20
-
1
+ import discord
2
+ from discord.ext import commands
3
+
4
+ # Define bot prefix and create bot instance
5
+ bot_prefix = "!"
6
+ bot = commands.Bot(command_prefix=bot_prefix)
7
+
8
+ # Define bot events
9
+ @bot.event
10
+ async def on_ready():
11
+ print(f"Logged in as {bot.user.name} ({bot.user.id})")
12
+
13
+ # Define bot commands
14
+ @bot.command()
15
+ async def ping(ctx):
16
+ await ctx.send("Pong!")
17
+
18
+ # Run bot with bot token
19
+ bot.run("<%= bot-token %>")
20
+
21
21
  # For more information on how to use discord.py, visit https://discordpy.readthedocs.io/en/latest/
@@ -1,3 +1,3 @@
1
- {
2
- "token":"<%= bot-token %>"
1
+ {
2
+ "token":"<%= bot-token %>"
3
3
  }
@@ -1,16 +1,16 @@
1
- {
2
- "name": "<%= bot-name %>",
3
- "displayName": "<%= bot-name %>",
4
- "description": "Please enter a brief description here",
5
- "version": "1.0.0",
6
- "main": "./src/index.ts",
7
- "scripts": {
8
- "start": "tsc && node ./dist/src/index.js",
9
- "watch": "tsc -w",
10
- "build": "tsc"
11
- },
12
- "dependencies": {
13
- "discord.js": "^13.13.1",
14
- "typescript": "^4.9.5"
15
- }
16
- }
1
+ {
2
+ "name": "<%= bot-name %>",
3
+ "displayName": "<%= bot-name %>",
4
+ "description": "Please enter a brief description here",
5
+ "version": "1.0.0",
6
+ "main": "./src/index.ts",
7
+ "scripts": {
8
+ "start": "tsc && node ./dist/src/index.js",
9
+ "watch": "tsc -w",
10
+ "build": "tsc"
11
+ },
12
+ "dependencies": {
13
+ "discord.js": "^13.13.1",
14
+ "typescript": "^4.9.5"
15
+ }
16
+ }
@@ -1,27 +1,42 @@
1
- import { Client, Intents } from 'discord.js';
2
- import { token } from '../config.json';
3
-
4
- // Create a new client instance with Intents that specify which privileged intents your bot requires
5
- const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
6
-
7
- // Run this code when the client is ready. This event will only trigger one time after logging in
8
- client.once('ready', () => {
9
- console.log(`Bot is logged in as ${client.user.tag}.`);
10
- });
11
-
12
-
13
- // Listen for messages
14
- client.on('messageCreate', async message => {
15
- const { content } = message;
16
- // Reply with "Pong!" when someone says "!ping"
17
- if (content === "!ping") {
18
- await message.reply("Pong!");
19
- return;
20
- }
21
- });
22
-
23
-
24
- // Login to Discord with your app's token
25
- client.login(token);
26
-
27
- // For more information about the Discord.js library, visit https://discord.js.org/#/docs/main/stable/general/welcome
1
+ import { Client, Intents } from 'discord.js';
2
+ import { token } from '../config.json';
3
+
4
+ // Create a new client instance with Intents that specify which privileged intents your bot requires
5
+ const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
6
+ const prefix = '!';
7
+
8
+ // Run this code when the client is ready. This event will only trigger one time after logging in
9
+ client.once('ready', () => {
10
+ console.log(`Bot is logged in as ${client.user.tag}.`);
11
+ });
12
+
13
+
14
+ // Listen for messages
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
+ }
36
+ });
37
+
38
+
39
+ // Login to Discord with your app's token
40
+ client.login(token);
41
+
42
+ // For more information about the Discord.js library, visit https://discord.js.org/#/docs/main/stable/general/welcome∏
@@ -1,24 +1,24 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES6",
4
- "module": "commonjs",
5
- "lib": ["ESNext"],
6
- "sourceMap": true,
7
- "outDir": "dist",
8
- "strict": false,
9
- "noUnusedLocals": true,
10
- "noImplicitReturns": true,
11
- "moduleResolution": "node",
12
- "esModuleInterop": true,
13
- "skipLibCheck": true,
14
- "resolveJsonModule": true,
15
- "forceConsistentCasingInFileNames": true
16
- },
17
- "include": [
18
- "src/**/*.ts",
19
- ],
20
- "exclude": [
21
- "dist",
22
- "node_modules"
23
- ]
24
- }
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES6",
4
+ "module": "commonjs",
5
+ "lib": ["ESNext"],
6
+ "sourceMap": true,
7
+ "outDir": "dist",
8
+ "strict": false,
9
+ "noUnusedLocals": true,
10
+ "noImplicitReturns": true,
11
+ "moduleResolution": "node",
12
+ "esModuleInterop": true,
13
+ "skipLibCheck": true,
14
+ "resolveJsonModule": true,
15
+ "forceConsistentCasingInFileNames": true
16
+ },
17
+ "include": [
18
+ "src/**/*.ts",
19
+ ],
20
+ "exclude": [
21
+ "dist",
22
+ "node_modules"
23
+ ]
24
+ }