port @zac@computerfox.xyz's `silence` to `BlocklistHelper`
parent
9a3c4bc051
commit
f86a3314f7
|
@ -1,8 +1,12 @@
|
||||||
module BlocklistHelper
|
module BlocklistHelper
|
||||||
|
FEDIVERSE_SPACE_URLS = [
|
||||||
|
"https://fediverse.network/mastodon?build=gab",
|
||||||
|
]
|
||||||
|
|
||||||
def merged_blocklist
|
def merged_blocklist
|
||||||
# ordered by preference
|
# ordered by preference
|
||||||
# prefer vulpine b/c they have easy-to-parse reason text
|
# prefer vulpine b/c they have easy-to-parse reason text
|
||||||
blocklist = vulpine_club_blocks | dialup_express_blocks | ten_forward_blocks
|
blocklist = vulpine_club_blocks | dialup_express_blocks | ten_forward_blocks | fediverse_space_blocks
|
||||||
blocklist.uniq { |entry| entry[:domain] }
|
blocklist.uniq { |entry| entry[:domain] }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -49,4 +53,27 @@ module BlocklistHelper
|
||||||
{domain: domain, severity: severity.to_sym, reject_media: reject_media, reason: reason}
|
{domain: domain, severity: severity.to_sym, reject_media: reject_media, reason: reason}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# shamelessly adapted from @zac@computerfox.xyz's `silence` tool
|
||||||
|
# <https://github.com/theZacAttacks/silence/blob/master/silence>
|
||||||
|
# which you'll find useful if you're a non-monsterfork mastoadmin
|
||||||
|
def fediverse_space_fetch_domains(url)
|
||||||
|
body = Request.new(:get, url).perform do |response|
|
||||||
|
response.code != 200 ? nil : response.body_with_limit(66.kilobytes)
|
||||||
|
end
|
||||||
|
|
||||||
|
return [] unless body.present?
|
||||||
|
|
||||||
|
document = Nokogiri::HTML(body)
|
||||||
|
document.css('table.table-condensed td a').collect { |link| link.content.strip }
|
||||||
|
end
|
||||||
|
|
||||||
|
def fediverse_space_blocks
|
||||||
|
domains = FEDIVERSE_SPACE_URLS.flat_map { |url| fediverse_space_fetch_domains(url) }
|
||||||
|
domains.uniq!
|
||||||
|
|
||||||
|
domains.map! do |domain|
|
||||||
|
{domain: domain, severity: :suspend, reason: '(imported from fediverse.space)'}
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue