Advertisement
Guest User

Untitled

a guest
Nov 17th, 2017
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Nim 1.05 KB | None | 0 0
  1. #Code checks to see what msgType a SlackMessage object has and process it accordingly
  2.  
  3. #Returns a SlackMessage object  
  4. result = self.server.apiCall(request=request, timeout=timeout, payload=payload)
  5. echo $(result.ok)
  6. echo result.text
  7.  
  8. #Save SlackMessage to var so we can use it inside msgTypePred's scope
  9. var r = result
  10.  
  11. #Defines predicate for any() call
  12. proc msgTypePred(x: string): bool {.inline.} = return cmpIgnoreCase(x, r.msgtype) == 0
  13.  
  14. #Check if we have any groups that need to be added
  15. if cmpIgnoreCase(result.msgtype, "im.open") == 0:
  16.   if result.ok and result.ok == true:
  17.     discard self.server.attachChannel(result.user.name, result.channel.id)
  18. #Substitute msgTypePred call for inline "proc (x: string): bool {.inline.} = return cmpIgnoreCase(x, r.msgtype) == 0" and it fails
  19. elif any(@["mpim.open", "groups.create", "groups.createchild"], msgTypePred):
  20.   if result.ok and result.ok == true:
  21.     discard self.server.attachChannel(
  22.       name=result.user.name,
  23.       user_id=result.user.id,
  24.       members=payload["group"]["members"]
  25.     )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement