generator-discord 1.2.0 → 1.2.2

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 ADDED
@@ -0,0 +1,10 @@
1
+ import Generator from 'yeoman-generator';
2
+ export default class DiscordGenerator extends Generator {
3
+ private answers;
4
+ constructor(args: string | string[], options: Generator.GeneratorOptions);
5
+ prompting(): Promise<void>;
6
+ logo(): void;
7
+ writing(): void;
8
+ install(): Promise<void>;
9
+ end(): Promise<void>;
10
+ }
package/app/index.js ADDED
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const yeoman_generator_1 = __importDefault(require("yeoman-generator"));
16
+ const path_1 = __importDefault(require("path"));
17
+ const TEMPLATE_DIR = '../templates/';
18
+ const USER_DIR = '.';
19
+ const OPEN = '<%= ';
20
+ const CLOSE = ' %>';
21
+ const BOT_NAME = 'bot-name';
22
+ const BOT_TOKEN = 'bot-token';
23
+ class DiscordGenerator extends yeoman_generator_1.default {
24
+ constructor(args, options) {
25
+ super(args, options);
26
+ }
27
+ prompting() {
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ this.logo();
30
+ this.answers = yield this.prompt([
31
+ {
32
+ type: 'input',
33
+ name: 'botName',
34
+ message: 'Your Discord Bot name:',
35
+ default: 'my-bot',
36
+ validate: (input) => new RegExp("^(?:@[a-z0-9-*~][a-z0-9-*._~]*/)?[a-z0-9-~][a-z0-9-._~]*$").test(input)
37
+ ? true
38
+ : 'Invalid bot name. Please use only lowercase letters, numbers, and hyphens. Must start with a letter.'
39
+ },
40
+ {
41
+ type: 'list',
42
+ name: 'botType',
43
+ message: 'The type of Discord Bot you want to create.',
44
+ choices: [
45
+ {
46
+ name: 'New Discord Bot (TypeScript)',
47
+ value: 'typescript'
48
+ },
49
+ {
50
+ name: 'New Discord Bot (JavaScript)',
51
+ value: 'javascript'
52
+ },
53
+ {
54
+ name: 'New Discord Bot (Python)',
55
+ value: 'python'
56
+ }
57
+ ]
58
+ },
59
+ {
60
+ type: 'input',
61
+ name: 'botToken',
62
+ message: 'Your Discord Bot Token. (Enter to leave blank)',
63
+ default: 'your-bot-token'
64
+ }
65
+ ]);
66
+ });
67
+ }
68
+ logo() {
69
+ this.log(" \x1b[36m_____ _ _ \x1b[31m_ ");
70
+ this.log(" \x1b[36m| __ \\(_) | | \x1b[31m(_) ");
71
+ this.log(" \x1b[36m| | | |_ ___ ___ ___ _ __ __| | \x1b[33m_ ___ ");
72
+ this.log(" \x1b[36m| | | | / __|/ __/ _ \\| '__/ _` | \x1b[33m| / __|");
73
+ this.log(" \x1b[36m| |__| | \\__ \\ (_| (_) | | | (_| |\x1b[37m_\x1b[32m| \\__ \\");
74
+ this.log(" \x1b[36m|_____/|_|___/\\___\\___/|_| \\__,_\x1b[37m(_) \x1b[32m|___/");
75
+ this.log(" \x1b[34m_/ | ");
76
+ this.log(" \x1b[35m|__/ ");
77
+ this.log("\x1b[0m");
78
+ }
79
+ writing() {
80
+ this.sourceRoot(path_1.default.join(__dirname, TEMPLATE_DIR + this.answers.botType));
81
+ ['.'].forEach((path) => {
82
+ const replaceWords = (answers, content) => [
83
+ [BOT_NAME, this.answers.botName],
84
+ [BOT_TOKEN, this.answers.botToken]
85
+ ].reduce((acc, [templateWord, userAnswer]) => acc.replace(new RegExp(`${OPEN}${templateWord}${CLOSE}`, 'g'), userAnswer), content.toString());
86
+ this.fs.copy(this.templatePath(path), this.destinationPath(USER_DIR, this.answers.botName, path), {
87
+ process: (content) => replaceWords(this.answers, content)
88
+ });
89
+ });
90
+ }
91
+ install() {
92
+ return __awaiter(this, void 0, void 0, function* () {
93
+ this.log('');
94
+ if (this.answers.botType === 'typescript' || this.answers.botType === 'javascript') {
95
+ const options = { cwd: this.destinationPath(USER_DIR, this.answers.botName) };
96
+ this.spawnCommandSync('npm', ['install'], options);
97
+ if (this.answers.botType === 'typescript') {
98
+ this.spawnCommandSync('npm', ['run', 'build'], options);
99
+ }
100
+ }
101
+ this.log('Your Discord Bot ' + this.answers.botName + ' has been created!');
102
+ });
103
+ }
104
+ end() {
105
+ return __awaiter(this, void 0, void 0, function* () {
106
+ const answer = yield this.prompt({
107
+ type: 'list',
108
+ name: 'openWithCode',
109
+ message: 'Do you want to open your Discord Bot with Visual Studio Code?',
110
+ choices: [
111
+ {
112
+ name: 'open with `code`',
113
+ value: true
114
+ },
115
+ {
116
+ name: 'skip',
117
+ value: false
118
+ }
119
+ ]
120
+ });
121
+ this.log('');
122
+ if (answer && answer.openWithCode) {
123
+ this.spawnCommand('code', [this.destinationPath(USER_DIR, this.answers.botName)]);
124
+ }
125
+ });
126
+ }
127
+ }
128
+ exports.default = DiscordGenerator;
129
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,wEAAyC;AACzC,gDAAwB;AAGxB,MAAM,YAAY,GAAG,eAAe,CAAC;AACrC,MAAM,QAAQ,GAAG,GAAG,CAAC;AAErB,MAAM,IAAI,GAAG,MAAM,CAAC;AACpB,MAAM,KAAK,GAAG,KAAK,CAAC;AAEpB,MAAM,QAAQ,GAAG,UAAU,CAAC;AAC5B,MAAM,SAAS,GAAG,WA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IC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "generator-discord",
3
3
  "displayName": "Generator-Discord",
4
- "version": "1.2.0",
4
+ "version": "1.2.2",
5
5
  "main": "./app/index.js",
6
6
  "description": "Yeoman generator for Discord.js",
7
7
  "keywords": [
@@ -14,7 +14,8 @@
14
14
  "build": "tsc",
15
15
  "watch": "tsc -w",
16
16
  "test": "vitest run",
17
- "debug": "npx --node-arg=--inspect yo discord"
17
+ "debug": "npx --node-arg=--inspect yo discord",
18
+ "clean": "npx rimraf app && npx rimraf node_modules"
18
19
  },
19
20
  "files": [
20
21
  "app",
@@ -34,14 +35,12 @@
34
35
  },
35
36
  "homepage": "https://github.com/emilkrebs/Generator-Discord",
36
37
  "dependencies": {
37
- "typescript": "^4.7.2",
38
- "yeoman-generator": "^5.6.1"
38
+ "typescript": "^5.1.6",
39
+ "yeoman-generator": "^5.9.0"
39
40
  },
40
41
  "devDependencies": {
41
- "@types/yeoman-generator": "^5.2.10",
42
- "@types/yeoman-test": "~4.0.3",
43
- "yeoman-test": "~7.3.0",
44
- "dotenv": "^16.0.3",
45
- "vitest": "^0.29.2"
42
+ "dotenv": "^16.3.1",
43
+ "vitest": "^0.34.1",
44
+ "yeoman-test": "^7.4.0"
46
45
  }
47
46
  }
@@ -1,21 +1,20 @@
1
1
  import discord
2
- from discord.ext import commands
3
2
 
4
- # Define bot prefix and create bot instance
5
- bot_prefix = "!"
6
- bot = commands.Bot(command_prefix=bot_prefix)
3
+ intents = discord.Intents.default()
4
+ intents.message_content = True
7
5
 
8
- # Define bot events
9
- @bot.event
6
+ client = discord.Client(intents=intents)
7
+
8
+ @client.event
10
9
  async def on_ready():
11
- print(f"Logged in as {bot.user.name} ({bot.user.id})")
10
+ print(f'Bot is logged in as {client.user}')
12
11
 
13
- # Define bot commands
14
- @bot.command()
15
- async def ping(ctx):
16
- await ctx.send("Pong!")
12
+ @client.event
13
+ async def on_message(message):
14
+ if message.author == client.user:
15
+ return
17
16
 
18
- # Run bot with bot token
19
- bot.run("<%= bot-token %>")
17
+ if message.content.startswith('!ping'):
18
+ await message.channel.send('Pong!')
20
19
 
21
- # For more information on how to use discord.py, visit https://discordpy.readthedocs.io/en/latest/
20
+ client.run('<%= bot-token %>')
@@ -57,23 +57,22 @@ const CONFIG_JSON_EXPECTED = normilizeEOL(`{
57
57
  }`);
58
58
 
59
59
  const BOT_PY_EXPECTED = normilizeEOL(`import discord
60
- from discord.ext import commands
61
60
 
62
- # Define bot prefix and create bot instance
63
- bot_prefix = "!"
64
- bot = commands.Bot(command_prefix=bot_prefix)
61
+ intents = discord.Intents.default()
62
+ intents.message_content = True
65
63
 
66
- # Define bot events
67
- @bot.event
64
+ client = discord.Client(intents=intents)
65
+
66
+ @client.event
68
67
  async def on_ready():
69
- print(f"Logged in as {bot.user.name} ({bot.user.id})")
68
+ print(f'Bot is logged in as {client.user}')
70
69
 
71
- # Define bot commands
72
- @bot.command()
73
- async def ping(ctx):
74
- await ctx.send("Pong!")
70
+ @client.event
71
+ async def on_message(message):
72
+ if message.author == client.user:
73
+ return
75
74
 
76
- # Run bot with bot token
77
- bot.run("xxxx")
75
+ if message.content.startswith('!ping'):
76
+ await message.channel.send('Pong!')
78
77
 
79
- # For more information on how to use discord.py, visit https://discordpy.readthedocs.io/en/latest/`);
78
+ client.run('xxxx')`);