abstract sclass DynTalkBot > DynDiscordHopper { switchable S myName = "Anonymous bot"; transient bool useAGIBlueForDropPunctuation = true; transient bool preprocessAtSelfToMyName = true; transient bool dropPunctuation = true; L authorizedUsers = ll(54770685468029747); // stefan start { dm_vmBus_onMessage_q('discordGuildJoin, voidfunc(Map map) { ret unless map.get('module) == module(); print("Got join"); onUserJoin(getLong userID(map), map); }); } // overridable void onUserJoin(long userID, O... _) {} @Override S answer(S input, Map map) { try answer super.answer(input, map); // discord hopping ret mapEachLine_tlft_nempties(input, s -> { ret processLine(s, map); }); } S processLine(S s, O... _) { s = preprocess(s, _); ret processSimplifiedLine(s, _); } S preprocess(S s, O... _) { if (preprocessAtSelfToMyName && discordBotID != 0) s = replace(s, atSelf(), " " + myName + " "); if (dropPunctuation) s = dropPunctuation3_withAGIBlue(useAGIBlueForDropPunctuation, s); s = trim(simpleSpaces_noTok(s)); print("simplified >> " + quote(s)); ret s; } S myPrefix() { ret preprocessAtSelfToMyName ? myName + " " : (dropPunctuation ? replace(atSelf(), "@", "") /* @ is killed by preprocessing */ : atSelf()) + " "; } // extend me S processSimplifiedLine(S input, O... _) { new Matches m; if (swic_trim(input, myPrefix() + "add master ", m)) { try answer checkAuth(_); add(authorizedUsers, parseFirstLong(m.rest())); change(); ret "Okidoki. Have " + n2(l(authorizedUsers), "master"); } if (eqic(input, myPrefix() + "masters")) ret empty(authorizedUsers) ? "I have no masters." : "My masters are: " + joinWithComma(map discordAtPlusID(authorizedUsers)); if (swic_trim(input, myPrefix() + "delete master ", m)) { try answer checkAuth(_); remove(authorizedUsers, parseFirstLong(m.rest())); change(); ret "Okidoki. Have " + n2(l(authorizedUsers), "master"); } null; } bool authed(O... _) { ret contains(authorizedUsers, optPar userID(_)); } S checkAuth(O... _) { if (!authed(_)) ret "You are not authorized"; null; } }