@power-bots/powerbotlibrary 0.0.3 → 0.0.5
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 +4 -1
- package/dist/main.js +13 -11
- 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")) {
|
|
@@ -45,9 +47,9 @@ class Bot {
|
|
|
45
47
|
discord_js_1.GatewayIntentBits.MessageContent
|
|
46
48
|
] });
|
|
47
49
|
// IMPORT COMMANDS
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const foldersPath = node_path_1.default.join(
|
|
50
|
+
this.commands = new discord_js_1.Collection();
|
|
51
|
+
this.commandsArray = [];
|
|
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);
|
|
@@ -63,8 +65,8 @@ class Bot {
|
|
|
63
65
|
const command = require(filePath);
|
|
64
66
|
if ('data' in command && 'execute' in command) {
|
|
65
67
|
this.log.info(`"${command.data.name}" command was imported from ${filePath}`);
|
|
66
|
-
commands.set(command.data.name, command);
|
|
67
|
-
commandsArray.push(command.data.toJSON());
|
|
68
|
+
this.commands.set(command.data.name, command);
|
|
69
|
+
this.commandsArray.push(command.data.toJSON());
|
|
68
70
|
}
|
|
69
71
|
else {
|
|
70
72
|
this.log.warn(`The command at ${filePath} is missing a required "data" or "execute" property.`);
|
|
@@ -81,8 +83,8 @@ class Bot {
|
|
|
81
83
|
const rest = new discord_js_1.REST().setToken(botToken);
|
|
82
84
|
(() => __awaiter(this, void 0, void 0, function* () {
|
|
83
85
|
try {
|
|
84
|
-
this.log.info(`Started refreshing ${commandsArray.length} application (/) commands.`);
|
|
85
|
-
const data = yield rest.put(discord_js_1.Routes.applicationCommands(readyClient.user.id), { body: commandsArray });
|
|
86
|
+
this.log.info(`Started refreshing ${this.commandsArray.length} application (/) commands.`);
|
|
87
|
+
const data = yield rest.put(discord_js_1.Routes.applicationCommands(readyClient.user.id), { body: this.commandsArray });
|
|
86
88
|
this.log.info(`Successfully reloaded ${data.length} application (/) commands.`);
|
|
87
89
|
}
|
|
88
90
|
catch (error) {
|
|
@@ -97,7 +99,7 @@ class Bot {
|
|
|
97
99
|
this.client.on(discord_js_1.Events.InteractionCreate, (interaction) => __awaiter(this, void 0, void 0, function* () {
|
|
98
100
|
try {
|
|
99
101
|
if (interaction.isChatInputCommand()) {
|
|
100
|
-
const command = commands.get(interaction.commandName);
|
|
102
|
+
const command = this.commands.get(interaction.commandName);
|
|
101
103
|
if (!command) {
|
|
102
104
|
this.log.error(`No command matching ${interaction.commandName} was found.`);
|
|
103
105
|
return;
|