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

72
LINES

< > BotCompany Repo | #1025300 // Clusters Bot v1 [as made in youtube.be/0gmwaqmjKhM]

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

Uses 5909K of libraries. Click here for Pure Java version (9740L/51K).

!7

cmodule ClustersBot extends DynTalkBot2<ClustersBot.ByServer> {
  start {
    makeByServer = () -> new ByServer;
    useAGIBlueForDropPunctuation = false;
    preprocessAtSelfToMyName = false;
  }

  sclass Cluster {
    GlobalID globalID = aGlobalIDObject();
    Set<S> synonyms = ciSet();

    *() {}
    *(S s) { synonyms.add(s); }
  }
 
  class ByServer extends DynTalkBot2.ByServer {
    new L<Cluster> clusters;
    Cluster topic;

    L<Cluster> searchForCluster(S s) {
      ret filter(clusters, c -> contains(c.synonyms, s));
    }
    
    synchronized S processSimplifiedLine(S s, O... _) {
      try answer super.processSimplifiedLine(s, _); // adding authorized users etc.
      
      new Matches m;
      
      S sOld = s;
      s = dropPrefixOrNull(myPrefix(), s);
      if (s == null) {
        print("no got prefix: " + quote(myPrefix()) + " / " + quote(sOld));
        null;
      }
      
      if (matchX2("do you know ...|name ...", s, m)) {
        L<Cluster> found = searchForCluster($1);
        if (empty(found)) {
          topic = new Cluster($1);
          clusters.add(topic);
          change();
          ret "No I don't know " + $1;
        }
        topic = random(found); change();
        ret (l(found) > 1 ? "I know multiple. " : "")
          + "You mean " + join(" = ", topic.synonyms) + "?";
      }

      if (matchX2("he is ...|she is ...|it is ...|he's ...|she's ...|it's ...|they are ...", s, m)) {
        if (topic == null) ret "Who is?";
        if (topic.synonyms.add($1)) {
          change();
          ret "Aha. " + join(" = ", topic.synonyms);
        } else
          ret "Yup, I know";
      }

      if "number of clusters" ret l_str(clusters);
        
      if (eqic(s, "help"))
        ret trim([[
Help text will go here.
  
[Bot made by https://BotCompany.de]
  ]]).replace("@me", atSelf());
  
      null;
    }
  }
}

Author comment

Began life as a copy of #1025290

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1025300
Snippet name: Clusters Bot v1 [as made in youtube.be/0gmwaqmjKhM]
Eternal ID of this version: #1025300/1
Text MD5: 07df9b2582bec9aabeb18d9c01cc3ac0
Transpilation MD5: e2f17efadcf73c54771bcf38f1436363
Author: stefan
Category:
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-09-20 13:31:32
Source code size: 1955 bytes / 72 lines
Pitched / IR pitched: No / No
Views / Downloads: 223 / 332
Referenced in: [show references]