Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
require 'rubygems'
require 'mechanize'
require 'httparty'
# Ugly code, for an ugly hack.
# Hey, if Lighthouse didn't suck then none of this would happen.
# It's been lotsa fun coding it though, so I suppose I should be thankful for the "opportunity"
def locate_form_by_button(page, value)
page.forms.detect { |f| f.buttons.detect { |b| b.value == value } }
class String
def underscore
self.downcase.gsub(" ", "_")
# The IDs of all the known bastards
bastards = [119236]
# Setup mechanize
agent =
# Load configuration
config = YAML.load_file(File.join(ENV["HOME"] + "/.lighthouse.yml"))
# Logging in
page = agent.get('')
# There's two forms, use the login form not the open id form
login_form = page.forms[1] = config["email"]
login_form.password = config["password"]
page = agent.submit(login_form, login_form.buttons.first)
bastards.each do |bastard|
page = agent.get("{bastard}")
pp page.title
# Get all their ticket comments
links = { |l| l.href =~ /tickets\/\d+/ }.map(&:href).uniq
links.each do |link|
page = agent.get(link)
# Detect if the spammer has changed the title
id, version = /#ticket-(\d+)-(\d+)/.match(link).to_a
comment =
# Get the changes for this ticket and revert them.
# Because Lighthouse is too fucking stupid to revert (all) the changes of a ticket when you delete it.
changes =".ticket-changes li")
update_ticket_form = locate_form_by_button(page, "Update ticket")
update_ticket_action = "{update_ticket_form.action}"
p "Updating: #{update_ticket_action}"
authenticity_token = update_ticket_form.fields.detect { |f| == "authenticity_token" }.value
params = {} do |change|
matches = /(.*?) changed from (.*?) to (.*?)$/.match(change)
field = matches[1].split(" ")[1..-1].join(" ").underscore
original_value = matches[2].gsub("\u0093", "").gsub("\u0094", "").gsub("\302\223", "").gsub("\302\224", "")
new_value = matches[3]
params[field] = original_value
# If assigned user has changed, switch it back
user_select_box = update_ticket_form.fields.detect { |f| == "ticket[assigned_user_id]" }
assigned_user = params.delete("assigned_user")
if !assigned_user.blank?
params["assigned_user_id"] = user_select_box.options.detect { |o| o.text == assigned_user }.select
# If tags changed, switch them back
tag = update_ticket_form.fields.detect { |f| == "ticket[tag]"}
tag.value = params["tag"] if params["tag"]
# If title changed, switch it back
title = update_ticket_form.fields.detect { |f| == "ticket[title]"}
title.value = params["title"] if params["title"]
comment = update_ticket_form.fields.detect { |f| == "ticket[body]" }
comment.value = "Automatic cleanup of spam."
# Now we delete the motherfucker.
numbers = /#ticket-(\d+)-(\d+)/.match(link)
version_to_delete_url = "{update_ticket_form.action}/versions/#{numbers[2]}"
page = agent.get(version_to_delete_url)
# begin
delete_form = locate_form_by_button(page, "Yes, delete this ticket comment.")
agent.submit(delete_form, delete_form.buttons.first)
# rescue
# next
# end
rescue Exception => e
p e.message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.