Template of a custom feed generator service for the Bluesky network in Ruby
1require_relative 'feed'
2
3class KitFeed < Feed
4 KIT_REGEX = [/\bkit\b/i]
5 CAT_REGEX = [/\bcat\b/i, /\bkitty\b/i]
6
7 PAUL = 'did:plc:ragtjsm2j2vknwkz3zp4oxrd'
8
9 def feed_id
10 3
11 end
12
13 def display_name
14 "Kit Feed"
15 end
16
17 def description
18 "Photos of Paul's lovely cat Kit 🐱"
19 end
20
21 def avatar_file
22 "images/kitkat.jpg"
23 end
24
25 def post_matches?(post)
26 return false unless post.repo == PAUL
27
28 alt = embed_text(post)
29 return false if alt.nil?
30
31 KIT_REGEX.any? { |r| alt =~ r } || (CAT_REGEX.any? { |r| alt =~ r } && KIT_REGEX.any? { |r| post.text =~ r })
32 end
33
34 def embed_text(post)
35 if embed = post.record['embed']
36 if images = (embed['images'] || embed['media'] && embed['media']['images'])
37 images.map { |i| i['alt'] }.compact.join("\n")
38 end
39 end
40 end
41
42 def colored_text(t)
43 text = t.dup
44
45 KIT_REGEX.each { |r| text.gsub!(r) { |s| Rainbow(s).green }}
46 CAT_REGEX.each { |r| text.gsub!(r) { |s| Rainbow(s).bright.orange }}
47
48 text
49 end
50end