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

95
LINES

< > BotCompany Repo | #1025863 // AGI.blue Rules Bot (dev.)

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

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

!7

//!include once #1025868 // DynTalkBot2 compact include - causes exceptions sometimes after reloads

concept PostedRuleMatch {
  long guildID, msgID;
  AGIBlue_MatchedRule matchedRule;
  
  L<Reaction> reactions() {
    ret conceptsWhere(concepts(), Reaction, +msgID);
  }
  
  toString { ret sfu(this); }
}

concept Reaction {
  long msgID, userID;
  S emoji;
}

standardBot1 agiBlueRulesBot {
  init {
    dbIndexing(PostedRuleMatch, 'msgID, Reaction, 'msgID);
    analyze();
    dropPunctuation = false;
  }

  processSimplified {
    if null (s = dropMyPrefixOrNull(s)) null;
    
    PairS p = tok_splitAtDoubleArrow_pair(s);
    if (p != null)
      ret agiBlue_postInSlice_trueIfNew(agiBlue_rulesSlice(),
        s, "is", "a rule") ? "OK" : "I know";

    long channelID = longPar channelID(_);
    
    L<AGIBlue_Rule> rules = agiBlue_ruleObjects();
    L<AGIBlue_MatchedRule> matches = agiBlue_matchAllRulesOnInput(s);
    if (empty(matches)) ret "No matches with " + nRules(rules);
    L<AGIBlue_MatchedRule> matches2 = takeFirst(resultsToShow, matches);
    for (AGIBlue_MatchedRule mm : matches2) {
      S r = backtickQuote(mm.rewrittenRHS())
        + "\n  " + mm.map;
      postInChannel(channelID, r, msg -> {
        temp enter();
        cnew(PostedRuleMatch, guildID := guildID, msgID := msg.getIdLong(), matchedRule := mm);
        queue(msg.addReaction(positiveEmoji));
        queue(msg.addReaction(negativeEmoji));
      });
    }
    postInChannel(channelID, plusNMoreWithNL(matches, matches2));
  }
  
  void onMessageReaction(Map map, bool added) {
    long msgID = cast map.get('msgID);
    long userID = cast map.get('userID);
    S emoji = cast map.get('emoji);
    
    if (added) {
      Reaction r = uniq(Reaction, +msgID, +userID, +emoji);
      print("Added reaction: " + sfu(r));
    } else {
      print("Removed reaction: " + sfu(removeConceptsWhere(Reaction, +msgID, +userID, +emoji)));
    }
  }
  
  allServers {
    transient S positiveEmoji = unicode_thumbsUp();
    transient S negativeEmoji = unicode_thumbsDown();
    transient int resultsToShow = 3;
  
    void analyze {
      for (PostedRuleMatch pr) {
        int pos = 0, neg = 0;
        for (Reaction r : pr.reactions()) {
          if (eq(r.emoji, positiveEmoji)) ++pos;
          else if (eq(r.emoji, negativeEmoji)) ++neg;
        }
        if (pos > 0 && neg > 0) continue with print("Unclear reactions to " + pr);
        if (pos == 0 && neg == 0) continue;
        SS map = pr.matchedRule.map;
        S pn = pos > 0 ? "Positive" : "Negative";
        if (empty(map))
          if (neg > 0)
            continue with print("Weird: Negative reaction to unchanged rule: " + pr);
          else
            continue with print("Unchanged rule confirmed: " + pr);
        if (l(map) == 1)
          continue with print(quote(firstKey(map)) + " and " + quote(firstValue(map)) + " are " + (pos > 0 ? "similar" : "dissimilar"));
        print(pn + " feedback needs to be assigned to parts: " + map);
      }
    }
  }
}

Author comment

Began life as a copy of #1025572

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: #1025863
Snippet name: AGI.blue Rules Bot (dev.)
Eternal ID of this version: #1025863/41
Text MD5: fb518bed90b2f8861c59f37c0162beb1
Transpilation MD5: 9fd55e2d86e6190eecbe40d196dbacdb
Author: stefan
Category: javax / agi.blue
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-10-27 22:35:02
Source code size: 3118 bytes / 95 lines
Pitched / IR pitched: No / No
Views / Downloads: 236 / 28270
Version history: 40 change(s)
Referenced in: [show references]