Sha256: 4a88515071952039cfd3bc8f9bf7ea8ca589afdcbc16cfd94ccd562c0c3a4252
Contents?: true
Size: 1.25 KB
Versions: 4
Compression:
Stored size: 1.25 KB
Contents
#!/usr/bin/env ruby require 'pry' require 'set' def rate_limited?(response) pp response response[:error] == "ratelimited" end require 'async/rest' URL = "https://slack.com/api" TOKEN = "xoxp-your-api-token" Async::REST::Resource.for(URL) do |resource| authenticated = resource.with(parameters: {token: TOKEN}) delete = authenticated.with(path: "chat.delete") page = 1 while true search = authenticated.with(path: "search.messages", parameters: {page: page, count: 100, query: "from:@username before:2019-02-15"}) representation = search.get messages = representation.value[:messages] matches = messages[:matches] puts "Found #{matches.count} messages on page #{page} out of #{messages[:total]}..." break if matches.empty? matches.each do |message| text = message[:text] channel_id = message[:channel][:id] channel_name = message[:channel][:name] timestamp = message[:ts] pp [timestamp, channel_name, text] message_delete = Async::REST::Representation.new( delete.with(parameters: {channel: channel_id, ts: timestamp}) ) response = message_delete.post if rate_limited?(response.read) puts "Rate limiting..." Async::Task.current.sleep 10 end end page += 1 end end puts "Done"
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
async-rest-0.9.0 | examples/slack/clean.rb |
async-rest-0.8.2 | examples/slack/clean.rb |
async-rest-0.8.1 | examples/slack/clean.rb |
async-rest-0.8.0 | examples/slack/clean.rb |