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

!7

cmodule Giraffe > DynDiscordHopper {
  switchable S myName = "Giraffe";
  switchable S sliceID = "wgeuwbcepeoxfwma"; // "Height bot" slice - https://agi.blue/?slice=cxbfnllthxfsuwxw
  
  transient PKIKeyPair keys;
  
  start {
    keys = keyPairForProgram();
    dm_vmBus_onMessage_q('discordGuildJoin, voidfunc(Map map) {
      ret unless map.get('module) == module();
      print("Got join");
      postInChannel(preferredChannelID,
        discordAt(getLong userID(map)) + ", " + questionToAsk());
    });
  }
  
  @Override S answer(S input, Map map) {
    ret mapEachLine_tlft_nempties(input, s -> {
      new Matches m;
      
      // preprocess
      if (discordBotID != 0)
        s = replacePrefix(discordAt(discordBotID), myName + " ", s);
      s = simpleSpaces_noTok(s);
      
      if "what's your name" ret myName;

      S questionToAsk = questionToAsk();
      
      if (eqic(s, "hey " + myName))
        ret or2(questionToAsk, "I don't know what to ask");
        
      if (swic_trim(s, myName + " example for: ", m))
        ret findExample(m.rest());

      if (swic_trim(s, myName + " ", m)) {
        S question = m.rest();
        S answerPattern = randomAnswerPattern(m.rest());
        if (nempty(answerPattern))
          ret fillPattern(answerPattern);
      }

      // react to user input matching an answer pattern
      
      for (S pattern : allAnswerPatterns(questionToAsk)) {
        S regexp = ellipsisToGroupedDotPlusRegexp(angleBracketVarsToEllipsis(pattern));
        print("Have regexp: " + regexp);
        LS groups = regexpFirstGroupsIC(regexp, s);
        if (nempty(groups))
          ret "Aha! " + first(groups) + " " + discordAt(getLong userID(map));
      }

      null;
    });
  }
  
  S questionToAsk() {
    ret agiBlue_randomLookupInSlice(sliceID, "question to ask", "is");
  }
  
  // assume s is sanitized
  S findExample(S s) {
    ret agiBlue_randomALookupInSlice(sliceID, "is a", s);
  }
  
  S randomAnswerPattern(S question) {
    ret agiBlue_randomLookupInSlice(sliceID, question, "answer pattern");
  }

  LS allAnswerPatterns(S question) {
    ret agiBlue_multiLookupInSlice(sliceID, question, "answer pattern");
  }

  S fillPattern(S pattern) {
    LS tok = javaTokWithAngleBrackets(pattern);
    for (int idx : indicesOfAngleBracketVars(tok)) {
      S value = findExample(deAngleBracket(tok.get(idx)));
      if (nempty(value))
        tok.set(idx, value);
    }
    ret join(tok);
  }
  
}

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: 202 / 262
Referenced in: