!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(); retrieveHistory(channel, history, 0); 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; } /*void postMsgs(MessageChannel channel, L msgs) { postInChannel(channel, linesLL( "Got " + nMessages(msgs) + ".", first(msgs), "...", last(msgs) )); }*/ void retrieveHistory(MessageChannel channel, MessageHistory history, int n) { history.retrievePast(100).queue(msgs -> { temp enter(); print("Got msgs: " + l(msgs)); if (empty(msgs)) ret with postInChannel(channel, "Done (" + nMessages(n) + ")"); storeMsgs(msgs); retrieveHistory(channel, history, n+l(msgs)); }, onQueueError); } void storeMsgs(L l) { for (Message msg : l) cset(uniq(Msg, msgID := msg.getIdLong()), channelID := msg.getTextChannel().getIdLong(), userID := msg.getAuthor().getIdLong(), date := msg.getCreationTime().toEpochSecond(), edited := msg.isEdited() ? msg.getEditedTime().toEpochSecond() : 0, text := msg.getContentRaw()); } }