@power-bots/powerbotlibrary 0.5.4 → 0.5.6
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/commands/other/info.js +0 -3
- package/dist/lib/lang.d.ts +1 -0
- package/dist/lib/lang.js +19 -8
- package/package.json +1 -1
|
@@ -18,8 +18,6 @@ module.exports = {
|
|
|
18
18
|
execute(interaction) {
|
|
19
19
|
return __awaiter(this, void 0, void 0, function* () {
|
|
20
20
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
21
|
-
main_1.bot.log.info("hello");
|
|
22
|
-
main_1.bot.log.info(main_1.bot.info);
|
|
23
21
|
let embed = new discord_js_1.EmbedBuilder()
|
|
24
22
|
.setTitle((_b = (_a = main_1.bot.info) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : null)
|
|
25
23
|
.setThumbnail((_d = (_c = main_1.bot.info) === null || _c === void 0 ? void 0 : _c.icon) !== null && _d !== void 0 ? _d : "")
|
|
@@ -27,7 +25,6 @@ module.exports = {
|
|
|
27
25
|
.addFields({
|
|
28
26
|
name: "Repository", value: (_h = (_g = main_1.bot.info) === null || _g === void 0 ? void 0 : _g.repo) !== null && _h !== void 0 ? _h : "undefined"
|
|
29
27
|
});
|
|
30
|
-
main_1.bot.log.info(embed.toJSON());
|
|
31
28
|
yield interaction.reply({ embeds: [embed] });
|
|
32
29
|
});
|
|
33
30
|
},
|
package/dist/lib/lang.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { CommandInteraction } from "discord.js";
|
|
|
2
2
|
export declare function reply(interaction: CommandInteraction, text: string, args?: Record<string, any>): Promise<void>;
|
|
3
3
|
export declare class Lang {
|
|
4
4
|
texts: any;
|
|
5
|
+
static global: Lang;
|
|
5
6
|
static en: Lang;
|
|
6
7
|
static embed: Lang;
|
|
7
8
|
constructor(lang: string);
|
package/dist/lib/lang.js
CHANGED
|
@@ -21,8 +21,16 @@ const discord_js_1 = require("discord.js");
|
|
|
21
21
|
function localize(obj, lang, args) {
|
|
22
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
23
23
|
if (typeof obj === "string") {
|
|
24
|
-
if (obj.startsWith("$"))
|
|
25
|
-
|
|
24
|
+
if (obj.startsWith("$")) {
|
|
25
|
+
const spaceIndex = obj.indexOf(" ");
|
|
26
|
+
const endIndex = spaceIndex === -1 ? obj.length : spaceIndex;
|
|
27
|
+
const keyPart = obj.slice(0, endIndex);
|
|
28
|
+
const key = keyPart.slice(1);
|
|
29
|
+
const replacement = yield lang.get(key, args);
|
|
30
|
+
if (replacement !== undefined) {
|
|
31
|
+
return obj.replace(keyPart, replacement);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
26
34
|
return obj;
|
|
27
35
|
}
|
|
28
36
|
if (Array.isArray(obj)) {
|
|
@@ -51,26 +59,26 @@ function reply(interaction, text, args) {
|
|
|
51
59
|
let flags = [];
|
|
52
60
|
if ((_a = embed === null || embed === void 0 ? void 0 : embed.options) === null || _a === void 0 ? void 0 : _a.ephemeral)
|
|
53
61
|
flags.push(discord_js_1.MessageFlags.Ephemeral);
|
|
54
|
-
|
|
62
|
+
var newEmbed = yield localize(embed, Lang.en, args);
|
|
63
|
+
var newEmbed = yield localize(newEmbed, Lang.global, args);
|
|
55
64
|
yield interaction.reply({ embeds: [newEmbed], flags: flags });
|
|
56
65
|
});
|
|
57
66
|
}
|
|
58
67
|
class Lang {
|
|
59
68
|
constructor(lang) {
|
|
69
|
+
this.texts = {};
|
|
60
70
|
const langFileLocation = path_1.default.join(Lang.folder, `${lang}.json`);
|
|
61
71
|
if (fs_1.default.existsSync(langFileLocation)) {
|
|
62
|
-
fs_1.default.
|
|
63
|
-
|
|
64
|
-
return;
|
|
65
|
-
});
|
|
72
|
+
const data = fs_1.default.readFileSync(langFileLocation, { encoding: "utf-8" });
|
|
73
|
+
this.texts = JSON.parse(data);
|
|
66
74
|
}
|
|
67
|
-
this.texts = null;
|
|
68
75
|
}
|
|
69
76
|
static get folder() {
|
|
70
77
|
return path_1.default.join(main_1.bot.dirname, "lang");
|
|
71
78
|
}
|
|
72
79
|
static setup() {
|
|
73
80
|
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
Lang.global = new Lang("global");
|
|
74
82
|
Lang.embed = new Lang("embed");
|
|
75
83
|
Lang.en = new Lang("en");
|
|
76
84
|
});
|
|
@@ -78,6 +86,9 @@ class Lang {
|
|
|
78
86
|
get(text, args) {
|
|
79
87
|
return __awaiter(this, void 0, void 0, function* () {
|
|
80
88
|
let newText = this.texts[text];
|
|
89
|
+
if (newText === undefined && Lang.global) {
|
|
90
|
+
newText = Lang.global.texts[text];
|
|
91
|
+
}
|
|
81
92
|
if (typeof newText === "string") {
|
|
82
93
|
if (args) {
|
|
83
94
|
for (const [name, value] of Object.entries(args)) {
|