Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

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
You can’t perform that action at this time.