Menu Home

Mastodon: Anti-spam “search toots for strings” ruby script

pattern = 'google\.[a-z.]+/share\.google\?'
scope = :local          # :local or :remote (anything else for both).
since = 90.days.ago    # set to nil to search all time (slow on a big instance)

statuses = Status.unscoped
                 .joins(:account)
                 .where(deleted_at: nil)
                 .where('statuses.text ~* ?', pattern)

statuses = statuses.where('statuses.created_at > ?', since) if since

statuses = statuses.where(accounts: { domain: nil })     if scope == :local
statuses = statuses.where.not(accounts: { domain: nil }) if scope == :remote

counts   = statuses.group('statuses.account_id').count
accounts = Account.where(id: counts.keys).index_by(&:id)

counts.sort_by { |_, n| -n }.each do |id, n|
  puts "@#{accounts[id].acct} (#{n})"
end
nil

results in a nice list

Categories: Uncategorised

shlee

Leave a Reply

Your email address will not be published. Required fields are marked *

Your post must include a link to this post.

How does this work?
Write a response on your own website and include a link to this post. Then submit your response’s URL here. Your response may appear here after moderation. To update or remove it, edit or delete your original post and submit the same URL again. Learn more about Webmentions.