Skip to content

Instantly share code, notes, and snippets.

@tateisu
Last active September 25, 2019 07:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tateisu/920a26d73ebdfb485adac07a0f783c32 to your computer and use it in GitHub Desktop.
Save tateisu/920a26d73ebdfb485adac07a0f783c32 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;
# ワンライナーをdockerコンテナのrails console に送る
open(my $fh,"|-","docker-compose run --rm web bundle exec rails console") or die $!;
print $fh $cmd;
close($fh) or die $!;
@tateisu
Copy link
Author

tateisu commented Sep 16, 2019

rails console 直打ちなら

Account .where(domain:'pawoo.net',suspended_at:nil) .where('note like ?',"%\u{3081}\u{3063}\u{305f}\u{306b}Pawoo\u{3092}\u{4f7f}\u{3044}\u{307e}\u{305b}\u{3093}%") .map{ |account| SuspendAccountService.new.call(account, reserve_email: false) ;"#{account.username},#{account.domain}" }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment