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

44
LINES

< > BotCompany Repo | #1009323 // MultiBot with commands + bots list [WORKS]

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Uses 3874K of libraries. Click here for Pure Java version (9261L/64K/218K).

1  
!7
2  
3  
concept Config { new L<S> bots; /* contains program IDs */ }
4  
static L<Pair<S, Class>> bots = synchroList(); // pair(program ID, main class)
5  
static JList lCommands, lBots;
6  
7  
p-subst {
8  
  db(); loadBots();
9  
  if (isMainProgram()) {
10  
    swing { addToWindowSplitRight_aggressive(consoleFrame(),
11  
      jvsplit(
12  
        withMargin(withCenteredTitle("Bots", lBots = jlist())),
13  
        withMargin(withCenteredTitle("Commands", lCommands = jlist_dragEnabled()))));
14  
      awtCalcEvery(lBots, 1000, f updateBotsList);
15  
      centerConsole(600, 600);
16  
    }
17  
    updateCommandList(); focusConsole(); botSleep();
18  
  }
19  
}
20  
21  
svoid loadBots { cleanUpAndClear(bots); for (S x : config().bots) bots.add(pair(x, runSubBot(x))); updateCommandList(); }
22  
23  
answer {
24  
  lock dbLock();
25  
  if "add bot *" {
26  
    setAddOrMoveToFront(config().bots, formatSnippetID($1));
27  
    config().change(); loadBots(); ret "OK";
28  
  }
29  
  if "remove bot *" {
30  
    config().bots.remove(formatSnippetID($1));
31  
    config().change(); loadBots(); ret "OK";
32  
  }
33  
  if "list bots" ret sfu(config().bots);
34  
  try answer scanMultipleBots(secondOfPairs(bots), s);
35  
}
36  
37  
svoid updateCommandList { fillListWithStrings(lCommands, knownCommands()); }
38  
svoid updateBotsList { fillListWithStrings(lBots, snippetsWithTitles(firstOfPairs(bots))); }
39  
40  
static L<S> knownCommands() {
41  
  ret getSupportedQuestions_multipleBots(concatLists(ll(mc()), secondOfPairs(bots)));
42  
}
43  
44  
static Config config() { ret uniq_sync(Config); }

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1009323
Snippet name: MultiBot with commands + bots list [WORKS]
Eternal ID of this version: #1009323/38
Text MD5: 4371bbd536ce38b79ed8ef6b79adf580
Transpilation MD5: 97d752e05f0be1fbe70659da4879fe62
Author: stefan
Category: javax / talking robots
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-07-24 16:48:30
Source code size: 1482 bytes / 44 lines
Pitched / IR pitched: No / No
Views / Downloads: 506 / 775
Version history: 37 change(s)
Referenced in: [show references]