@alexandredeveloper/standalone 0.0.1

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.
@@ -0,0 +1,11 @@
1
+ module.exports = {
2
+ name: "ping",
3
+ execute(client, message) {
4
+ const gatewayPing = Math.round(client.ws.ping);
5
+
6
+ message.reply(
7
+ `⛓️‍💥 Gateway: ${gatewayPing}ms\n` +
8
+ `📎 API: ${Date.now() - message.createdTimestamp}ms`
9
+ );
10
+ }
11
+ };
@@ -0,0 +1,5 @@
1
+ {
2
+ "token": "",
3
+ "prefix": "!",
4
+ "botName": "BotPrefix"
5
+ }
@@ -0,0 +1,20 @@
1
+ const config = require("../config.json");
2
+
3
+ module.exports = {
4
+ name: "messageCreate",
5
+ execute(client, message) {
6
+ if (message.author.bot) return;
7
+ if (!message.content.startsWith(config.prefix)) return;
8
+
9
+ const args = message.content
10
+ .slice(config.prefix.length)
11
+ .trim()
12
+ .split(/ +/);
13
+
14
+ const commandName = args.shift().toLowerCase();
15
+ const command = client.commands.get(commandName);
16
+ if (!command) return;
17
+
18
+ command.execute(client, message, args);
19
+ }
20
+ };
@@ -0,0 +1,6 @@
1
+ module.exports = {
2
+ name: "ready",
3
+ execute(client) {
4
+ console.log(`( ⛓️‍💥 ) ${client.user.tag} | Powered by Standalone`);
5
+ }
6
+ };
@@ -0,0 +1,32 @@
1
+ const { Client, GatewayIntentBits, Collection } = require("discord.js");
2
+ const fs = require("fs");
3
+ const path = require("path");
4
+ const config = require("./config.json");
5
+
6
+ const client = new Client({
7
+ intents: [
8
+ GatewayIntentBits.Guilds,
9
+ GatewayIntentBits.GuildMessages,
10
+ GatewayIntentBits.MessageContent
11
+ ]
12
+ });
13
+
14
+ client.commands = new Collection();
15
+
16
+ /* ===== LOAD COMMANDS ===== */
17
+ const commandsPath = path.join(__dirname, "commands");
18
+ for (const file of fs.readdirSync(commandsPath)) {
19
+ if (!file.endsWith(".js")) continue;
20
+ const command = require(`./commands/${file}`);
21
+ client.commands.set(command.name, command);
22
+ }
23
+
24
+ /* ===== LOAD EVENTS ===== */
25
+ const eventsPath = path.join(__dirname, "events");
26
+ for (const file of fs.readdirSync(eventsPath)) {
27
+ if (!file.endsWith(".js")) continue;
28
+ const event = require(`./events/${file}`);
29
+ client.on(event.name, (...args) => event.execute(client, ...args));
30
+ }
31
+
32
+ client.login(config.token);
@@ -0,0 +1,8 @@
1
+ {
2
+ "name": "STA-base",
3
+ "version": "1.0.0",
4
+ "main": "index.js",
5
+ "scripts": {
6
+ "start": "node index.js"
7
+ }
8
+ }
@@ -0,0 +1,16 @@
1
+ const { SlashCommandBuilder } = require("discord.js");
2
+
3
+ module.exports = {
4
+ data: new SlashCommandBuilder()
5
+ .setName("ping")
6
+ .setDescription("[UTIL] Check the application latency. "),
7
+
8
+ async execute(client, interaction) {
9
+ const gatewayPing = Math.round(client.ws.ping);
10
+
11
+ await interaction.reply(
12
+ `⛓️‍💥 Gateway: ${gatewayPing}ms\n` +
13
+ `📎 API: ${Date.now() - interaction.createdTimestamp}ms`
14
+ );
15
+ }
16
+ };
@@ -0,0 +1,4 @@
1
+ {
2
+ "token": "",
3
+ "botName": "BotSlash"
4
+ }
@@ -0,0 +1,20 @@
1
+ module.exports = {
2
+ name: "interactionCreate",
3
+ async execute(client, interaction) {
4
+ if (!interaction.isChatInputCommand()) return;
5
+
6
+ const command = client.commands.get(interaction.commandName);
7
+ if (!command) return;
8
+
9
+ try {
10
+ await command.execute(client, interaction);
11
+ } catch (err) {
12
+ console.error(err);
13
+ if (interaction.replied || interaction.deferred) {
14
+ interaction.followUp({ content: "An error occurred while executing. ", ephemeral: true });
15
+ } else {
16
+ interaction.reply({ content: "An error occurred while executing. ", ephemeral: true });
17
+ }
18
+ }
19
+ }
20
+ };
@@ -0,0 +1,6 @@
1
+ module.exports = {
2
+ name: "ready",
3
+ execute(client) {
4
+ console.log(`( ⛓️‍💥 ) ${client.user.tag} | Powered by Standalone`);
5
+ }
6
+ };
@@ -0,0 +1,47 @@
1
+ const { Client, GatewayIntentBits, Collection, REST, Routes } = require("discord.js");
2
+ const fs = require("fs");
3
+ const path = require("path");
4
+ const config = require("./config.json");
5
+
6
+ const client = new Client({
7
+ intents: [GatewayIntentBits.Guilds]
8
+ });
9
+
10
+ client.commands = new Collection();
11
+
12
+ /* ===== LOAD COMMANDS ===== */
13
+ const commandsPath = path.join(__dirname, "commands");
14
+ const slashData = [];
15
+
16
+ for (const file of fs.readdirSync(commandsPath)) {
17
+ if (!file.endsWith(".js")) continue;
18
+
19
+ const command = require(`./commands/${file}`);
20
+ client.commands.set(command.data.name, command);
21
+ slashData.push(command.data.toJSON());
22
+ }
23
+
24
+ /* ===== LOAD EVENTS ===== */
25
+ const eventsPath = path.join(__dirname, "events");
26
+ for (const file of fs.readdirSync(eventsPath)) {
27
+ if (!file.endsWith(".js")) continue;
28
+
29
+ const event = require(`./events/${file}`);
30
+ client.on(event.name, (...args) => event.execute(client, ...args));
31
+ }
32
+
33
+ /* ===== REGISTER SLASH COMMANDS ===== */
34
+ client.once("ready", async () => {
35
+ const rest = new REST({ version: "10" }).setToken(config.token);
36
+
37
+ try {
38
+ await rest.put(
39
+ Routes.applicationCommands(client.user.id),
40
+ { body: slashData }
41
+ );
42
+ } catch (err) {
43
+ console.error(err);
44
+ }
45
+ });
46
+
47
+ client.login(config.token);
@@ -0,0 +1,8 @@
1
+ {
2
+ "name": "discord-slash-bot",
3
+ "version": "1.0.0",
4
+ "main": "index.js",
5
+ "scripts": {
6
+ "start": "node index.js"
7
+ }
8
+ }
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env node
2
+ const log = require("../src/logger");
3
+ const { runPrompt } = require("../src/prompt");
4
+ const { buildBot } = require("../src/builder");
5
+
6
+ const args = process.argv.slice(2);
7
+
8
+ if (!args.includes("--build")) {
9
+ log.warn("Use: standalone --build");
10
+ process.exit(0);
11
+ }
12
+
13
+ (async () => {
14
+ log.sta("Standalone builder started");
15
+ const answers = await runPrompt();
16
+ await buildBot(answers);
17
+ })();
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@alexandredeveloper/standalone",
3
+ "version": "0.0.1",
4
+ "description": "Standalone — CLI para criar bots Discord automaticamente",
5
+ "type": "commonjs",
6
+ "main": "src/builder.js",
7
+ "bin": {
8
+ "standalone": "bin/standalone.js"
9
+ },
10
+ "scripts": {
11
+ "build": "node bin/standalone.js --build"
12
+ },
13
+ "keywords": [
14
+ "discord",
15
+ "bot",
16
+ "cli",
17
+ "standalone",
18
+ "generator"
19
+ ],
20
+ "author": "Alexandre Developer",
21
+ "license": "MIT",
22
+ "dependencies": {
23
+ "inquirer": "^8.2.6",
24
+ "chalk": "^4.1.2",
25
+ "fs-extra": "^11.2.0"
26
+ },
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "engines": {
31
+ "node": ">=18"
32
+ }
33
+ }
package/src/builder.js ADDED
@@ -0,0 +1,38 @@
1
+ const fs = require("fs-extra");
2
+ const path = require("path");
3
+ const log = require("./logger");
4
+ const { installDeps, startBot } = require("./installer");
5
+
6
+ async function buildBot({ token, botName, mode }) {
7
+ const isSlash = mode.toLowerCase() === "sl";
8
+ const base = isSlash ? "slash" : "prefix";
9
+
10
+ const basePath = path.join(__dirname, "..", "Bases", base);
11
+ const targetPath = path.join(process.cwd(), botName);
12
+
13
+ if (fs.existsSync(targetPath)) {
14
+ return log.err("Folder already exists");
15
+ }
16
+
17
+ log.wait("Creating bot structure");
18
+ await fs.copy(basePath, targetPath);
19
+
20
+ const configPath = path.join(targetPath, "config.json");
21
+ const config = await fs.readJson(configPath);
22
+
23
+ config.token = token;
24
+ config.botName = botName;
25
+ if (!isSlash) config.prefix = mode;
26
+
27
+ await fs.writeJson(configPath, config, { spaces: 2 });
28
+ log.ok("Configuration saved");
29
+
30
+ log.wait("Installing discord.js");
31
+ await installDeps(targetPath);
32
+
33
+ log.ok("Bot ready");
34
+ log.sta("Starting bot");
35
+ startBot(targetPath);
36
+ }
37
+
38
+ module.exports = { buildBot };
@@ -0,0 +1,19 @@
1
+ const { exec } = require("child_process");
2
+ const log = require("./logger");
3
+
4
+ function installDeps(dir) {
5
+ return new Promise((resolve, reject) => {
6
+ exec("npm install discord.js", { cwd: dir }, err => {
7
+ if (err) {
8
+ log.err("Dependency installation failed");
9
+ reject(err);
10
+ } else resolve();
11
+ });
12
+ });
13
+ }
14
+
15
+ function startBot(dir) {
16
+ exec("npm start", { cwd: dir, stdio: "inherit" });
17
+ }
18
+
19
+ module.exports = { installDeps, startBot };
package/src/logger.js ADDED
@@ -0,0 +1,11 @@
1
+ function tag(symbol) {
2
+ return `( ${symbol} )`;
3
+ }
4
+
5
+ module.exports = {
6
+ sta: msg => console.log(`${tag("⛓️‍💥")} ${msg}`),
7
+ ok: msg => console.log(`${tag("✔")} ${msg}`),
8
+ warn: msg => console.log(`${tag("⚠")} ${msg}`),
9
+ err: msg => console.log(`${tag("✖")} ${msg}`),
10
+ wait: msg => console.log(`${tag("⏳")} ${msg}`)
11
+ };
package/src/prompt.js ADDED
@@ -0,0 +1,23 @@
1
+ const inquirer = require("inquirer");
2
+
3
+ async function runPrompt() {
4
+ return inquirer.prompt([
5
+ {
6
+ name: "token",
7
+ message: "( ⛓️‍💥 ) Please tell me your Discord bot token",
8
+ type: "password",
9
+ mask: "*"
10
+ },
11
+ {
12
+ name: "botName",
13
+ message: "( ⛓️‍💥 ) What's your bot's name?"
14
+ },
15
+ {
16
+ name: "mode",
17
+ message:
18
+ "( ⛓️‍💥 ) Prefix or SlashCommands? (type prefix | SL)"
19
+ }
20
+ ]);
21
+ }
22
+
23
+ module.exports = { runPrompt };