Toot toooooooot (Bluesky-Mastodon cross-poster)

optional feature to extract links from quoted posts

Changed files
+33 -4
app
+1 -1
Gemfile
··· 2 2 3 3 gem 'didkit', '~> 0.2' 4 4 gem 'mastodon-api', git: 'https://github.com/mastodon/mastodon-api.git' 5 - gem 'minisky', '~> 0.4' 5 + gem 'minisky', '~> 0.5' 6 6 7 7 gem 'io-console', '~> 0.5' 8 8 gem 'json', '~> 2.5'
+1 -1
Gemfile.lock
··· 61 61 io-console (~> 0.5) 62 62 json (~> 2.5) 63 63 mastodon-api! 64 - minisky (~> 0.4) 64 + minisky (~> 0.5) 65 65 net-http (~> 0.2) 66 66 uri (~> 0.13) 67 67 yaml (~> 0.1)
+31 -2
app/tootify.rb
··· 1 1 require 'io/console' 2 + require 'yaml' 2 3 3 4 require_relative 'bluesky_account' 4 5 require_relative 'mastodon_account' 5 6 require_relative 'post_history' 6 7 7 8 class Tootify 9 + CONFIG_FILE = File.expand_path(File.join(__dir__, '..', 'config', 'tootify.yml')) 10 + 8 11 attr_accessor :check_interval 9 12 10 13 def initialize 11 14 @bluesky = BlueskyAccount.new 12 15 @mastodon = MastodonAccount.new 13 16 @history = PostHistory.new 17 + @config = load_config 14 18 @check_interval = 60 15 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 16 28 17 29 def login_bluesky(handle) 18 30 handle = handle.gsub(/^@/, '') ··· 120 132 repo, collection, rkey = quote_uri.split('/')[2..4] 121 133 122 134 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) 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) 125 146 end 126 147 end 127 148 ··· 162 183 end 163 184 164 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'] 165 194 end 166 195 167 196 def expand_facets(record)