···1#!/usr/bin/env ruby
23-# Example: monitor the network for people blocking your account or adding you to mute lists.
45# load skyfall from a local folder - you normally won't need this
6$LOAD_PATH.unshift(File.expand_path('../lib', __dir__))
···2122sky = Skyfall::Firehose.new('bsky.network', :subscribe_repos)
2324-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}" }
2829sky.on_message do |msg|
30 # we're only interested in repo commit messages
···41 process_list_item(msg, op)
42 end
43 rescue StandardError => e
44- puts "Error: #{e}"
45 end
46 end
47end
48000049def 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
54end
55···60 list_uri = op.raw_record['list']
61 list_name = get_list_name(list_uri)
6263- puts "@#{owner_handle} has added you to list \"#{list_name}\" (#{msg.time.getlocal})"
64 end
65end
66
···1#!/usr/bin/env ruby
23+# Example: monitor the network for people blocking your account or adding you to lists.
45# load skyfall from a local folder - you normally won't need this
6$LOAD_PATH.unshift(File.expand_path('../lib', __dir__))
···2122sky = Skyfall::Firehose.new('bsky.network', :subscribe_repos)
2324+sky.on_connect { log "Connected, monitoring #{$monitored_did}" }
25+sky.on_disconnect { log "Disconnected" }
26+sky.on_reconnect { log "Reconnecting..." }
27+sky.on_error { |e| log "ERROR: #{e}" }
2829sky.on_message do |msg|
30 # we're only interested in repo commit messages
···41 process_list_item(msg, op)
42 end
43 rescue StandardError => e
44+ log "Error: #{e}"
45 end
46 end
47end
4849+def log(msg)
50+ puts "[#{Time.now}] #{msg}"
51+end
52+53def process_block(msg, op)
54 if op.raw_record['subject'] == $monitored_did
55 owner_handle = get_user_handle(op.repo)
56+ log "@#{owner_handle} has blocked you! (#{msg.time.getlocal})"
57 end
58end
59···64 list_uri = op.raw_record['list']
65 list_name = get_list_name(list_uri)
6667+ log "@#{owner_handle} has added you to list \"#{list_name}\" (#{msg.time.getlocal})"
68 end
69end
70
+5-2
example/print_all_posts.rb
···1#!/usr/bin/env ruby
23# Example: print the date and text of every new post made on the network as they appear.
045# load skyfall from a local folder - you normally won't need this
6$LOAD_PATH.unshift(File.expand_path('../lib', __dir__))
78require 'skyfall'
910-sky = Skyfall::Firehose.new('bsky.network', :subscribe_repos)
001112sky.on_message do |msg|
13 # we're only interested in repo commit messages
···23 end
24end
2526-sky.on_connect { puts "Connected" }
27sky.on_disconnect { puts "Disconnected" }
28sky.on_reconnect { puts "Reconnecting..." }
29sky.on_error { |e| puts "ERROR: #{e}" }
···1#!/usr/bin/env ruby
23# Example: print the date and text of every new post made on the network as they appear.
4+# Pass a hostname of a single PDS as the argument to only stream new posts from that PDS.
56# load skyfall from a local folder - you normally won't need this
7$LOAD_PATH.unshift(File.expand_path('../lib', __dir__))
89require 'skyfall'
1011+firehose_host = ARGV[0] || 'bsky.network'
12+13+sky = Skyfall::Firehose.new(firehose_host, :subscribe_repos)
1415sky.on_message do |msg|
16 # we're only interested in repo commit messages
···26 end
27end
2829+sky.on_connect { puts "Connected to #{firehose_host}" }
30sky.on_disconnect { puts "Disconnected" }
31sky.on_reconnect { puts "Reconnecting..." }
32sky.on_error { |e| puts "ERROR: #{e}" }