Sha256: e3d353d34567f41de1e3c9e21943aa5342bdd42282bdb220e700615a9cb70c07
Contents?: true
Size: 1.23 KB
Versions: 1
Compression:
Stored size: 1.23 KB
Contents
#!/usr/bin/env ruby require 'pry' require 'set' def rate_limited?(response) pp response response[:error] == "ratelimited" end require 'async/rest/resource' 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}..." 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 1 end end page += 1 end end puts "Done"
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
async-rest-0.7.2 | examples/slack/clean.rb |