this repo has no description
at main 76 lines 1.9 kB view raw
1-- Constants 2local PDS_HOST = "https://bsky.social" 3local CREATE_SESSION_URL = PDS_HOST .. "/xrpc/com.atproto.server.createSession" 4local CREATE_POST_URL = PDS_HOST .. "/xrpc/com.atproto.repo.createRecord" 5 6-- Helper function to get current UTC time in ISO format 7local function getISOTime() 8 return os.date("!%Y-%m-%dT%H:%M:%SZ") 9end 10 11-- Prompt for user input while hiding password 12print("Enter your Bluesky username:") 13local username = read() 14print("Enter your app password:") 15local password = read("*") -- "*" hides the input 16 17-- Create session 18print("Creating session...") 19local sessionResponse = http.post( 20 CREATE_SESSION_URL, 21 textutils.serialiseJSON({ 22 identifier = username, 23 password = password 24 }), 25 { 26 ["Content-Type"] = "application/json" 27 } 28) 29 30if not sessionResponse then 31 error("Failed to connect to Bluesky") 32end 33 34local sessionData = textutils.unserialiseJSON(sessionResponse.readAll()) 35sessionResponse.close() 36 37if not sessionData or not sessionData.accessJwt then 38 error("Failed to create session. Check your credentials.") 39end 40 41print("Session created successfully!") 42 43-- Prompt for post content 44print("Enter your post text:") 45local postText = read() 46 47-- Create post 48print("Creating post...") 49local postResponse = http.post( 50 CREATE_POST_URL, 51 textutils.serialiseJSON({ 52 repo = username, 53 collection = "app.bsky.feed.post", 54 record = { 55 text = postText, 56 createdAt = getISOTime() 57 } 58 }), 59 { 60 ["Content-Type"] = "application/json", 61 ["Authorization"] = "Bearer " .. sessionData.accessJwt 62 } 63) 64 65if not postResponse then 66 error("Failed to connect to Bluesky while posting") 67end 68 69local postData = textutils.unserialiseJSON(postResponse.readAll()) 70postResponse.close() 71 72if postData then 73 print("Post created successfully!") 74else 75 print("Failed to create post. Something went wrong.") 76end