Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. require "slack"
  3. require "date"
  4.  
  5. Slack.configure { |config|
  6. config.token = "token"
  7. }
  8.  
  9. target_channel = "target_channel"
  10. bot_id = "bot_id"
  11. time_stamp_list = []
  12.  
  13. groups = Slack.channels_list()["groups"]
  14. groups.each { |group|
  15. if group["name"] == target_channel then
  16. messages = Slack.groups_history(channel: group["id"])["messages"]
  17. messages.each { |message|
  18. if message["bot_id"] == bot_id then
  19. ts = message["ts"]
  20. puts DateTime.strptime(ts, "%s")
  21. time_stamp_list << ts
  22. end
  23. }
  24. end
  25. }
  26.  
  27. loop {
  28. groups = Slack.groups_list()["groups"]
  29. groups.each { |group|
  30. if group["name"] == target_channel then
  31. group_id = group["id"]
  32. messages = Slack.groups_history(channel: group_id)["messages"]
  33. messages.each { |message|
  34. ts = message["ts"]
  35. if message["bot_id"] == bot_id and not time_stamp_list.include? ts then
  36. puts DateTime.strptime(ts, "%s")
  37. time_stamp_list << ts
  38. Slack.pins_add(channel: group_id, timestamp: ts)
  39. end
  40. }
  41. end
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement