Warning: session_start(): open(/var/lib/php/sessions/sess_c1mptgtqgomganqto057ltlrpi, 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
// requires Msg concept
class DiscordScanner {
MessageChannel channel;
MessageHistory history;
int scanned;
bool incremental, postResult = true;
Runnable whenDone;
run {
if (history == null) history = channel.getHistory();
history.retrievePast(100).queue(msgs -> {
temp enter();
print("Got msgs: " + l(msgs));
if (empty(msgs)) {
if (postResult)
postInChannel(channel, "Done scanning " + discordChannelRef(channel.getIdLong()) + " (" + nMessages(scanned) + ")");
callF(whenDone);
ret;
}
scanned += l(msgs);
if (storeMsgs(msgs) && incremental) {
if (postResult)
postInChannel(channel, "Stopping incremental scan of " + discordChannelRef(channel.getIdLong()) + " after " + nMessages(scanned));
callF(whenDone);
ret;
}
run();
}, onQueueError);
}
}
// returns true if seen
Pair storeMsg(Message msg) {
if (msg == null) null;
Msg m, bool isNew = unpair uniq2(Msg, msgID := msg.getIdLong());
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 pair(m, !isNew);
}
// returns true if any seen
bool storeMsgs(L l) {
bool anySeen;
for (Message msg : l) {
if (pairB(storeMsg(m))) set anySeen;
}
ret anySeen;
}