rewrite repeated domain maps to use a helper function & make vulpine.club yaml url a variable
parent
f86a3314f7
commit
879166633c
|
@ -1,7 +1,6 @@
|
||||||
module BlocklistHelper
|
module BlocklistHelper
|
||||||
FEDIVERSE_SPACE_URLS = [
|
FEDIVERSE_SPACE_URLS = ["https://fediverse.network/mastodon?build=gab"]
|
||||||
"https://fediverse.network/mastodon?build=gab",
|
VULPINE_CLUB_URL = "https://raw.githubusercontent.com/vulpineclub/vulpineclub.github.io/master/_data/blocks.yml"
|
||||||
]
|
|
||||||
|
|
||||||
def merged_blocklist
|
def merged_blocklist
|
||||||
# ordered by preference
|
# ordered by preference
|
||||||
|
@ -10,15 +9,19 @@ module BlocklistHelper
|
||||||
blocklist.uniq { |entry| entry[:domain] }
|
blocklist.uniq { |entry| entry[:domain] }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def domain_map(domains, reason)
|
||||||
|
domains.map! do |domain|
|
||||||
|
{domain: domain, severity: :suspend, reason: reason}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def dialup_express_blocks
|
def dialup_express_blocks
|
||||||
admin_id = Account.find_remote('xenon', 'sleeping.town')&.id
|
admin_id = Account.find_remote('xenon', 'sleeping.town')&.id
|
||||||
return [] if admin_id.nil?
|
return [] if admin_id.nil?
|
||||||
|
|
||||||
domains = ActiveRecord::Base.connection.select_values("SELECT unnest(regexp_matches(text, '\\m[\\w\\-]+\\.[\\w\-]+(?:\\.[\\w\\-]+)*', 'g')) FROM statuses WHERE account_id = #{admin_id.to_i} AND NOT reply AND created_at >= (NOW() - INTERVAL '2 days') AND tsv @@ to_tsquery('new <-> dialup <-> express <2> block') EXCEPT SELECT domain FROM domain_blocks")
|
domains = ActiveRecord::Base.connection.select_values("SELECT unnest(regexp_matches(text, '\\m[\\w\\-]+\\.[\\w\-]+(?:\\.[\\w\\-]+)*', 'g')) FROM statuses WHERE account_id = #{admin_id.to_i} AND NOT reply AND created_at >= (NOW() - INTERVAL '2 days') AND tsv @@ to_tsquery('new <-> dialup <-> express <2> block') EXCEPT SELECT domain FROM domain_blocks")
|
||||||
|
|
||||||
domains.map! do |domain|
|
domain_map(domains, "Imported from <https://dialup.express>.")
|
||||||
{domain: domain, severity: :suspend, reason: '(imported from dialup.express)'}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def ten_forward_blocks
|
def ten_forward_blocks
|
||||||
|
@ -27,15 +30,11 @@ module BlocklistHelper
|
||||||
|
|
||||||
domains = ActiveRecord::Base.connection.select_values("SELECT unnest(regexp_matches(text, '\\m[\\w\\-]+\\.[\\w\-]+(?:\\.[\\w\\-]+)*', 'g')) FROM statuses WHERE account_id = #{admin_id.to_i} AND NOT reply AND created_at >= (NOW() - INTERVAL '2 days') AND tsv @@ to_tsquery('ten <-> forward <-> moderation <-> announcement') EXCEPT SELECT domain FROM domain_blocks")
|
domains = ActiveRecord::Base.connection.select_values("SELECT unnest(regexp_matches(text, '\\m[\\w\\-]+\\.[\\w\-]+(?:\\.[\\w\\-]+)*', 'g')) FROM statuses WHERE account_id = #{admin_id.to_i} AND NOT reply AND created_at >= (NOW() - INTERVAL '2 days') AND tsv @@ to_tsquery('ten <-> forward <-> moderation <-> announcement') EXCEPT SELECT domain FROM domain_blocks")
|
||||||
|
|
||||||
domains.map! do |domain|
|
domain_map(domains, "Imported from <https://ten.forward>.")
|
||||||
{domain: domain, severity: :suspend, reason: '(imported from ten.forward)'}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def vulpine_club_blocks
|
def vulpine_club_blocks
|
||||||
url = "https://raw.githubusercontent.com/vulpineclub/vulpineclub.github.io/master/_data/blocks.yml"
|
body = Request.new(:get, VULPINE_CLUB_URL).perform do |response|
|
||||||
|
|
||||||
body = Request.new(:get, url).perform do |response|
|
|
||||||
response.code != 200 ? nil : response.body_with_limit(66.kilobytes)
|
response.code != 200 ? nil : response.body_with_limit(66.kilobytes)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -49,7 +48,7 @@ module BlocklistHelper
|
||||||
reject_media = 'nomedia'.in?(severity)
|
reject_media = 'nomedia'.in?(severity)
|
||||||
severity = (severity[0].nil? || severity[0] == 'nomedia') ? 'noop' : severity[0]
|
severity = (severity[0].nil? || severity[0] == 'nomedia') ? 'noop' : severity[0]
|
||||||
|
|
||||||
reason = "(imported from vulpine.club) #{entry['reason']}#{entry['link'].present? ? " (#{entry['link']})" : ''}".rstrip
|
reason = "Imported from <https://vulpine.club>: \"#{entry['reason']}\"#{entry['link'].present? ? " (#{entry['link']})" : ''}".rstrip
|
||||||
{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
|
||||||
|
@ -72,8 +71,6 @@ module BlocklistHelper
|
||||||
domains = FEDIVERSE_SPACE_URLS.flat_map { |url| fediverse_space_fetch_domains(url) }
|
domains = FEDIVERSE_SPACE_URLS.flat_map { |url| fediverse_space_fetch_domains(url) }
|
||||||
domains.uniq!
|
domains.uniq!
|
||||||
|
|
||||||
domains.map! do |domain|
|
domain_map(domains, "Imported from <https://fediverse.space>.")
|
||||||
{domain: domain, severity: :suspend, reason: '(imported from fediverse.space)'}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue