Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

38
LINES

< > BotCompany Repo | #1002183 // multiSlurp - multiple Slack slurps for one channel until the job is done!

JavaX fragment (include)

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  
}

Author comment

Began life as a copy of #1002173

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

Comments [hide]

ID Author/Program Comment Date
1202 stefan TODO: go forward also 2016-01-01 22:31:27

add comment

Snippet ID: #1002183
Snippet name: multiSlurp - multiple Slack slurps for one channel until the job is done!
Eternal ID of this version: #1002183/1
Text MD5: 038b0ee6de84fea2c8c8df54308bd4a1
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-12-25 16:43:52
Source code size: 1272 bytes / 38 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 875 / 1083
Referenced in: [show references]