@power-bots/powerbotlibrary 0.0.3 → 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/dist/db.d.ts +1 -0
- package/dist/db.js +21 -0
- package/dist/main.d.ts +1 -1
- package/dist/main.js +6 -4
- package/package.json +1 -1
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);
|