A Discord bot, made with Gleam, designed to help manage a pixel art server.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

make sure posts have existed for more than a minute before posting

Isaac 1ec50512 d7243255

+23 -3
+11 -3
src/pablo_pixarto.gleam
··· 14 14 import gleam/result 15 15 import gleam/set.{type Set} 16 16 import gleam/string 17 + import gleam/time/duration 17 18 import gleam/time/timestamp.{type Timestamp} 18 19 import grom 19 20 import grom/activity ··· 187 188 fn check_and_post(state: AppState) -> AppState { 188 189 case latest_bsky_posts(bluesky_actor, 50) { 189 190 Ok(posts) -> { 191 + // Only make posts that have existed for at least 5 minutes 192 + let now = timestamp.system_time() 193 + let timeago = fn(minutes: Int) { 194 + timestamp.add(now, duration.minutes(minutes * -1)) 195 + } 196 + 190 197 let matched = 191 198 list.filter(posts, fn(post) { 192 199 has_theme_and_tag(post.text) 193 200 && !set.contains(state.posted_uris, post.uri) 194 - && { 195 - timestamp.compare(post.created_at, state.last_updated) == order.Gt 196 - } 201 + // Older than 1 minute 202 + && timestamp.compare(post.created_at, timeago(1)) == order.Lt 203 + // Newer than a few minutes ago 204 + && timestamp.compare(post.created_at, timeago(3)) == order.Gt 197 205 }) 198 206 199 207 case matched {
+12
test/pablo_pixarto_test.gleam
··· 1 + import gleam/time/duration 2 + import gleam/time/timestamp 1 3 import gleeunit 2 4 import pablo_pixarto 3 5 ··· 25 27 26 28 assert feed != [] 27 29 } 30 + 31 + pub fn timestamp_5minsago_test() { 32 + echo timestamp.system_time() 33 + |> timestamp.to_rfc3339(duration.seconds(0)) 34 + 35 + timestamp.system_time() 36 + |> timestamp.add(duration.minutes(-5)) 37 + |> timestamp.to_rfc3339(duration.seconds(0)) 38 + |> echo 39 + }