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

72
LINES

< > BotCompany Repo | #1025290 // Clusters Bot [old]

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).

1  
!7
2  
3  
cmodule ClustersBot extends DynTalkBot2<ClustersBot.ByServer> {
4  
  start {
5  
    makeByServer = () -> new ByServer;
6  
    useAGIBlueForDropPunctuation = false;
7  
    preprocessAtSelfToMyName = false;
8  
  }
9  
10  
  sclass Cluster {
11  
    GlobalID globalID = aGlobalIDObject();
12  
    Set<S> synonyms = ciSet();
13  
14  
    *() {}
15  
    *(S s) { synonyms.add(s); }
16  
  }
17  
 
18  
  class ByServer extends DynTalkBot2.ByServer {
19  
    new L<Cluster> clusters;
20  
    Cluster topic;
21  
22  
    L<Cluster> searchForCluster(S s) {
23  
      ret filter(clusters, c -> contains(c.synonyms, s));
24  
    }
25  
    
26  
    synchronized S processSimplifiedLine(S s, O... _) {
27  
      try answer super.processSimplifiedLine(s, _); // adding authorized users etc.
28  
      
29  
      new Matches m;
30  
      
31  
      S sOld = s;
32  
      s = dropPrefixOrNull(myPrefix(), s);
33  
      if (s == null) {
34  
        print("no got prefix: " + quote(myPrefix()) + " / " + quote(sOld));
35  
        null;
36  
      }
37  
      
38  
      if (matchX2("do you know ...|name ...", s, m)) {
39  
        L<Cluster> found = searchForCluster($1);
40  
        if (empty(found)) {
41  
          topic = new Cluster($1);
42  
          clusters.add(topic);
43  
          change();
44  
          ret "No I don't know " + $1;
45  
        }
46  
        topic = random(found); change();
47  
        ret (l(found) > 1 ? "I know multiple. " : "")
48  
          + "You mean " + join(" = ", topic.synonyms) + "?";
49  
      }
50  
51  
      if (matchX2("he is ...|she is ...|it is ...|he's ...|she's ...|it's ...|they are ...", s, m)) {
52  
        if (topic == null) ret "Who is?";
53  
        if (topic.synonyms.add($1)) {
54  
          change();
55  
          ret "Aha. " + join(" = ", topic.synonyms);
56  
        } else
57  
          ret "Yup, I know";
58  
      }
59  
60  
      if "number of clusters" ret l_str(clusters);
61  
        
62  
      if (eqic(s, "help"))
63  
        ret trim([[
64  
Help text will go here.
65  
  
66  
[Bot made by https://BotCompany.de]
67  
  ]]).replace("@me", atSelf());
68  
  
69  
      null;
70  
    }
71  
  }
72  
}

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: #1025290
Snippet name: Clusters Bot [old]
Eternal ID of this version: #1025290/18
Text MD5: 07df9b2582bec9aabeb18d9c01cc3ac0
Transpilation MD5: 2d7311a7434f459e558f796d47a934e4
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 14:36:34
Source code size: 1955 bytes / 72 lines
Pitched / IR pitched: No / No
Views / Downloads: 220 / 24498
Version history: 17 change(s)
Referenced in: [show references]