Toot toooooooot (Bluesky-Mastodon cross-poster)

optional feature to extract links from quoted posts

Changed files
+33 -4
app
+1 -1
Gemfile
··· 2 3 gem 'didkit', '~> 0.2' 4 gem 'mastodon-api', git: 'https://github.com/mastodon/mastodon-api.git' 5 - gem 'minisky', '~> 0.4' 6 7 gem 'io-console', '~> 0.5' 8 gem 'json', '~> 2.5'
··· 2 3 gem 'didkit', '~> 0.2' 4 gem 'mastodon-api', git: 'https://github.com/mastodon/mastodon-api.git' 5 + gem 'minisky', '~> 0.5' 6 7 gem 'io-console', '~> 0.5' 8 gem 'json', '~> 2.5'
+1 -1
Gemfile.lock
··· 61 io-console (~> 0.5) 62 json (~> 2.5) 63 mastodon-api! 64 - minisky (~> 0.4) 65 net-http (~> 0.2) 66 uri (~> 0.13) 67 yaml (~> 0.1)
··· 61 io-console (~> 0.5) 62 json (~> 2.5) 63 mastodon-api! 64 + minisky (~> 0.5) 65 net-http (~> 0.2) 66 uri (~> 0.13) 67 yaml (~> 0.1)
+31 -2
app/tootify.rb
··· 1 require 'io/console' 2 3 require_relative 'bluesky_account' 4 require_relative 'mastodon_account' 5 require_relative 'post_history' 6 7 class Tootify 8 attr_accessor :check_interval 9 10 def initialize 11 @bluesky = BlueskyAccount.new 12 @mastodon = MastodonAccount.new 13 @history = PostHistory.new 14 @check_interval = 60 15 end 16 17 def login_bluesky(handle) 18 handle = handle.gsub(/^@/, '') ··· 120 repo, collection, rkey = quote_uri.split('/')[2..4] 121 122 if collection == 'app.bsky.feed.post' 123 - bsky_url = bsky_post_link(repo, rkey) 124 - append_link(text, bsky_url) unless text.include?(bsky_url) 125 end 126 end 127 ··· 162 end 163 164 @mastodon.post_status(text, media_ids, mastodon_parent_id) 165 end 166 167 def expand_facets(record)
··· 1 require 'io/console' 2 + require 'yaml' 3 4 require_relative 'bluesky_account' 5 require_relative 'mastodon_account' 6 require_relative 'post_history' 7 8 class Tootify 9 + CONFIG_FILE = File.expand_path(File.join(__dir__, '..', 'config', 'tootify.yml')) 10 + 11 attr_accessor :check_interval 12 13 def initialize 14 @bluesky = BlueskyAccount.new 15 @mastodon = MastodonAccount.new 16 @history = PostHistory.new 17 + @config = load_config 18 @check_interval = 60 19 end 20 + 21 + def load_config 22 + if File.exist?(CONFIG_FILE) 23 + YAML.load(File.read(CONFIG_FILE)) 24 + else 25 + {} 26 + end 27 + end 28 29 def login_bluesky(handle) 30 handle = handle.gsub(/^@/, '') ··· 132 repo, collection, rkey = quote_uri.split('/')[2..4] 133 134 if collection == 'app.bsky.feed.post' 135 + link_to_append = bsky_post_link(repo, rkey) 136 + 137 + if @config['extract_link_from_quotes'] 138 + quoted_record = fetch_record_by_at_uri(quote_uri) 139 + 140 + if link_from_quote = link_embed(quoted_record) 141 + link_to_append = link_from_quote 142 + end 143 + end 144 + 145 + append_link(text, link_to_append) unless text.include?(link_to_append) 146 end 147 end 148 ··· 183 end 184 185 @mastodon.post_status(text, media_ids, mastodon_parent_id) 186 + end 187 + 188 + def fetch_record_by_at_uri(quote_uri) 189 + repo, collection, rkey = quote_uri.split('/')[2..4] 190 + pds = DID.new(repo).get_document.pds_endpoint 191 + sky = Minisky.new(pds, nil) 192 + resp = sky.get_request('com.atproto.repo.getRecord', { repo: repo, collection: collection, rkey: rkey }) 193 + resp['value'] 194 end 195 196 def expand_facets(record)