@power-bots/powerbotlibrary 0.0.5 → 0.1.0
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/dist/main.d.ts +6 -4
- package/dist/main.js +34 -23
- package/package.json +1 -1
package/dist/main.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { Collection } from 'discord.js';
|
|
2
1
|
export { db } from "./db";
|
|
3
2
|
export declare class Bot {
|
|
4
3
|
log: any;
|
|
5
4
|
client: any;
|
|
6
|
-
commands:
|
|
7
|
-
commandsArray:
|
|
8
|
-
|
|
5
|
+
commands: any;
|
|
6
|
+
commandsArray: any;
|
|
7
|
+
dirname: any;
|
|
8
|
+
setup(dirname: any): void;
|
|
9
|
+
run(): void;
|
|
9
10
|
}
|
|
11
|
+
export declare const bot: Bot;
|
package/dist/main.js
CHANGED
|
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.Bot = exports.db = void 0;
|
|
15
|
+
exports.bot = exports.Bot = exports.db = void 0;
|
|
16
16
|
// IMPORTS
|
|
17
17
|
const dotenv_1 = __importDefault(require("dotenv"));
|
|
18
18
|
dotenv_1.default.config();
|
|
@@ -24,9 +24,16 @@ const db_1 = require("./db");
|
|
|
24
24
|
var db_2 = require("./db");
|
|
25
25
|
Object.defineProperty(exports, "db", { enumerable: true, get: function () { return db_2.db; } });
|
|
26
26
|
class Bot {
|
|
27
|
-
|
|
27
|
+
setup(dirname) {
|
|
28
|
+
this.dirname = dirname;
|
|
29
|
+
}
|
|
30
|
+
run() {
|
|
31
|
+
if (!this.dirname) {
|
|
32
|
+
this.log.error(`Bot was not setup.`);
|
|
33
|
+
process.exit();
|
|
34
|
+
}
|
|
28
35
|
this.log = new log_1.Log();
|
|
29
|
-
(0, db_1.updateDatabase)(dirname);
|
|
36
|
+
(0, db_1.updateDatabase)(this.dirname);
|
|
30
37
|
this.log.info("Press Control+C to stop the bot");
|
|
31
38
|
// ENVIROMENT VARS
|
|
32
39
|
if (!node_fs_1.default.existsSync(".env")) {
|
|
@@ -49,37 +56,40 @@ class Bot {
|
|
|
49
56
|
// IMPORT COMMANDS
|
|
50
57
|
this.commands = new discord_js_1.Collection();
|
|
51
58
|
this.commandsArray = [];
|
|
52
|
-
const foldersPath = node_path_1.default.join(dirname, 'commands');
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
else {
|
|
61
|
-
commandFiles = [""];
|
|
62
|
-
}
|
|
63
|
-
for (const file of commandFiles) {
|
|
64
|
-
const filePath = node_path_1.default.join(commandsPath, file);
|
|
65
|
-
const command = require(filePath);
|
|
66
|
-
if ('data' in command && 'execute' in command) {
|
|
67
|
-
this.log.info(`"${command.data.name}" command was imported from ${filePath}`);
|
|
68
|
-
this.commands.set(command.data.name, command);
|
|
69
|
-
this.commandsArray.push(command.data.toJSON());
|
|
59
|
+
const foldersPath = node_path_1.default.join(this.dirname, 'commands');
|
|
60
|
+
if (node_fs_1.default.existsSync(foldersPath)) {
|
|
61
|
+
const commandFolders = node_fs_1.default.readdirSync(foldersPath);
|
|
62
|
+
for (const folder of commandFolders) {
|
|
63
|
+
const commandsPath = node_path_1.default.join(foldersPath, folder);
|
|
64
|
+
let commandFiles;
|
|
65
|
+
if (node_fs_1.default.statSync(commandsPath).isDirectory()) {
|
|
66
|
+
commandFiles = node_fs_1.default.readdirSync(commandsPath).filter((file) => file.endsWith('.js'));
|
|
70
67
|
}
|
|
71
68
|
else {
|
|
72
|
-
|
|
69
|
+
commandFiles = [""];
|
|
70
|
+
}
|
|
71
|
+
for (const file of commandFiles) {
|
|
72
|
+
const filePath = node_path_1.default.join(commandsPath, file);
|
|
73
|
+
const command = require(filePath);
|
|
74
|
+
if ('data' in command && 'execute' in command) {
|
|
75
|
+
this.commands.set(command.data.name, command);
|
|
76
|
+
this.commandsArray.push(command.data.toJSON());
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
this.log.warn(`The command at ${filePath} is missing a required "data" or "execute" property.`);
|
|
80
|
+
}
|
|
81
|
+
;
|
|
73
82
|
}
|
|
74
83
|
;
|
|
75
84
|
}
|
|
76
85
|
;
|
|
77
86
|
}
|
|
78
|
-
;
|
|
79
87
|
// LOGIN CLIENT
|
|
80
88
|
this.client.once(discord_js_1.Events.ClientReady, (readyClient) => {
|
|
81
89
|
this.log.info(`Logged in as ${readyClient.user.tag}`);
|
|
82
90
|
// REGISTER COMMANDS
|
|
91
|
+
if (this.commandsArray.length === 0)
|
|
92
|
+
return;
|
|
83
93
|
const rest = new discord_js_1.REST().setToken(botToken);
|
|
84
94
|
(() => __awaiter(this, void 0, void 0, function* () {
|
|
85
95
|
try {
|
|
@@ -127,3 +137,4 @@ class Bot {
|
|
|
127
137
|
}
|
|
128
138
|
}
|
|
129
139
|
exports.Bot = Bot;
|
|
140
|
+
exports.bot = new Bot();
|