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

20
LINES

< > BotCompany Repo | #1027309 // philosophyBot1_addEnableableExtension

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (9310L/60K).

svoid philosophyBot1_addEnableableExtension(PhilosophyBot1 bot, S name, IVF1<PhilosophyBot1> enable) {
  Map<S, IVF1<PhilosophyBot1>> map = cast bot.getExtension("enableableExtensions");
  if (map == null) {
    // first time, register ourselves as an extension
    bot.addExtension("enableableExtensions", map = new Map);
    Map<S, IVF1<PhilosophyBot1>> _map = map;
    bot.addFactPreprocessor(s -> {
      new Matches m;
      if "enable extension *" {
        IVF1<PhilosophyBot1> action = _map.get($1);
        if (action == null) warn("Extension " + $1 + " not found");
        else action.get(bot);
        true;
      }
      false;
    });
  }
  // after that, just add new entry to map
  map.put(name, enable);
}

Author comment

Began life as a copy of #1027180

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: #1027309
Snippet name: philosophyBot1_addEnableableExtension
Eternal ID of this version: #1027309/7
Text MD5: 16f18694598efdcfc48f130303802744
Transpilation MD5: 7076415ef985f552322b31b58750a591
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-03-02 14:53:12
Source code size: 741 bytes / 20 lines
Pitched / IR pitched: No / No
Views / Downloads: 185 / 282
Version history: 6 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)