Uses 1059K of libraries. Click here for Pure Java version (11623L/60K).
1 | !7 |
2 | |
3 | concept GModule { |
4 | S moduleID, moduleLibID; |
5 | S userID; // e. g. discord user id |
6 | S userName; |
7 | S shorthand; |
8 | } |
9 | |
10 | cmodule2 GModulesManager > DynCRUD<GModule> { |
11 | // API |
12 | |
13 | S startModuleForUser(S moduleLibID, S userID, S userName, S shorthand, O... _) { |
14 | assertNempty("Need user ID", userID); |
15 | assertNempty("Need module shorthand", shorthand); |
16 | Pair<GModule, Bool> p = uniqConcept2(+userID, +shorthand); |
17 | if (!p.b) ret "Module already running"; |
18 | cset(p.a, +userName, +moduleLibID); |
19 | print("Starting module: " + moduleLibID); |
20 | S moduleID = dm_makeNewModule(moduleLibID); |
21 | cset(p.a, +moduleID); |
22 | |
23 | O info = dm_getOpt(moduleID, 'gInfo); |
24 | if (info != null) { |
25 | setOpt(info, +userID); |
26 | setOpt(info, +shorthand); |
27 | dm_call(moduleID, 'change); |
28 | } |
29 | |
30 | S answer = cast dm_callOpt(p.a.moduleID, 'initialAnswer, (O) _); |
31 | if (nempty(answer)) ret answer; |
32 | ret print("Module " + moduleLibID + " started for " + userName + " as " + quote(shorthand)); |
33 | } |
34 | |
35 | S deleteAllModulesForUser(S userID, O... _) { |
36 | Cl<GModule> l = conceptsWhere GModule(+userID); |
37 | if (empty(l)) ret boolPar silentIfEmpty(_) ? "" : "No modules loaded"; |
38 | for (GModule m : l) |
39 | dm_deleteModule(m.moduleID); |
40 | deleteConcepts(l); |
41 | ret n2(l, "module") + " deleted"; |
42 | } |
43 | |
44 | // returns module ID |
45 | S findModuleForUser(S userID, S shorthand) { |
46 | if (empty(userID) || empty(shorthand)) null; |
47 | GModule mod = conceptWhere GModule(+userID, +shorthand); |
48 | ret mod == null ? null : mod.moduleID; |
49 | } |
50 | |
51 | S deleteModuleForUser(S userID, S shorthand) { |
52 | GModule mod = conceptWhere GModule(+userID, +shorthand); |
53 | if (mod == null) ret "Module not found"; |
54 | dm_deleteModule(mod.moduleID); |
55 | deleteConcept(mod); |
56 | ret "Module deleted"; |
57 | } |
58 | |
59 | void removeModule(O mod) { |
60 | deleteConcept(conceptWhere GModule(moduleID := dm_moduleID(mod))); |
61 | } |
62 | |
63 | void removeModuleAndDelete(O mod) { |
64 | removeModule(mod); |
65 | doLater(5.0, r { |
66 | dm_deleteModule(mod) |
67 | }); |
68 | } |
69 | |
70 | LS modulesForUser(S userID) { |
71 | ret collect moduleID(conceptsWhere GModule(+userID)); |
72 | } |
73 | |
74 | LS activeModulesForUser(S userID) { |
75 | ret filter(modulesForUser(userID), mod -> moduleIsActive(mod)); |
76 | } |
77 | |
78 | bool moduleIsActive(S moduleID) { |
79 | O info = dm_getOpt(moduleID, 'gInfo); |
80 | ret info == null || !isFalse(getOpt(info, 'active)); |
81 | } |
82 | |
83 | Cl<GModule> modulesInfoForUser(S userID) { |
84 | ret conceptsWhere GModule(+userID); |
85 | } |
86 | } |
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1021931 |
Snippet name: | Gazelle Modules Manager |
Eternal ID of this version: | #1021931/33 |
Text MD5: | 26fe262840352f399aaaa1e7ec1fb974 |
Transpilation MD5: | e18d6b5d8c1a4d5983c2b92de9fc2e0e |
Author: | stefan |
Category: | javax / gazelle |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-01-26 06:24:35 |
Source code size: | 2545 bytes / 86 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 407 / 39586 |
Version history: | 32 change(s) |
Referenced in: | [show references] |