Toot toooooooot (Bluesky-Mastodon cross-poster)
1#!/usr/bin/env ruby
2
3require 'bundler/setup'
4require_relative 'app/tootify'
5
6def run(argv)
7 $stdout.sync = true
8
9 options, args = argv.partition { |x| x.start_with?('-') }
10
11 app = Tootify.new
12
13 options.each do |o|
14 if o.start_with?('--interval=')
15 app.check_interval = o.split('=')[1].to_i
16 end
17 end
18
19 case args.first
20 when 'login'
21 login(args[1])
22 when 'check'
23 app.sync
24 when 'watch'
25 app.watch
26 else
27 print_help
28 end
29end
30
31def print_help
32 puts "Usage: #{$PROGRAM_NAME} login mastodon@account | login @bluesky"
33 puts " #{$PROGRAM_NAME} check | watch"
34 exit 1
35end
36
37def login(name)
38 app = Tootify.new
39
40 if name =~ /\A[^@]+@[^@]+\z/
41 app.login_to_mastodon(name)
42 elsif name =~ /\A@?[^@]+\z/
43 app.login_to_bluesky(name)
44 elsif name.nil?
45 print_help
46 else
47 puts "Invalid handle: #{name.inspect}"
48 exit 1
49 end
50end
51
52run(ARGV)