Load stickers from config file.

This commit is contained in:
N-Pex 2021-09-25 14:35:38 +02:00
parent 3bd15adc29
commit 46a4268245
7 changed files with 78 additions and 38 deletions

View file

@ -2,39 +2,24 @@ const stickerPacks = {};
stickerPacks.ordering = [];
const stickerCodeMap = {};
try {
const stickerPackInfo = require("!!raw-loader!@/assets/stickers/order.txt").default;
const packInfo = stickerPackInfo.split("\n");
for (let i = 0; i < packInfo.length; i++) {
const pack = packInfo[i];
if (pack && pack.length > 0 && !pack.startsWith('#')) {
stickerPacks[pack] = [];
stickerPacks.ordering.push(pack);
}
}
} catch (ignorederr) {
//
}
function importAll(r) {
return r.keys().map(res => {
// Remove"./"
const parts = res.split("/");
const pack = parts[1];
const sticker = parts[2].split(".")[0];
const image = r(res);
if (stickerPacks[pack] !== undefined) {
stickerPacks[pack].push({ image: image, name: sticker });
stickerCodeMap[":" + pack + "-" + sticker + ":"] = image;
}
});
}
importAll(require.context('@/assets/stickers/', true, /\.png$/));
class Stickers {
constructor() {
}
loadStickersFromConfig(config) {
const stickerConfig = config.shortCodeStickers;
for (const pack of stickerConfig.packs) {
stickerPacks[pack.name] = [];
stickerPacks.ordering.push(pack.name);
for (const sticker of pack.stickers) {
const stickerName = sticker.split(".")[0];
const stickerUrl = stickerConfig.baseUrl + pack.name + "/" + sticker;
stickerPacks[pack.name].push({ image: stickerUrl, name: stickerName });
stickerCodeMap[":" + pack.name + "-" + stickerName + ":"] = stickerUrl;
}
}
}
isStickerShortcode(messageBody) {
if (messageBody && messageBody.startsWith(":") && messageBody.startsWith(":") && messageBody.length >= 5) {
const image = this.getStickerImage(messageBody);