|
|
|
@ -1,21 +1,15 @@ |
|
|
|
|
require 'mastodon' |
|
|
|
|
require 'sanitize' |
|
|
|
|
require 'awesome_print' |
|
|
|
|
|
|
|
|
|
class CrossPost |
|
|
|
|
class Mastodon |
|
|
|
|
def initialize(config) |
|
|
|
|
url = config['mastodon.url'] |
|
|
|
|
token = config['mastodon.token'] |
|
|
|
|
user = config['mastodon.user'] |
|
|
|
|
url = config['mastodon.url'] |
|
|
|
|
token = config['mastodon.token'] |
|
|
|
|
user = config['mastodon.user'] |
|
|
|
|
@user_url = URI.join(url, "/@#{user}").to_s |
|
|
|
|
@client = ::Mastodon::REST::Client.new base_url: url, bearer_token: token |
|
|
|
|
@stream = ::Mastodon::Streaming::Client.new base_url: url, bearer_token: token |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def post(text) |
|
|
|
|
post = @client.create_status text |
|
|
|
|
ap post |
|
|
|
|
@client = ::Mastodon::REST::Client.new base_url: url, bearer_token: token |
|
|
|
|
@stream = ::Mastodon::Streaming::Client.new base_url: url, bearer_token: token |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def feed(twitter) |
|
|
|
@ -23,17 +17,22 @@ class CrossPost |
|
|
|
|
begin |
|
|
|
|
case object |
|
|
|
|
when ::Mastodon::Status |
|
|
|
|
next if object.account.url != @user_url |
|
|
|
|
next if object.visibility != 'public' |
|
|
|
|
next if object.in_reply_to_id |
|
|
|
|
|
|
|
|
|
ap object |
|
|
|
|
next if reject? object |
|
|
|
|
twitter.post object |
|
|
|
|
end |
|
|
|
|
rescue => e |
|
|
|
|
$stderr.puts e |
|
|
|
|
#$stderr.puts e |
|
|
|
|
raise |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
private |
|
|
|
|
|
|
|
|
|
def reject?(status) |
|
|
|
|
status.account.url != @user_url or |
|
|
|
|
status.visibility != 'public' or |
|
|
|
|
status.in_reply_to_id |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|