1 | // slurp whole channel at once
|
2 |
|
3 | static L<SlackMsg> multiSlurp(S channelName, S token) {
|
4 | ret multiSlurp(channelName, token, null, null);
|
5 | }
|
6 |
|
7 | // inclusive is always false
|
8 | // slurp a part of the channel (everything > oldest and < latest)
|
9 | // channelName can also by the ID (starting with "C")
|
10 |
|
11 | static L<SlackMsg> multiSlurp(S channelName, S token, S oldest, S latest) {
|
12 | S channelID = channelName;
|
13 | if (!channelName.startsWith("C")) {
|
14 | Map<S, S> channels = slackGetChannelIDs(token);
|
15 | channelName = dropPrefix("#", channelName);
|
16 | channelID = channels.get(channelName);
|
17 | }
|
18 | if (channelID == null) fail("Channel not found: " + channelName);
|
19 | int limit = 1000;
|
20 | L<SlackMsg> l;
|
21 | new L<L<SlackMsg>> all;
|
22 | int n = 0; // safety switch #1 - never suck more than 100.000 msgs
|
23 | do {
|
24 | l = slackSlurp(channelID, token, limit, oldest, latest, false);
|
25 | if (empty(l)) break;
|
26 | S newLatest = first(l).ts;
|
27 | assertNotNull(newLatest);
|
28 |
|
29 | // safety switch #2
|
30 | if (latest != null) assertTrue(cmp(latest, newLatest) > 0);
|
31 |
|
32 | latest = newLatest;
|
33 | print("latest=" + latest);
|
34 | print(l(l) + " messages slurped from #" + channelName);
|
35 | all.add(l);
|
36 | } while (++n < 100);
|
37 | ret concatLists(reversedList(all));
|
38 | }
|