Uses 5909K of libraries. Click here for Pure Java version (20448L/110K).
1 | !7 |
2 | |
3 | //!include once #1025868 // DynTalkBot2 compact include - causes exceptions sometimes after reloads |
4 | |
5 | concept PostedRuleMatch {
|
6 | long guildID, msgID; |
7 | AGIBlue_MatchedRule matchedRule; |
8 | |
9 | L<Reaction> reactions() {
|
10 | ret conceptsWhere(concepts(), Reaction, +msgID); |
11 | } |
12 | |
13 | toString { ret sfu(this); }
|
14 | } |
15 | |
16 | concept Reaction {
|
17 | long msgID, userID; |
18 | S emoji; |
19 | } |
20 | |
21 | standardBot1 agiBlueRulesBot {
|
22 | init {
|
23 | dbIndexing(PostedRuleMatch, 'msgID, Reaction, 'msgID); |
24 | analyze(); |
25 | dropPunctuation = false; |
26 | } |
27 | |
28 | processSimplified {
|
29 | if null (s = dropMyPrefixOrNull(s)) null; |
30 | |
31 | PairS p = tok_splitAtDoubleArrow_pair(s); |
32 | if (p != null) |
33 | ret agiBlue_postInSlice_trueIfNew(agiBlue_rulesSlice(), |
34 | s, "is", "a rule") ? "OK" : "I know"; |
35 | |
36 | long channelID = longPar channelID(_); |
37 | |
38 | L<AGIBlue_Rule> rules = agiBlue_ruleObjects(); |
39 | L<AGIBlue_MatchedRule> matches = agiBlue_matchAllRulesOnInput(s); |
40 | if (empty(matches)) ret "No matches with " + nRules(rules); |
41 | L<AGIBlue_MatchedRule> matches2 = takeFirst(resultsToShow, matches); |
42 | for (AGIBlue_MatchedRule mm : matches2) {
|
43 | S r = backtickQuote(mm.rewrittenRHS()) |
44 | + "\n " + mm.map; |
45 | postInChannel(channelID, r, msg -> {
|
46 | temp enter(); |
47 | cnew(PostedRuleMatch, guildID := guildID, msgID := msg.getIdLong(), matchedRule := mm); |
48 | queue(msg.addReaction(positiveEmoji)); |
49 | queue(msg.addReaction(negativeEmoji)); |
50 | }); |
51 | } |
52 | postInChannel(channelID, plusNMoreWithNL(matches, matches2)); |
53 | } |
54 | |
55 | void onMessageReaction(Map map, bool added) {
|
56 | long msgID = cast map.get('msgID);
|
57 | long userID = cast map.get('userID);
|
58 | S emoji = cast map.get('emoji);
|
59 | |
60 | if (added) {
|
61 | Reaction r = uniq(Reaction, +msgID, +userID, +emoji); |
62 | print("Added reaction: " + sfu(r));
|
63 | } else {
|
64 | print("Removed reaction: " + sfu(removeConceptsWhere(Reaction, +msgID, +userID, +emoji)));
|
65 | } |
66 | } |
67 | |
68 | allServers {
|
69 | transient S positiveEmoji = unicode_thumbsUp(); |
70 | transient S negativeEmoji = unicode_thumbsDown(); |
71 | transient int resultsToShow = 3; |
72 | |
73 | void analyze {
|
74 | for (PostedRuleMatch pr) {
|
75 | int pos = 0, neg = 0; |
76 | for (Reaction r : pr.reactions()) {
|
77 | if (eq(r.emoji, positiveEmoji)) ++pos; |
78 | else if (eq(r.emoji, negativeEmoji)) ++neg; |
79 | } |
80 | if (pos > 0 && neg > 0) continue with print("Unclear reactions to " + pr);
|
81 | if (pos == 0 && neg == 0) continue; |
82 | SS map = pr.matchedRule.map; |
83 | S pn = pos > 0 ? "Positive" : "Negative"; |
84 | if (empty(map)) |
85 | if (neg > 0) |
86 | continue with print("Weird: Negative reaction to unchanged rule: " + pr);
|
87 | else |
88 | continue with print("Unchanged rule confirmed: " + pr);
|
89 | if (l(map) == 1) |
90 | continue with print(quote(firstKey(map)) + " and " + quote(firstValue(map)) + " are " + (pos > 0 ? "similar" : "dissimilar")); |
91 | print(pn + " feedback needs to be assigned to parts: " + map); |
92 | } |
93 | } |
94 | } |
95 | } |
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: | 514 / 28602 |
| Version history: | 40 change(s) |
| Referenced in: | [show references] |