Warning: session_start(): open(/var/lib/php/sessions/sess_2ge62847g06br68h7qjp7ku23j, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
!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 (S) random(jsonDecodeList(agiBlue_query([[
question to ask / is / $x
return $x
]], slice := sliceID)));
}
// assume s is sanitized
S findExample(S s) {
ret (S) random(jsonDecodeList(agiBlue_query([[
$x / is a / ***
return $x
]].replace("***", s), slice := sliceID)));
}
S randomAnswerPattern(S question) {
ret random(agiBlue_lookupInSlice(sliceID, question, "answer pattern"));
}
LS allAnswerPatterns(S question) {
ret jsonDecodeList(loadPage(agiBlueURL() + "/bot/multiLookup"
+ hquery(slice := sliceID, q := question, key := "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);
}
}