You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
1.0KB

  1. #!/usr/bin/env ruby
  2. require 'cross-post'
  3. require 'mastodon'
  4. require 'oauth2'
  5. require 'launchy'
  6. config = CrossPost::Config.new
  7. print 'Mastodon URL ? '
  8. url = gets.strip
  9. url = "https://#{url}" unless url.start_with? 'https://'
  10. config['mastodon.url'] = url
  11. client_id, client_secret = unless config['mastodon.consumer']
  12. token = SecureRandom.hex 64
  13. redirect_url = 'urn:ietf:wg:oauth:2.0:oob'
  14. client = Mastodon::REST::Client.new base_url: url, bearer_token: token
  15. app = client.create_app 'CrossPost', redirect_url,
  16. 'read write', 'https://git.imirhil.fr/aeris/cross-post/'
  17. [app.client_id, app.client_secret]
  18. else
  19. [config['mastodon.consumer.key'], config['mastodon.consumer.secret']]
  20. end
  21. client = OAuth2::Client.new client_id, client_secret, site: url
  22. url = client.auth_code.authorize_url redirect_uri: redirect_url
  23. Launchy.open url
  24. print 'Token ? '
  25. token = gets.chomp
  26. config['mastodon.token'] = token
  27. config.save