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

24
LINES

< > BotCompany Repo | #1001940 // slackReactionScore

JavaX fragment (include)

1  
static int slackReactionScore(S token, S channelID, S timestamp) {
2  
  S url = "https://slack.com/api/reactions.get";
3  
  S postData = "token=" + urlencode(token) + "&channel=" + urlencode(channelID) + "&timestamp=" + urlencode(timestamp);
4  
  S data = doPostWithTimeout(postData, url, slackSetTimeout_get());
5  
  Map map = jsonDecodeMap(data);
6  
  Map msg = cast map.get("message");
7  
  if (msg == null) ret 0;
8  
  //printStructure(msg);
9  
  L<Map> reactions = cast msg.get("reactions");
10  
  if (reactions == null) ret 0;
11  
  //printStructure(reactions);
12  
  int score = 0;
13  
  for (Map r : reactions) {
14  
    S name = cast r.get("name");
15  
    int count = (int) r.get("count");
16  
    if (litlist("confused").contains(name))
17  
      score -= count;
18  
    else 
19  
      score += count;
20  
    /*else 
21  
      print("Unknown reaction emoji: " + name);*/
22  
  }
23  
  ret score;
24  
}

Author comment

Began life as a copy of #1001938

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

No comments. add comment

Snippet ID: #1001940
Snippet name: slackReactionScore
Eternal ID of this version: #1001940/1
Text MD5: 8bbf72bba92993ab2a5dd76aaf938c4c
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-04-02 20:12:58
Source code size: 855 bytes / 24 lines
Pitched / IR pitched: No / No
Views / Downloads: 720 / 1202
Referenced in: [show references]