Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
1.9 kB · 76 lines
Lua
at main
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576-- Constantslocal PDS_HOST = "https://bsky.social"local CREATE_SESSION_URL = PDS_HOST .. "/xrpc/com.atproto.server.createSession"local CREATE_POST_URL = PDS_HOST .. "/xrpc/com.atproto.repo.createRecord"
-- Helper function to get current UTC time in ISO formatlocal function getISOTime() return os.date("!%Y-%m-%dT%H:%M:%SZ")end
-- Prompt for user input while hiding passwordprint("Enter your Bluesky username:")local username = read()print("Enter your app password:")local password = read("*") -- "*" hides the input
-- Create sessionprint("Creating session...")local sessionResponse = http.post( CREATE_SESSION_URL, textutils.serialiseJSON({ identifier = username, password = password }), { ["Content-Type"] = "application/json" })
if not sessionResponse then error("Failed to connect to Bluesky")end
local sessionData = textutils.unserialiseJSON(sessionResponse.readAll())sessionResponse.close()
if not sessionData or not sessionData.accessJwt then error("Failed to create session. Check your credentials.")end
print("Session created successfully!")
-- Prompt for post contentprint("Enter your post text:")local postText = read()
-- Create postprint("Creating post...")local postResponse = http.post( CREATE_POST_URL, textutils.serialiseJSON({ repo = username, collection = "app.bsky.feed.post", record = { text = postText, createdAt = getISOTime() } }), { ["Content-Type"] = "application/json", ["Authorization"] = "Bearer " .. sessionData.accessJwt })
if not postResponse then error("Failed to connect to Bluesky while posting")end
local postData = textutils.unserialiseJSON(postResponse.readAll())postResponse.close()
if postData then print("Post created successfully!")else print("Failed to create post. Something went wrong.")end