Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

43
LINES

< > BotCompany Repo | #1027665 // Chat Bot Frontend v3 [with scripts]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 911K of libraries. Click here for Pure Java version (20801L/111K).

1  
!7
2  
3  
cmodule ChatBotFrontend > DynChatBotFrontend {
4  
  Set<S> scriptRefs = syncSet();
5  
  transient L<virtual CruddieScript> scripts;
6  
  
7  
  start-thread {
8  
    while (dm_booting()) sleepSeconds(0.1);
9  
    loadScripts();
10  
  }
11  
  
12  
  void loadScripts {
13  
    new L<virtual CruddieScript> scripts;
14  
    for (S ref : scriptRefs) pcall {
15  
      LS l = splitAtSlash(ref);
16  
      if (l(l) != 3) continue with print("Can't load script: " + ref);
17  
      S mod = dm_require(first(l) + "/" + second(l));
18  
      Class c = dm_getClassInModuleRealm(mod, "main$" + last(l));
19  
      if (c == null) continue with print("Couldn't find class: " + ref);
20  
      O o = nu(c);
21  
      forwardSwappableFunctionsToObject(o, module(), 'setBotName, 'getBotName);
22  
      scripts.add(o);
23  
      print("Got script: " + o);
24  
    }
25  
    this.scripts = scripts;
26  
  }
27  
  
28  
  @Override
29  
  S answer_other(S s) null {
30  
    fOr (virtual CruddieScript script : scripts) pcall {
31  
      try S a = (S) call(script, 'answer, s);
32  
    }
33  
  }
34  
  
35  
  // API
36  
  
37  
  void addScript(S moduleLibID, S shortClassName) {
38  
    if (scriptRefs.add(addPrefix("#", moduleLibID) + "/" + assertIdentifier(shortClassName))) {
39  
      change();
40  
      loadScripts();
41  
    }
42  
  }
43  
}

Author comment

Began life as a copy of #1027602

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1027665
Snippet name: Chat Bot Frontend v3 [with scripts]
Eternal ID of this version: #1027665/12
Text MD5: c48218e566e0ad082cddc97f76e64a66
Transpilation MD5: 72564f638b65addf48879780e314d6a8
Author: stefan
Category: javax
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-03-30 00:22:45
Source code size: 1218 bytes / 43 lines
Pitched / IR pitched: No / No
Views / Downloads: 194 / 440
Version history: 11 change(s)
Referenced in: [show references]