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

24
LINES

< > BotCompany Repo | #1001940 // slackReactionScore

JavaX fragment (include)

static int slackReactionScore(S token, S channelID, S timestamp) {
  S url = "https://slack.com/api/reactions.get";
  S postData = "token=" + urlencode(token) + "&channel=" + urlencode(channelID) + "&timestamp=" + urlencode(timestamp);
  S data = doPostWithTimeout(postData, url, slackSetTimeout_get());
  Map map = jsonDecodeMap(data);
  Map msg = cast map.get("message");
  if (msg == null) ret 0;
  //printStructure(msg);
  L<Map> reactions = cast msg.get("reactions");
  if (reactions == null) ret 0;
  //printStructure(reactions);
  int score = 0;
  for (Map r : reactions) {
    S name = cast r.get("name");
    int count = (int) r.get("count");
    if (litlist("confused").contains(name))
      score -= count;
    else 
      score += count;
    /*else 
      print("Unknown reaction emoji: " + name);*/
  }
  ret score;
}

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: 708 / 1189
Referenced in: [show references]