public
Last active

Nuke HipChat 1:1 History

  • Download Gist
b00m.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
require 'rubygems'
require 'mechanize'
 
account = {
:email => "jpr5@serv.io",
:password => "balls",
}
 
agent = Mechanize.new
site = agent.post("https://www.hipchat.com/sign_in", account).uri.host
 
# get numeric UID
member_id = agent.get("https://#{site}/account").
search('img[alt="Your photo"]').first["src"].match(%r{photos/(\d+)})[1]
 
# determine intervals
registered_around = agent.get("https://#{site}/members/#{member_id}").
search('li:contains("Signed up")').text.sub(/Signed up: /, '')
registered_on = Date.parse(`date -d "#{registered_around}"`.chomp)
intervals = (registered_on..Date.today).map { |d| d.strftime("/%Y/%m/%d") }
 
# identify 1:1 chats
members = agent.get("https://#{site}/history").search("ul.members").children.search("a").
map { |m| m.attributes["href"].value }.
reject { |m| m =~ /#{member_id}/ }
 
# walk intervals for each member, capture message_id's
messages = {}
 
members.each do |member|
intervals.each do |interval|
messages[member] ||= []
messages[member] += agent.get("https://#{site}#{member}#{interval}").
search("input[name=message_id]").map { |m| m["value"] }
end
end
 
messages.each do |member, msg_ids|
msg_ids.each do |msg_id|
agent.post("https://#{site}#{member}", {:action => "delete", :message_id => msg_id})
end
end

jpr5 does this still work? It feels like they have closed a few of these routes

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.