@power-bots/powerbotlibrary 0.0.2 → 0.0.4
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 +3 -3
- package/dist/db.d.ts +1 -0
- package/dist/db.js +21 -0
- package/dist/main.d.ts +1 -1
- package/dist/main.js +7 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,13 +6,13 @@ PowerBotsLibrary is the core of all Power Bots and makes up the foundation to sh
|
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
```
|
|
9
|
-
npm install
|
|
9
|
+
npm install @power-bots/powerbotlibrary
|
|
10
10
|
```
|
|
11
11
|
|
|
12
12
|
## Usage
|
|
13
13
|
```typescript
|
|
14
|
-
import { Bot } from "powerbotlibrary"
|
|
15
|
-
import { db } from "powerbotlibrary" // If you want to use database
|
|
14
|
+
import { Bot } from "@power-bots/powerbotlibrary"
|
|
15
|
+
import { db } from "@power-bots/powerbotlibrary" // If you want to use database
|
|
16
16
|
|
|
17
17
|
const bot = new Bot(__dirname)
|
|
18
18
|
```
|
package/dist/db.d.ts
CHANGED
package/dist/db.js
CHANGED
|
@@ -4,7 +4,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.db = void 0;
|
|
7
|
+
exports.updateDatabase = updateDatabase;
|
|
7
8
|
const better_sqlite3_1 = __importDefault(require("better-sqlite3"));
|
|
9
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
10
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
11
|
exports.db = new better_sqlite3_1.default('bot.db');
|
|
9
12
|
exports.db.pragma('journal_mode = WAL');
|
|
10
13
|
exports.db.defaultSafeIntegers();
|
|
14
|
+
function updateDatabase(dirname) {
|
|
15
|
+
const userVersion = parseInt(exports.db.pragma('user_version', { simple: true }));
|
|
16
|
+
const migrateFolder = node_path_1.default.join(dirname, "migrate");
|
|
17
|
+
if (!node_fs_1.default.existsSync(migrateFolder))
|
|
18
|
+
return;
|
|
19
|
+
let updating = true;
|
|
20
|
+
let nextVersion = userVersion;
|
|
21
|
+
while (updating) {
|
|
22
|
+
nextVersion = nextVersion + 1;
|
|
23
|
+
const nextVersionFile = node_path_1.default.join(migrateFolder, `${nextVersion}.sql`);
|
|
24
|
+
if (!node_fs_1.default.existsSync(nextVersionFile)) {
|
|
25
|
+
updating = false;
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
exports.db.exec(node_fs_1.default.readFileSync(nextVersionFile, { encoding: "utf-8" }));
|
|
29
|
+
exports.db.pragma(`user_version = ${nextVersion}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
package/dist/main.d.ts
CHANGED
package/dist/main.js
CHANGED
|
@@ -20,11 +20,13 @@ const node_fs_1 = __importDefault(require("node:fs"));
|
|
|
20
20
|
const node_path_1 = __importDefault(require("node:path"));
|
|
21
21
|
const discord_js_1 = require("discord.js");
|
|
22
22
|
const log_1 = require("./log");
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
const db_1 = require("./db");
|
|
24
|
+
var db_2 = require("./db");
|
|
25
|
+
Object.defineProperty(exports, "db", { enumerable: true, get: function () { return db_2.db; } });
|
|
25
26
|
class Bot {
|
|
26
|
-
constructor(
|
|
27
|
+
constructor(dirname) {
|
|
27
28
|
this.log = new log_1.Log();
|
|
29
|
+
(0, db_1.updateDatabase)(dirname);
|
|
28
30
|
this.log.info("Press Control+C to stop the bot");
|
|
29
31
|
// ENVIROMENT VARS
|
|
30
32
|
if (!node_fs_1.default.existsSync(".env")) {
|
|
@@ -47,7 +49,7 @@ class Bot {
|
|
|
47
49
|
// IMPORT COMMANDS
|
|
48
50
|
let commands = new discord_js_1.Collection();
|
|
49
51
|
let commandsArray = [];
|
|
50
|
-
const foldersPath = node_path_1.default.join(
|
|
52
|
+
const foldersPath = node_path_1.default.join(dirname, 'commands');
|
|
51
53
|
const commandFolders = node_fs_1.default.readdirSync(foldersPath);
|
|
52
54
|
for (const folder of commandFolders) {
|
|
53
55
|
const commandsPath = node_path_1.default.join(foldersPath, folder);
|
|
@@ -110,7 +112,7 @@ class Bot {
|
|
|
110
112
|
}
|
|
111
113
|
catch (error) {
|
|
112
114
|
this.log.error(`${error}`);
|
|
113
|
-
const errorMessage = { content: 'There was an error while executing this command!',
|
|
115
|
+
const errorMessage = { content: 'There was an error while executing this command!', flags: [discord_js_1.MessageFlags.Ephemeral] };
|
|
114
116
|
if (interaction.replied || interaction.deferred) {
|
|
115
117
|
yield interaction.followUp(errorMessage);
|
|
116
118
|
}
|
|
@@ -125,4 +127,3 @@ class Bot {
|
|
|
125
127
|
}
|
|
126
128
|
}
|
|
127
129
|
exports.Bot = Bot;
|
|
128
|
-
log_1.Log.prototype.warn("osdcnf");
|