···11#!/usr/bin/env ruby
2233-# Example: monitor the network for people blocking your account or adding you to mute lists.
33+# Example: monitor the network for people blocking your account or adding you to lists.
4455# load skyfall from a local folder - you normally won't need this
66$LOAD_PATH.unshift(File.expand_path('../lib', __dir__))
···21212222sky = Skyfall::Firehose.new('bsky.network', :subscribe_repos)
23232424-sky.on_connect { puts "Connected, monitoring #{$monitored_did}" }
2525-sky.on_disconnect { puts "Disconnected" }
2626-sky.on_reconnect { puts "Reconnecting..." }
2727-sky.on_error { |e| puts "ERROR: #{e}" }
2424+sky.on_connect { log "Connected, monitoring #{$monitored_did}" }
2525+sky.on_disconnect { log "Disconnected" }
2626+sky.on_reconnect { log "Reconnecting..." }
2727+sky.on_error { |e| log "ERROR: #{e}" }
28282929sky.on_message do |msg|
3030 # we're only interested in repo commit messages
···4141 process_list_item(msg, op)
4242 end
4343 rescue StandardError => e
4444- puts "Error: #{e}"
4444+ log "Error: #{e}"
4545 end
4646 end
4747end
48484949+def log(msg)
5050+ puts "[#{Time.now}] #{msg}"
5151+end
5252+4953def process_block(msg, op)
5054 if op.raw_record['subject'] == $monitored_did
5155 owner_handle = get_user_handle(op.repo)
5252- puts "@#{owner_handle} has blocked you! (#{msg.time.getlocal})"
5656+ log "@#{owner_handle} has blocked you! (#{msg.time.getlocal})"
5357 end
5458end
5559···6064 list_uri = op.raw_record['list']
6165 list_name = get_list_name(list_uri)
62666363- puts "@#{owner_handle} has added you to list \"#{list_name}\" (#{msg.time.getlocal})"
6767+ log "@#{owner_handle} has added you to list \"#{list_name}\" (#{msg.time.getlocal})"
6468 end
6569end
6670
+5-2
example/print_all_posts.rb
···11#!/usr/bin/env ruby
2233# Example: print the date and text of every new post made on the network as they appear.
44+# Pass a hostname of a single PDS as the argument to only stream new posts from that PDS.
4556# load skyfall from a local folder - you normally won't need this
67$LOAD_PATH.unshift(File.expand_path('../lib', __dir__))
7889require 'skyfall'
9101010-sky = Skyfall::Firehose.new('bsky.network', :subscribe_repos)
1111+firehose_host = ARGV[0] || 'bsky.network'
1212+1313+sky = Skyfall::Firehose.new(firehose_host, :subscribe_repos)
11141215sky.on_message do |msg|
1316 # we're only interested in repo commit messages
···2326 end
2427end
25282626-sky.on_connect { puts "Connected" }
2929+sky.on_connect { puts "Connected to #{firehose_host}" }
2730sky.on_disconnect { puts "Disconnected" }
2831sky.on_reconnect { puts "Reconnecting..." }
2932sky.on_error { |e| puts "ERROR: #{e}" }