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

86
LINES

< > BotCompany Repo | #1024502 // Giraffe backup

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

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

1  
!7
2  
3  
cmodule Giraffe > DynDiscordHopper {
4  
  switchable S myName = "Giraffe";
5  
  switchable S sliceID = "wgeuwbcepeoxfwma"; // "Height bot" slice - https://agi.blue/?slice=cxbfnllthxfsuwxw
6  
  
7  
  transient PKIKeyPair keys;
8  
  
9  
  start {
10  
    keys = keyPairForProgram();
11  
    dm_vmBus_onMessage_q('discordGuildJoin, voidfunc(Map map) {
12  
      ret unless map.get('module) == module();
13  
      print("Got join");
14  
      postInChannel(preferredChannelID,
15  
        discordAt(getLong userID(map)) + ", " + questionToAsk());
16  
    });
17  
  }
18  
  
19  
  @Override S answer(S input, Map map) {
20  
    ret mapEachLine_tlft_nempties(input, s -> {
21  
      new Matches m;
22  
      
23  
      // preprocess
24  
      if (discordBotID != 0)
25  
        s = replacePrefix(discordAt(discordBotID), myName + " ", s);
26  
      s = simpleSpaces_noTok(s);
27  
      
28  
      if "what's your name" ret myName;
29  
30  
      S questionToAsk = questionToAsk();
31  
      
32  
      if (eqic(s, "hey " + myName))
33  
        ret or2(questionToAsk, "I don't know what to ask");
34  
        
35  
      if (swic_trim(s, myName + " example for: ", m))
36  
        ret findExample(m.rest());
37  
38  
      if (swic_trim(s, myName + " ", m)) {
39  
        S question = m.rest();
40  
        S answerPattern = randomAnswerPattern(m.rest());
41  
        if (nempty(answerPattern))
42  
          ret fillPattern(answerPattern);
43  
      }
44  
45  
      // react to user input matching an answer pattern
46  
      
47  
      for (S pattern : allAnswerPatterns(questionToAsk)) {
48  
        S regexp = ellipsisToGroupedDotPlusRegexp(angleBracketVarsToEllipsis(pattern));
49  
        print("Have regexp: " + regexp);
50  
        LS groups = regexpFirstGroupsIC(regexp, s);
51  
        if (nempty(groups))
52  
          ret "Aha! " + first(groups) + " " + discordAt(getLong userID(map));
53  
      }
54  
55  
      null;
56  
    });
57  
  }
58  
  
59  
  S questionToAsk() {
60  
    ret agiBlue_randomLookupInSlice(sliceID, "question to ask", "is");
61  
  }
62  
  
63  
  // assume s is sanitized
64  
  S findExample(S s) {
65  
    ret agiBlue_randomALookupInSlice(sliceID, "is a", s);
66  
  }
67  
  
68  
  S randomAnswerPattern(S question) {
69  
    ret agiBlue_randomLookupInSlice(sliceID, question, "answer pattern");
70  
  }
71  
72  
  LS allAnswerPatterns(S question) {
73  
    ret agiBlue_multiLookupInSlice(sliceID, question, "answer pattern");
74  
  }
75  
76  
  S fillPattern(S pattern) {
77  
    LS tok = javaTokWithAngleBrackets(pattern);
78  
    for (int idx : indicesOfAngleBracketVars(tok)) {
79  
      S value = findExample(deAngleBracket(tok.get(idx)));
80  
      if (nempty(value))
81  
        tok.set(idx, value);
82  
    }
83  
    ret join(tok);
84  
  }
85  
  
86  
}

Author comment

Began life as a copy of #1024415

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: #1024502
Snippet name: Giraffe backup
Eternal ID of this version: #1024502/1
Text MD5: d456b164ca2a63ad9ce2e9945670b78c
Transpilation MD5: 91c4ad4d828048b34d6b5d2a461e9f0b
Author: stefan
Category: javax / discord / a.i.
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-08-15 13:55:00
Source code size: 2549 bytes / 86 lines
Pitched / IR pitched: No / No
Views / Downloads: 203 / 263
Referenced in: [show references]