1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const adminSockets = require.main.require('./src/socket.io/admin');
|
4 | const db = require.main.require('./src/database');
|
5 | const hash = require('string-hash');
|
6 | const async = require("async");
|
7 | const emojisKey = 'emoji:customizations:emojis';
|
8 | const adjunctsKey = 'emoji:customizations:adjuncts';
|
9 | exports.getCustomizations = (callback) => {
|
10 | async.waterfall([
|
11 | (next) => async.parallel({
|
12 | emojis: cb => db.getSortedSetRangeWithScores(emojisKey, 0, -1, cb),
|
13 | adjuncts: cb => db.getSortedSetRangeWithScores(adjunctsKey, 0, -1, cb),
|
14 | }, next),
|
15 | ({ emojis, adjuncts }, next) => {
|
16 | const emojisParsed = emojis.map(emoji => JSON.parse(emoji.value));
|
17 | const adjunctsParsed = adjuncts.map(adjunct => JSON.parse(adjunct.value));
|
18 | next(null, {
|
19 | emojis: emojisParsed,
|
20 | adjuncts: adjunctsParsed,
|
21 | });
|
22 | },
|
23 | ], callback);
|
24 | };
|
25 | const editThing = (key, name, thing) => {
|
26 | async.series([
|
27 | (next) => {
|
28 | const num = hash(name);
|
29 | db.sortedSetsRemoveRangeByScore([key], num, num, next);
|
30 | },
|
31 | (next) => {
|
32 | const num = hash(thing.name);
|
33 | db.sortedSetAdd(key, num, JSON.stringify(thing), next);
|
34 | },
|
35 | ]);
|
36 | };
|
37 | const deleteThing = (key, name) => {
|
38 | const num = hash(name);
|
39 | db.sortedSetsRemoveRangeByScore([key], num, num);
|
40 | };
|
41 | const emojiSockets = {};
|
42 | emojiSockets.getCustomizations = (socket, callback) => exports.getCustomizations(callback);
|
43 | emojiSockets.editEmoji = (socket, [name, emoji]) => editThing(emojisKey, name, emoji);
|
44 | emojiSockets.deleteEmoji = (socket, name) => deleteThing(emojisKey, name);
|
45 | emojiSockets.editAdjunct = (socket, [name, adjunct]) => editThing(adjunctsKey, name, adjunct);
|
46 | emojiSockets.deleteAdjunct = (socket, name) => deleteThing(adjunctsKey, name);
|
47 | adminSockets.plugins.emoji = emojiSockets;
|
48 |
|
\ | No newline at end of file |