You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.1 KiB

  1. # frozen_string_literal: true
  2. require_relative '../../config/boot'
  3. require_relative '../../config/environment'
  4. require_relative 'cli_helper'
  5. module Mastodon
  6. class DomainsCLI < Thor
  7. def self.exit_on_failure?
  8. true
  9. end
  10. option :dry_run, type: :boolean
  11. desc 'purge DOMAIN', 'Remove accounts from a DOMAIN without a trace'
  12. long_desc <<-LONG_DESC
  13. Remove all accounts from a given DOMAIN without leaving behind any
  14. records. Unlike a suspension, if the DOMAIN still exists in the wild,
  15. it means the accounts could return if they are resolved again.
  16. LONG_DESC
  17. def purge(domain)
  18. removed = 0
  19. dry_run = options[:dry_run] ? ' (DRY RUN)' : ''
  20. Account.where(domain: domain).find_each do |account|
  21. unless options[:dry_run]
  22. SuspendAccountService.new.call(account)
  23. account.destroy
  24. end
  25. removed += 1
  26. say('.', :green, false)
  27. end
  28. DomainBlock.where(domain: domain).destroy_all
  29. say
  30. say("Removed #{removed} accounts#{dry_run}", :green)
  31. end
  32. end
  33. end