@power-bots/powerbotlibrary 0.5.1 → 0.5.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/dist/commands/other/config.js +1 -1
- package/dist/{bot.d.ts → lib/bot.d.ts} +5 -0
- package/dist/{bot.js → lib/bot.js} +48 -31
- package/dist/{config.js → lib/config.js} +1 -1
- package/dist/{db.js → lib/db.js} +1 -1
- package/dist/{lang.js → lib/lang.js} +1 -1
- package/dist/main.d.ts +4 -4
- package/dist/main.js +4 -4
- package/package.json +1 -1
- /package/dist/{config.d.ts → lib/config.d.ts} +0 -0
- /package/dist/{db.d.ts → lib/db.d.ts} +0 -0
- /package/dist/{lang.d.ts → lib/lang.d.ts} +0 -0
- /package/dist/{log.d.ts → lib/log.d.ts} +0 -0
- /package/dist/{log.js → lib/log.js} +0 -0
|
@@ -11,7 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
const discord_js_1 = require("discord.js");
|
|
13
13
|
const main_1 = require("../../main");
|
|
14
|
-
const config_1 = require("../../config");
|
|
14
|
+
const config_1 = require("../../lib/config");
|
|
15
15
|
module.exports = {
|
|
16
16
|
data: new discord_js_1.SlashCommandBuilder()
|
|
17
17
|
.setName('config')
|
|
@@ -10,6 +10,11 @@ export declare class Bot {
|
|
|
10
10
|
info: any;
|
|
11
11
|
setup(dirname: any): Promise<void>;
|
|
12
12
|
run(): Promise<void>;
|
|
13
|
+
scanFolder(folder: string): Promise<string[]>;
|
|
14
|
+
importFolder(folder: string, func: Function, requiredData?: string[]): Promise<void>;
|
|
15
|
+
_importFolder(folder: string, func: Function, requiredData?: string[]): Promise<void>;
|
|
16
|
+
commandImporter(command: any): Promise<void>;
|
|
17
|
+
eventImporter(data: any): Promise<void>;
|
|
13
18
|
resolveGuild(guild: Guild | Snowflake): Promise<Guild | null>;
|
|
14
19
|
getGuild(id: Snowflake): Promise<Guild | null>;
|
|
15
20
|
getRole(id: Snowflake, guild: Guild | Snowflake): Promise<Role | null>;
|
|
@@ -26,35 +26,6 @@ Object.defineProperty(exports, "knex", { enumerable: true, get: function () { re
|
|
|
26
26
|
var config_1 = require("./config");
|
|
27
27
|
Object.defineProperty(exports, "Config", { enumerable: true, get: function () { return config_1.Config; } });
|
|
28
28
|
Object.defineProperty(exports, "ConfigTypes", { enumerable: true, get: function () { return config_1.ConfigTypes; } });
|
|
29
|
-
function addCommandsFromPath(bot, foldersPath) {
|
|
30
|
-
if (node_fs_1.default.existsSync(foldersPath)) {
|
|
31
|
-
const commandFolders = node_fs_1.default.readdirSync(foldersPath);
|
|
32
|
-
for (const folder of commandFolders) {
|
|
33
|
-
const commandsPath = node_path_1.default.join(foldersPath, folder);
|
|
34
|
-
let commandFiles;
|
|
35
|
-
if (node_fs_1.default.statSync(commandsPath).isDirectory()) {
|
|
36
|
-
commandFiles = node_fs_1.default.readdirSync(commandsPath).filter((file) => file.endsWith('.js'));
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
commandFiles = [""];
|
|
40
|
-
}
|
|
41
|
-
for (const file of commandFiles) {
|
|
42
|
-
const filePath = node_path_1.default.join(commandsPath, file);
|
|
43
|
-
const command = require(filePath);
|
|
44
|
-
if ('data' in command && 'execute' in command) {
|
|
45
|
-
bot.commands.set(command.data.name, command);
|
|
46
|
-
bot.commandsArray.push(command.data.toJSON());
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
bot.log.warn(`The command at ${filePath} is missing a required "data" or "execute" property.`);
|
|
50
|
-
}
|
|
51
|
-
;
|
|
52
|
-
}
|
|
53
|
-
;
|
|
54
|
-
}
|
|
55
|
-
;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
29
|
class Bot {
|
|
59
30
|
constructor() {
|
|
60
31
|
this.info = {};
|
|
@@ -103,8 +74,8 @@ class Bot {
|
|
|
103
74
|
// IMPORT COMMANDS
|
|
104
75
|
this.commands = new discord_js_1.Collection();
|
|
105
76
|
this.commandsArray = [];
|
|
106
|
-
|
|
107
|
-
|
|
77
|
+
yield this.importFolder('commands', (data) => this.commandImporter(data));
|
|
78
|
+
yield this.importFolder('events', (data) => this.eventImporter(data));
|
|
108
79
|
// LOGIN CLIENT
|
|
109
80
|
this.client.once(discord_js_1.Events.ClientReady, (readyClient) => {
|
|
110
81
|
this.log.info(`Logged in as ${readyClient.user.tag}`);
|
|
@@ -157,6 +128,52 @@ class Bot {
|
|
|
157
128
|
}));
|
|
158
129
|
});
|
|
159
130
|
}
|
|
131
|
+
scanFolder(folder) {
|
|
132
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
133
|
+
let results = [];
|
|
134
|
+
if (node_fs_1.default.existsSync(folder)) {
|
|
135
|
+
const folderContents = node_fs_1.default.readdirSync(folder);
|
|
136
|
+
for (const file of folderContents) {
|
|
137
|
+
const fullPath = node_path_1.default.join(folder, file);
|
|
138
|
+
const stats = node_fs_1.default.lstatSync(fullPath);
|
|
139
|
+
if (stats.isDirectory())
|
|
140
|
+
results.push(...yield this.scanFolder(fullPath));
|
|
141
|
+
if (stats.isFile())
|
|
142
|
+
results.push(fullPath);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return results;
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
importFolder(folder_1, func_1) {
|
|
149
|
+
return __awaiter(this, arguments, void 0, function* (folder, func, requiredData = []) {
|
|
150
|
+
yield this._importFolder(node_path_1.default.join(this.dirname, folder), func, requiredData);
|
|
151
|
+
yield this._importFolder(node_path_1.default.join(__dirname, "..", folder), func, requiredData);
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
_importFolder(folder_1, func_1) {
|
|
155
|
+
return __awaiter(this, arguments, void 0, function* (folder, func, requiredData = []) {
|
|
156
|
+
for (const file of yield this.scanFolder(folder)) {
|
|
157
|
+
const data = require(file);
|
|
158
|
+
for (const required of requiredData)
|
|
159
|
+
if (!data[required])
|
|
160
|
+
continue;
|
|
161
|
+
if (file.endsWith(".js"))
|
|
162
|
+
yield func(data);
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
commandImporter(command) {
|
|
167
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
168
|
+
this.commands.set(command.data.name, command);
|
|
169
|
+
this.commandsArray.push(command.data.toJSON());
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
eventImporter(data) {
|
|
173
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
174
|
+
this.client.on(data.event, data.execute);
|
|
175
|
+
});
|
|
176
|
+
}
|
|
160
177
|
resolveGuild(guild) {
|
|
161
178
|
return __awaiter(this, void 0, void 0, function* () {
|
|
162
179
|
let _guild;
|
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.Config = exports.ConfigTypes = void 0;
|
|
13
|
-
const main_1 = require("
|
|
13
|
+
const main_1 = require("../main");
|
|
14
14
|
var ConfigTypes;
|
|
15
15
|
(function (ConfigTypes) {
|
|
16
16
|
ConfigTypes["Guild"] = "guild";
|
package/dist/{db.js → lib/db.js}
RENAMED
|
@@ -17,7 +17,7 @@ exports.setupDatabase = setupDatabase;
|
|
|
17
17
|
exports.updateDatabase = updateDatabase;
|
|
18
18
|
const node_path_1 = __importDefault(require("node:path"));
|
|
19
19
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
20
|
-
const main_1 = require("
|
|
20
|
+
const main_1 = require("../main");
|
|
21
21
|
let rawDb;
|
|
22
22
|
function setupDatabase() {
|
|
23
23
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -16,7 +16,7 @@ exports.Lang = void 0;
|
|
|
16
16
|
exports.reply = reply;
|
|
17
17
|
const path_1 = __importDefault(require("path"));
|
|
18
18
|
const fs_1 = __importDefault(require("fs"));
|
|
19
|
-
const main_1 = require("
|
|
19
|
+
const main_1 = require("../main");
|
|
20
20
|
const discord_js_1 = require("discord.js");
|
|
21
21
|
function localize(obj, lang, args) {
|
|
22
22
|
return __awaiter(this, void 0, void 0, function* () {
|
package/dist/main.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Bot } from "./bot";
|
|
2
|
-
export { knex } from "./db";
|
|
3
|
-
export { Config, ConfigTypes } from "./config";
|
|
4
|
-
export { Lang, reply } from "./lang";
|
|
1
|
+
import { Bot } from "./lib/bot";
|
|
2
|
+
export { knex } from "./lib/db";
|
|
3
|
+
export { Config, ConfigTypes } from "./lib/config";
|
|
4
|
+
export { Lang, reply } from "./lib/lang";
|
|
5
5
|
export declare const bot: Bot;
|
package/dist/main.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.bot = exports.reply = exports.Lang = exports.ConfigTypes = exports.Config = exports.knex = void 0;
|
|
4
|
-
const bot_1 = require("./bot");
|
|
5
|
-
var db_1 = require("./db");
|
|
4
|
+
const bot_1 = require("./lib/bot");
|
|
5
|
+
var db_1 = require("./lib/db");
|
|
6
6
|
Object.defineProperty(exports, "knex", { enumerable: true, get: function () { return db_1.knex; } });
|
|
7
|
-
var config_1 = require("./config");
|
|
7
|
+
var config_1 = require("./lib/config");
|
|
8
8
|
Object.defineProperty(exports, "Config", { enumerable: true, get: function () { return config_1.Config; } });
|
|
9
9
|
Object.defineProperty(exports, "ConfigTypes", { enumerable: true, get: function () { return config_1.ConfigTypes; } });
|
|
10
|
-
var lang_1 = require("./lang");
|
|
10
|
+
var lang_1 = require("./lib/lang");
|
|
11
11
|
Object.defineProperty(exports, "Lang", { enumerable: true, get: function () { return lang_1.Lang; } });
|
|
12
12
|
Object.defineProperty(exports, "reply", { enumerable: true, get: function () { return lang_1.reply; } });
|
|
13
13
|
exports.bot = new bot_1.Bot();
|
package/package.json
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|