@power-bots/powerbotlibrary 0.5.0 → 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/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  <div align="center">
2
- <img width="125" alt="PowerBots" src="https://github.com/user-attachments/assets/9182c539-a992-407c-9ce5-df2cf7d93baf" />
2
+ <img width="125" alt="PowerBots" src="https://github.com/user-attachments/assets/0c231b99-1dbc-4a5e-b748-ca6da49c59df" />
3
3
  <h1>PowerBotsLibrary</h1>
4
4
  </div>
5
5
  PowerBotsLibrary is the core of all Power Bots and makes up the foundation to share code.
@@ -18,4 +18,4 @@ bot.setup(__dirname)
18
18
  bot.run()
19
19
  ```
20
20
 
21
- More documentation will be available soon.
21
+ There is ***some*** documnetation [here](https://github.com/Power-Bots/PowerBotLibrary/wiki)
@@ -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')
@@ -45,6 +45,8 @@ module.exports = {
45
45
  let id;
46
46
  switch (scope) {
47
47
  case config_1.ConfigTypes.Guild:
48
+ if (!interaction.memberPermissions.has(discord_js_1.PermissionFlagsBits.ManageGuild))
49
+ return yield interaction.reply({ content: "❌ `Manage Server` permission required" });
48
50
  id = interaction.guildId;
49
51
  break;
50
52
  case config_1.ConfigTypes.User:
@@ -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
- addCommandsFromPath(this, node_path_1.default.join(this.dirname, 'commands'));
107
- addCommandsFromPath(this, node_path_1.default.join(__dirname, 'commands'));
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("./main");
13
+ const main_1 = require("../main");
14
14
  var ConfigTypes;
15
15
  (function (ConfigTypes) {
16
16
  ConfigTypes["Guild"] = "guild";
@@ -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("./main");
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("./main");
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@power-bots/powerbotlibrary",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "main": "dist/main.js",
5
5
  "types": "dist/main.d.ts",
6
6
  "dependencies": {
File without changes
File without changes
File without changes
File without changes
File without changes