Warning: session_start(): open(/var/lib/php/sessions/sess_lrj8e9qbgpnqhdkbr64nqdjf59, 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
concept Msg {
long msgID, channelID, userID;
long date, edited; // epochSeconds
S text;
}
standardBot1 EAMBot {
init {
dbIndexing(Msg, 'msgID);
}
sync S processSimplifiedLine(S s, O... _) {
try answer super.processSimplifiedLine(s, _);
if ((s = dropMyPrefixOrNull(s)) == null) null;
optPar MessageChannel channel;
if "retrieve history" {
MessageHistory history = channel.getHistory();
nu Scan(+channel, +history, incremental := true).run();
ret "Retrieving...";
}
if "db size" ret nMessages(countConcepts(Msg));
if "random message" {
Msg msg = random(list(Msg));
ret msg == null ? "No messages" : "[" + msg.msgID + "] " + msg.text;
}
null;
}
class Scan {
MessageChannel channel;
MessageHistory history;
int scanned;
bool incremental;
run {
history.retrievePast(100).queue(msgs -> {
temp enter();
print("Got msgs: " + l(msgs));
if (empty(msgs)) ret with postInChannel(channel, "Done (" + nMessages(scanned) + ")");
scanned += l(msgs);
if (storeMsgs(msgs) && incremental) ret with print("Stopping incremental scan after " + scanned);
run();
}, onQueueError);
}
}
bool storeMsgs(L l) {
bool anyNew;
for (Message msg : l) {
Msg m, bool isNew = unpair uniq2(Msg, msgID := msg.getIdLong());
if (isNew) set anyNew;
cset(m,
channelID := msg.getTextChannel().getIdLong(),
userID := msg.getAuthor().getIdLong(),
date := msg.getCreationTime().toEpochSecond(),
edited := msg.isEdited() ? msg.getEditedTime().toEpochSecond() : 0,
text := msg.getContentRaw());
}
ret anyNew;
}
}