@power-bots/powerbotlibrary 0.2.0 → 0.3.0
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/config.d.ts +10 -0
- package/dist/config.js +61 -0
- package/dist/db.js +2 -1
- package/dist/main.d.ts +2 -1
- package/dist/main.js +4 -2
- package/package.json +1 -1
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Snowflake } from "discord.js";
|
|
2
|
+
export declare enum ConfigTypes {
|
|
3
|
+
Guild = "guild",
|
|
4
|
+
User = "user"
|
|
5
|
+
}
|
|
6
|
+
export declare class Config {
|
|
7
|
+
static getRaw(scope: ConfigTypes, id: Snowflake | string | number, key: string): Promise<any>;
|
|
8
|
+
static get(scope: ConfigTypes, id: Snowflake | string | number, key: string): Promise<any>;
|
|
9
|
+
static set(scope: ConfigTypes, id: Snowflake | string | number, key: string, value: string): Promise<void>;
|
|
10
|
+
}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Config = exports.ConfigTypes = void 0;
|
|
13
|
+
const main_1 = require("./main");
|
|
14
|
+
var ConfigTypes;
|
|
15
|
+
(function (ConfigTypes) {
|
|
16
|
+
ConfigTypes["Guild"] = "guild";
|
|
17
|
+
ConfigTypes["User"] = "user";
|
|
18
|
+
})(ConfigTypes || (exports.ConfigTypes = ConfigTypes = {}));
|
|
19
|
+
class Config {
|
|
20
|
+
static getRaw(scope, id, key) {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
const valueRaw = yield (0, main_1.knex)("config").where({
|
|
23
|
+
scope: scope,
|
|
24
|
+
id: id,
|
|
25
|
+
key: key
|
|
26
|
+
}).first();
|
|
27
|
+
return valueRaw;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
static get(scope, id, key) {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
const valueRaw = yield this.getRaw(scope, id, key);
|
|
33
|
+
const value = valueRaw === null || valueRaw === void 0 ? void 0 : valueRaw.value;
|
|
34
|
+
if (!value)
|
|
35
|
+
return null;
|
|
36
|
+
return value;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
static set(scope, id, key, value) {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
const valueRaw = yield this.getRaw(scope, id, key);
|
|
42
|
+
if (valueRaw) {
|
|
43
|
+
yield (0, main_1.knex)("config").where({
|
|
44
|
+
scope: scope,
|
|
45
|
+
id: id,
|
|
46
|
+
key: key
|
|
47
|
+
}).update({
|
|
48
|
+
value: value
|
|
49
|
+
});
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
yield (0, main_1.knex)("config").insert({
|
|
53
|
+
scope: scope,
|
|
54
|
+
id: id,
|
|
55
|
+
key: key,
|
|
56
|
+
value: value
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.Config = Config;
|
package/dist/db.js
CHANGED
|
@@ -18,6 +18,7 @@ exports.updateDatabase = updateDatabase;
|
|
|
18
18
|
const node_path_1 = __importDefault(require("node:path"));
|
|
19
19
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
20
20
|
const main_1 = require("./main");
|
|
21
|
+
let rawDb;
|
|
21
22
|
function setupDatabase() {
|
|
22
23
|
return __awaiter(this, void 0, void 0, function* () {
|
|
23
24
|
exports.knex = require("knex")({
|
|
@@ -28,6 +29,7 @@ function setupDatabase() {
|
|
|
28
29
|
useNullAsDefault: true,
|
|
29
30
|
pool: {
|
|
30
31
|
afterCreate: (conn, done) => {
|
|
32
|
+
rawDb = conn;
|
|
31
33
|
conn.pragma('journal_mode = WAL');
|
|
32
34
|
done(null, conn);
|
|
33
35
|
}
|
|
@@ -43,7 +45,6 @@ function updateDatabase() {
|
|
|
43
45
|
return;
|
|
44
46
|
let updating = true;
|
|
45
47
|
let nextVersion = userVersion;
|
|
46
|
-
const rawDb = yield exports.knex.client.acquireConnection();
|
|
47
48
|
while (updating) {
|
|
48
49
|
nextVersion = nextVersion + 1;
|
|
49
50
|
const nextVersionFile = node_path_1.default.join(migrateFolder, `${nextVersion}.sql`);
|
package/dist/main.d.ts
CHANGED
package/dist/main.js
CHANGED
|
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.bot = exports.
|
|
15
|
+
exports.bot = exports.ConfigTypes = exports.Config = exports.knex = void 0;
|
|
16
16
|
// IMPORTS
|
|
17
17
|
const dotenv_1 = __importDefault(require("dotenv"));
|
|
18
18
|
dotenv_1.default.config();
|
|
@@ -23,6 +23,9 @@ const log_1 = require("./log");
|
|
|
23
23
|
const db_1 = require("./db");
|
|
24
24
|
var db_2 = require("./db");
|
|
25
25
|
Object.defineProperty(exports, "knex", { enumerable: true, get: function () { return db_2.knex; } });
|
|
26
|
+
var config_1 = require("./config");
|
|
27
|
+
Object.defineProperty(exports, "Config", { enumerable: true, get: function () { return config_1.Config; } });
|
|
28
|
+
Object.defineProperty(exports, "ConfigTypes", { enumerable: true, get: function () { return config_1.ConfigTypes; } });
|
|
26
29
|
class Bot {
|
|
27
30
|
setup(dirname) {
|
|
28
31
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -141,5 +144,4 @@ class Bot {
|
|
|
141
144
|
});
|
|
142
145
|
}
|
|
143
146
|
}
|
|
144
|
-
exports.Bot = Bot;
|
|
145
147
|
exports.bot = new Bot();
|