!7 //!include once #1025868 // DynTalkBot2 compact include - causes exceptions sometimes after reloads concept PostedRuleMatch { long guildID, msgID; AGIBlue_MatchedRule matchedRule; L reactions() { ret conceptsWhere(concepts(), Reaction, +msgID); } } concept Reaction { long msgID, userID; S emoji; } standardBot1 agiBlueRulesBot { init { dbIndexing(PostedRuleMatch, 'msgID, Reaction, 'msgID); } processSimplified { if null (s = dropMyPrefixOrNull(s)) null; long channelID = longPar channelID(_); L rules = agiBlue_ruleObjects(); L matches = agiBlue_matchAllRulesOnInput(s); if (empty(matches)) ret "No matches with " + nRules(rules); L matches2 = takeFirst(5, 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(unicode_thumbsUp())); queue(msg.addReaction(unicode_thumbsDown())); }); } 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))); } } }