Skip to content

Commit 209de94

Browse files
Gargronhiyuki2578
authored andcommitted
Add tootctl accounts follow ACCT (mastodon#9414)
Fix mastodon#9369
1 parent bd6cc39 commit 209de94

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

lib/mastodon/accounts_cli.rb

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,66 @@ def refresh(username = nil)
300300
end
301301
end
302302

303+
desc 'follow ACCT', 'Make all local accounts follow account specified by ACCT'
304+
long_desc <<-LONG_DESC
305+
Make all local accounts follow an account specified by ACCT. ACCT can be
306+
a simple username, in case of a local user. It can also be in the format
307+
username@domain, in case of a remote user.
308+
LONG_DESC
309+
def follow(acct)
310+
target_account = ResolveAccountService.new.call(acct)
311+
processed = 0
312+
failed = 0
313+
314+
if target_account.nil?
315+
say("Target account (#{acct}) could not be resolved", :red)
316+
exit(1)
317+
end
318+
319+
Account.local.without_suspended.find_each do |account|
320+
begin
321+
FollowService.new.call(account, target_account)
322+
processed += 1
323+
say('.', :green, false)
324+
rescue StandardError
325+
failed += 1
326+
say('.', :red, false)
327+
end
328+
end
329+
330+
say("OK, followed target from #{processed} accounts, skipped #{failed}", :green)
331+
end
332+
333+
desc 'unfollow ACCT', 'Make all local accounts unfollow account specified by ACCT'
334+
long_desc <<-LONG_DESC
335+
Make all local accounts unfollow an account specified by ACCT. ACCT can be
336+
a simple username, in case of a local user. It can also be in the format
337+
username@domain, in case of a remote user.
338+
LONG_DESC
339+
def unfollow(acct)
340+
target_account = Account.find_remote(*acct.split('@'))
341+
processed = 0
342+
failed = 0
343+
344+
if target_account.nil?
345+
say("Target account (#{acct}) was not found", :red)
346+
exit(1)
347+
end
348+
349+
target_account.followers.local.find_each do |account|
350+
begin
351+
UnfollowService.new.call(account, target_account)
352+
processed += 1
353+
say('.', :green, false)
354+
rescue StandardError
355+
failed += 1
356+
say('.', :red, false)
357+
end
358+
end
359+
360+
say("OK, unfollowed target from #{processed} accounts, skipped #{failed}", :green)
361+
end
362+
303363
private
304364

305365
def rotate_keys_for_account(account, delay = 0)

0 commit comments

Comments
 (0)