Skip to content

Instantly share code, notes, and snippets.

@rosylilly
Forked from tateisu/removeSpam.pl
Last active September 25, 2019 07:12
Show Gist options
  • Save rosylilly/2b880282ed59bbd1b8665844f5b4b89e to your computer and use it in GitHub Desktop.
Save rosylilly/2b880282ed59bbd1b8665844f5b4b89e to your computer and use it in GitHub Desktop.
suspend user who in pawoo.net and his note like 'めったにPawooを使いません'.
#!/usr/bin/perl --
use strict;
use warnings;
use utf8;
# mastodonのdockerコンテナの rails console はreadline がUS-ASCIIなので、文字列リテラルはエスケープが必要
sub escapeNonAscii($){
my($a) = @_;
$a =~ s/([\x{80}-\x{fffff}])/"\\u{".sprintf("%x",ord $1)."}"/ge;
$a;
}
my $phrase = escapeNonAscii quotemeta 'めったにPawooを使いません';
# rails console に送るコマンドはワンライナーにする必要がある
my $cmd = <<"END";
Account
.where(domain:'pawoo.net',suspended_at:nil)
.where('note like ?',"%$phrase%")
.map{ |account|
SuspendAccountService.new.call(account, reserve_email: false)
;"#{account.username},#{account.domain}"
}
END
# ワンライナーを整形する
$cmd =~ s/^\s*#.+/ /gm;
$cmd =~ s/[\s\x0d\x0a]+/ /g;
# ワンライナーをrails console に送る
open(my $fh,"|-","bundle exec rails console") or die $!;
print $fh $cmd;
close($fh) or die $!;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment