skyfall 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -0
- data/README.md +182 -29
- data/example/block_tracker.rb +1 -1
- data/example/{monitor_phrases.rb → jet_monitor_phrases.rb} +3 -2
- data/example/print_all_posts.rb +1 -1
- data/example/push_notifications.rb +1 -1
- data/lib/skyfall/car_archive.rb +13 -12
- data/lib/skyfall/collection.rb +26 -0
- data/lib/skyfall/{messages → firehose}/account_message.rb +3 -1
- data/lib/skyfall/{messages → firehose}/commit_message.rb +9 -3
- data/lib/skyfall/firehose/handle_message.rb +14 -0
- data/lib/skyfall/firehose/identity_message.rb +9 -0
- data/lib/skyfall/{messages → firehose}/info_message.rb +3 -1
- data/lib/skyfall/{messages → firehose}/labels_message.rb +2 -2
- data/lib/skyfall/{messages/websocket_message.rb → firehose/message.rb} +13 -11
- data/lib/skyfall/firehose/operation.rb +58 -0
- data/lib/skyfall/firehose/tombstone_message.rb +11 -0
- data/lib/skyfall/firehose/unknown_message.rb +6 -0
- data/lib/skyfall/firehose.rb +79 -0
- data/lib/skyfall/jetstream/account_message.rb +19 -0
- data/lib/skyfall/jetstream/commit_message.rb +16 -0
- data/lib/skyfall/jetstream/identity_message.rb +15 -0
- data/lib/skyfall/jetstream/message.rb +50 -0
- data/lib/skyfall/jetstream/operation.rb +58 -0
- data/lib/skyfall/jetstream/unknown_message.rb +6 -0
- data/lib/skyfall/jetstream.rb +121 -0
- data/lib/skyfall/stream.rb +39 -59
- data/lib/skyfall/version.rb +1 -1
- data/lib/skyfall.rb +4 -2
- metadata +21 -14
- data/example/follower_tracker.rb +0 -84
- data/lib/skyfall/messages/handle_message.rb +0 -12
- data/lib/skyfall/messages/identity_message.rb +0 -7
- data/lib/skyfall/messages/tombstone_message.rb +0 -9
- data/lib/skyfall/messages/unknown_message.rb +0 -4
- data/lib/skyfall/operation.rb +0 -74
data/example/follower_tracker.rb
DELETED
@@ -1,84 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
# Example: track when people follow and unfollow your account.
|
4
|
-
|
5
|
-
# load skyfall from a local folder - you normally won't need this
|
6
|
-
$LOAD_PATH.unshift(File.expand_path('../lib', __dir__))
|
7
|
-
|
8
|
-
require 'json'
|
9
|
-
require 'open-uri'
|
10
|
-
require 'skyfall'
|
11
|
-
|
12
|
-
$monitored_did = ARGV[0]
|
13
|
-
|
14
|
-
if $monitored_did.to_s.empty?
|
15
|
-
puts "Usage: #{$PROGRAM_NAME} <monitored_did>"
|
16
|
-
exit 1
|
17
|
-
elsif ARGV[0] !~ /^did:plc:[a-z0-9]{24}$/
|
18
|
-
puts "Not a valid DID: #{$monitored_did}"
|
19
|
-
exit 1
|
20
|
-
end
|
21
|
-
|
22
|
-
sky = Skyfall::Stream.new('bsky.network', :subscribe_repos)
|
23
|
-
|
24
|
-
sky.on_connect { puts "Connected, monitoring #{$monitored_did}" }
|
25
|
-
sky.on_disconnect { puts "Disconnected" }
|
26
|
-
sky.on_reconnect { puts "Reconnecting..." }
|
27
|
-
sky.on_error { |e| puts "ERROR: #{e}" }
|
28
|
-
|
29
|
-
sky.on_message do |msg|
|
30
|
-
# we're only interested in repo commit messages
|
31
|
-
next if msg.type != :commit
|
32
|
-
|
33
|
-
msg.operations.each do |op|
|
34
|
-
next if op.action != :create
|
35
|
-
|
36
|
-
begin
|
37
|
-
case op.type
|
38
|
-
when :bsky_block
|
39
|
-
process_block(msg, op)
|
40
|
-
when :bsky_listitem
|
41
|
-
process_list_item(msg, op)
|
42
|
-
end
|
43
|
-
rescue StandardError => e
|
44
|
-
puts "Error: #{e}"
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def process_block(msg, op)
|
50
|
-
if op.raw_record['subject'] == $monitored_did
|
51
|
-
owner_handle = get_user_handle(op.repo)
|
52
|
-
puts "@#{owner_handle} has blocked you! (#{msg.time.getlocal})"
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def process_list_item(msg, op)
|
57
|
-
if op.raw_record['subject'] == $monitored_did
|
58
|
-
owner_handle = get_user_handle(op.repo)
|
59
|
-
|
60
|
-
list_uri = op.raw_record['list']
|
61
|
-
list_name = get_list_name(list_uri)
|
62
|
-
|
63
|
-
puts "@#{owner_handle} has added you to list \"#{list_name}\" (#{msg.time.getlocal})"
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def get_user_handle(did)
|
68
|
-
url = "https://plc.directory/#{did}"
|
69
|
-
json = JSON.parse(URI.open(url).read)
|
70
|
-
json['alsoKnownAs'][0].gsub('at://', '')
|
71
|
-
end
|
72
|
-
|
73
|
-
def get_list_name(list_uri)
|
74
|
-
repo, type, rkey = list_uri.gsub('at://', '').split('/')
|
75
|
-
url = "https://bsky.social/xrpc/com.atproto.repo.getRecord?repo=#{repo}&collection=#{type}&rkey=#{rkey}"
|
76
|
-
|
77
|
-
json = JSON.parse(URI.open(url).read)
|
78
|
-
json['value']['name']
|
79
|
-
end
|
80
|
-
|
81
|
-
# close the connection cleanly on Ctrl+C
|
82
|
-
trap("SIGINT") { sky.disconnect }
|
83
|
-
|
84
|
-
sky.connect
|
@@ -1,12 +0,0 @@
|
|
1
|
-
module Skyfall
|
2
|
-
|
3
|
-
#
|
4
|
-
# Note: this event type is deprecated and will stop being emitted at some point.
|
5
|
-
# You should instead listen for 'identity' events (Skyfall::IdentityMessage).
|
6
|
-
#
|
7
|
-
class HandleMessage < WebsocketMessage
|
8
|
-
def handle
|
9
|
-
@data_object['handle']
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
data/lib/skyfall/operation.rb
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
require_relative 'collection'
|
2
|
-
|
3
|
-
module Skyfall
|
4
|
-
class Operation
|
5
|
-
def initialize(message, json)
|
6
|
-
@message = message
|
7
|
-
@json = json
|
8
|
-
end
|
9
|
-
|
10
|
-
def repo
|
11
|
-
@message.repo
|
12
|
-
end
|
13
|
-
|
14
|
-
alias did repo
|
15
|
-
|
16
|
-
def path
|
17
|
-
@json['path']
|
18
|
-
end
|
19
|
-
|
20
|
-
def action
|
21
|
-
@json['action'].to_sym
|
22
|
-
end
|
23
|
-
|
24
|
-
def collection
|
25
|
-
@json['path'].split('/')[0]
|
26
|
-
end
|
27
|
-
|
28
|
-
def rkey
|
29
|
-
@json['path'].split('/')[1]
|
30
|
-
end
|
31
|
-
|
32
|
-
def uri
|
33
|
-
"at://#{repo}/#{path}"
|
34
|
-
end
|
35
|
-
|
36
|
-
def cid
|
37
|
-
@cid ||= @json['cid'] && CID.from_cbor_tag(@json['cid'])
|
38
|
-
end
|
39
|
-
|
40
|
-
def raw_record
|
41
|
-
@raw_record ||= cid && @message.blocks.section_with_cid(cid)
|
42
|
-
end
|
43
|
-
|
44
|
-
def type
|
45
|
-
case collection
|
46
|
-
when Collection::BSKY_BLOCK then :bsky_block
|
47
|
-
when Collection::BSKY_FEED then :bsky_feed
|
48
|
-
when Collection::BSKY_FOLLOW then :bsky_follow
|
49
|
-
when Collection::BSKY_LABELER then :bsky_labeler
|
50
|
-
when Collection::BSKY_LIKE then :bsky_like
|
51
|
-
when Collection::BSKY_LIST then :bsky_list
|
52
|
-
when Collection::BSKY_LISTBLOCK then :bsky_listblock
|
53
|
-
when Collection::BSKY_LISTITEM then :bsky_listitem
|
54
|
-
when Collection::BSKY_POST then :bsky_post
|
55
|
-
when Collection::BSKY_POSTGATE then :bsky_postgate
|
56
|
-
when Collection::BSKY_PROFILE then :bsky_profile
|
57
|
-
when Collection::BSKY_REPOST then :bsky_repost
|
58
|
-
when Collection::BSKY_STARTERPACK then :bsky_starterpack
|
59
|
-
when Collection::BSKY_THREADGATE then :bsky_threadgate
|
60
|
-
when Collection::BSKY_CHAT_DECLARATION then :bsky_chat_declaration
|
61
|
-
else :unknown
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
def inspectable_variables
|
66
|
-
instance_variables - [:@message]
|
67
|
-
end
|
68
|
-
|
69
|
-
def inspect
|
70
|
-
vars = inspectable_variables.map { |v| "#{v}=#{instance_variable_get(v).inspect}" }.join(", ")
|
71
|
-
"#<#{self.class}:0x#{object_id} #{vars}>"
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|