From f0506110c4543f34629e9950e71d58d23e50c619 Mon Sep 17 00:00:00 2001 From: multiple creatures Date: Sat, 20 Jul 2019 10:33:43 -0500 Subject: rewrite `admin:` bangtags to use moderation functions from bangtag helper module --- app/lib/bangtags.rb | 121 ++++++---------------------------------------------- 1 file changed, 14 insertions(+), 107 deletions(-) (limited to 'app') diff --git a/app/lib/bangtags.rb b/app/lib/bangtags.rb index a54a20748..f853a49a9 100644 --- a/app/lib/bangtags.rb +++ b/app/lib/bangtags.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class Bangtags - #include BangtagHelper + include BangtagHelper attr_reader :status, :account def initialize(status) @@ -549,7 +549,7 @@ class Bangtags @status.content_type = 'text/markdown' @chunks << "\n# #!admin:#{cmd[1].downcase}:\n
\n" case cmd[1].downcase - when 'silence', 'unsilence', 'suspend', 'unsuspend', 'forgive' + when 'silence', 'unsilence', 'suspend', 'unsuspend', 'force_unlisted', 'allow_public', 'force_sensitive', 'allow_nonsensitive', 'reset', 'forgive' @tf_cmds.push(cmd) @component_stack.push(:tf) when 'exec', 'eval' @@ -596,7 +596,8 @@ class Bangtags next unless @account.user.admin? next if tf_cmd[1].nil? || chunk.start_with?('`admin:') output = [] - case tf_cmd[1].downcase + action = tf_cmd[1].downcase + case action when 'announce' announcer = ENV['ANNOUNCEMENTS_USER'] if announcer.blank? @@ -622,113 +623,19 @@ class Bangtags RemoveStatusService.new.call(s) end end - when 'silence' + when 'silence', 'unsilence', 'suspend', 'unsuspend', 'force_unlisted', 'allow_public', 'force_sensitive', 'allow_nonsensitive', 'reset', 'forgive' + action = 'reset' if action == 'forgive' chunk.split.each do |c| if c.start_with?('@') - parts = c.split('@')[1..2] - a = Account.find_by(username: parts[0], domain: parts[1]) - if a.nil? || a.id == @account.id - output << "Skipped @#{parts.join('@')}." - next - end - output << "Silenced @#{parts.join('@')}." - Admin::ActionLog.create(account: @account, action: :silence, target: a) - a.silence! - a.save - elsif c.match?(/^[\w\-]+\.[\w\-]+(?:\.[\w\-]+)*$/) - c.downcase! - if c.end_with?('monsterpit.net', 'tailma.ws') - output << "Skipped #{c}." - next - end - begin - code = Request.new(:head, "https://#{c}").perform(&:code) - rescue - output << "Skipped #{c}." - next - end - if [404, 410].include?(code) - output << "Skipped #{c}." - next - end - domain_block = DomainBlock.find_or_create_by(domain: c) - domain_block.severity = "silence" - domain_block.save - output << "Silenced #{c}." - Admin::ActionLog.create(account: @account, action: :create, target: domain_block) - BlockDomainService.new.call(domain_block) - end - end - output = ['No action.'] if output.blank? - chunk = output.join("\n") + "\n" - when 'forgive', 'unsilence', 'unsuspend' - chunk.split.each do |c| - if c.start_with?('@') - parts = c.split('@')[1..2] - a = Account.find_by(username: parts[0], domain: parts[1]) - if a.nil? || a.id == @account.id - output << "Skipped @#{parts.join('@')}." - next - end - output << "Reset policy for @#{parts.join('@')}." - Admin::ActionLog.create(account: @account, action: :unsilence, target: a) - a.unsilence! - Admin::ActionLog.create(account: @account, action: :unsuspend, target: a) - a.unsuspend! - a.save - elsif c.match?(/^[\w\-]+\.[\w\-]+(?:\.[\w\-]+)*$/) - c.downcase! - if c.end_with?('monsterpit.net', 'tailma.ws') - output << "Skipped #{c}." - next - end - domain_block = DomainBlock.find_by(domain: c) - if domain_block.nil? - output << "Skipped #{c}." - next - end - output << "Reset policy for #{c}." - Admin::ActionLog.create(account: @account, action: :destroy, target: domain_block) - UnblockDomainService.new.call(domain_block) + account_parts = c.split('@')[1..2] + successful = account_policy(account_parts[0], account_parts[1], action) + else + successful = domain_policy(c, action) end - end - output = ['No action.'] if output.blank? - chunk = output.join("\n") + "\n" - when 'suspend' - chunk.split.each do |c| - if c.start_with?('@') - parts = c.split('@')[1..2] - a = Account.find_by(username: parts[0], domain: parts[1]) - if a.nil? || a.id == @account.id - output << "Skipped @#{parts.join('@')}." - next - end - output << "Suspended @#{parts.join('@')}." - Admin::ActionLog.create(account: @account, action: :suspend, target: a) - SuspendAccountService.new.call(a, include_user: true) - elsif c.match?(/\A[\w\-]+\.[\w\-]+(?:\.[\w\-]+)*\Z/) - c.downcase! - if c.end_with?('monsterpit.net', 'tailma.ws') - output << "Skipped #{c}." - next - end - begin - code = Request.new(:head, "https://#{c}").perform(&:code) - rescue - output << "Skipped #{c}." - next - end - if [404, 410].include?(code) - output << "Skipped #{c}." - next - end - domain_block = DomainBlock.find_or_create_by(domain: c) - domain_block.severity = "suspend" - domain_block.reject_media = true - domain_block.save - output << "Suspended #{c}." - Admin::ActionLog.create(account: @account, action: :create, target: domain_block) - BlockDomainService.new.call(domain_block) + if successful + output << "\u2705 #{c}" + else + output << "\u274c #{c}" end end output = ['No action.'] if output.blank? -- cgit