Back to packages list

Vals using @atproto/api

Description from the NPM package:
Client library for atproto and Bluesky
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { fetch } from "https://esm.town/v/std/fetch";
import process from "node:process";
import { resume as resume2 } from "https://esm.town/v/ajax/resume";
export async function annoy() {
const resume = resume2;
// const boo = await import("https://esm.sh/@atproto/api");
const { default: BskyAgent } = await import("npm:@atproto/api");
console.log(BskyAgent);
const agent = new BskyAgent.BskyAgent({ service: "https://bsky.social" });
await agent.login({
identifier: process.env.BLUESKY_USERNAME!,
password: process.env.BLUESKY_PASSWORD!,
});
// const actor = await agent.getProfile();
// console.log({ actor });
// const followers = await agent.getFollowers();
// console.log(followers);
// const posts = await agent.getPosts({ uris: ["at://lordajax.bsky.social"] });
// console.log({ posts });
const timeline = await agent.getTimeline();
console.log({ timeline });
const mostRecentPost = timeline.data.feed[0];
console.log({ mostRecentPost });
const author = mostRecentPost.post.author.handle;
const recordText = mostRecentPost.post.record.text;
console.log({ author, recordText });
const prompt =
`Choose an esoteric word of the day. You will use this word in the following poem.
Write a poem about how all you want to do is drink and get high using the chosen word.
Make it funny and short. Talk about your friends Pam and Tom.
Make it sound like you are wise.
Be dark and moody.
Make sure your response is no longer than 270 characters.
Put the word first and definition and then the poem below.
The poem MUST contain the chosen word of the day.
You MUST include the definition of the word
Here is an example;
Bifurcate - divide into two branches or forks.
Bifurcate! My life is stale, my friends just wanna inebriate.
Tom wants a coke, Pam needs a beer, they laugh and joke as I just sneer.
Just leave me be, no need to beep, can't you see I just wanna sleep?
---
Copying the example above, find a new word and do as above.
`;
console.log({ prompt });
const response = await fetch("https://api.openai.com/v1/completions", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer " + process.env.OPENAI_API_KEY, // Replace with your OpenAI API Key
},
body: JSON.stringify({
"prompt": prompt,
"model": "text-davinci-003",
"temperature": 1,
"max_tokens": 256,
"top_p": 1,
"frequency_penalty": 0,
"presence_penalty": 0,
}),
});
if (!response.ok) {
console.log(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
console.log(data);
const message = data.choices[0].text.trim();
console.log({ message });
await agent.post({
text: message,
});
return "asd";
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import process from "node:process";
export let bskySocialEx = (async () => {
const { default: api } = await import("npm:@atproto/api");
const service = "https://bsky.social";
const agent = await new api.BskyAgent({ service });
await agent.login({
identifier: process.env.blueskyEmail,
password: process.env.blueskyPassword,
});
const follows = await agent.getFollowers({
actor: "stevekrouse.bsky.social",
});
return follows;
})();
// Forked from @lukas.bskySocial
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { fetch } from "https://esm.town/v/std/fetch";
import process from "node:process";
import { resume as resume2 } from "https://esm.town/v/ajax/resume";
export async function annoy() {
const resume = resume2;
// const boo = await import("https://esm.sh/@atproto/api");
const { default: BskyAgent } = await import("npm:@atproto/api");
console.log(BskyAgent);
const agent = new BskyAgent.BskyAgent({ service: "https://bsky.social" });
await agent.login({
identifier: process.env.BLUESKY_USERNAME!,
password: process.env.BLUESKY_PASSWORD!,
});
// const actor = await agent.getProfile();
// console.log({ actor });
// const followers = await agent.getFollowers();
// console.log(followers);
// const posts = await agent.getPosts({ uris: ["at://lordajax.bsky.social"] });
// console.log({ posts });
const timeline = await agent.getTimeline();
console.log({ timeline });
const mostRecentPost = timeline.data.feed[0];
console.log({ mostRecentPost });
const author = mostRecentPost.post.author.handle;
const recordText = mostRecentPost.post.record.text;
console.log({ author, recordText });
const prompt =
`Choose an esoteric word of the day. You will use this word in the following poem.
Write a poem about how all you want to do is drink and get high using the chosen word.
Make it funny and short. Talk about your friends Pam and Tom.
Make it sound like you are wise.
Be dark and moody.
Make sure your response is no longer than 270 characters.
Put the word first and definition and then the poem below.
The poem MUST contain the chosen word of the day.
You MUST include the definition of the word
Here is an example;
Bifurcate - divide into two branches or forks.
Bifurcate! My life is stale, my friends just wanna inebriate.
Tom wants a coke, Pam needs a beer, they laugh and joke as I just sneer.
Just leave me be, no need to beep, can't you see I just wanna sleep?
---
Copying the example above, find a new word and do as above.
`;
console.log({ prompt });
const response = await fetch("https://api.openai.com/v1/completions", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer " + process.env.OPENAI_API_KEY, // Replace with your OpenAI API Key
},
body: JSON.stringify({
"prompt": prompt,
"model": "text-davinci-003",
"temperature": 1,
"max_tokens": 256,
"top_p": 1,
"frequency_penalty": 0,
"presence_penalty": 0,
}),
});
if (!response.ok) {
console.log(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
console.log(data);
const message = data.choices[0].text.trim();
console.log({ message });
await agent.post({
text: message,
});
return "asd";
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
export let denoImportEx = (async () => {
// const { DOMParser } = await import(
// "https://deno.land/x/deno_dom/deno-dom-wasm.ts"
// );
// const { BskyAgent, AtpSessionEvent, AtpSessionData } = await import(
// "npm:atproto/api"
// );
// const _ = await import("npm:lodash-es"); // The Lodash library exported as ES modules.
const { BskyAgent } = await import("npm:@atproto/api");
// return _.shuffle(_.zip([1, 2, 3, 4], [5, 6, 7, 8]));
const agent = new BskyAgent({
service: "https://scottraymond.com",
persistSession: (evt, sess) => {
// store the session-data for reuse
console.log("got session");
console.log(sess);
},
});
await agent.login({ identifier: "sco@scottraymond.net", password: "foo" });
return "foo";
})();

Big League yourself! WARNING, this will unfollow every user you follow!

Readme
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
export const bigLeagueMe = async (req: Request) => {
const params = Object.fromEntries(new URL(req.url).searchParams.entries());
var {default: atproto} = await import("npm:@atproto/api");
const BskyAgent = atproto.
// YOUR bluesky handle
// Ex: user.bsky.social
const handle = params.HANDLE || "";
// YOUR bluesky password, or preferably an App Password (found in your client settings)
// Ex: abcd-1234-efgh-5678
const password = params.PASS || "";
// only update this if in a test environment
const agent = new BskyAgent({ service: "https://bsky.social" });
await agent.login({ identifier: handle, password });
let follows = [];
let cursor;
while (true) {
const following = await agent.app.bsky.graph.getFollows({
cursor,
actor: handle,
});
cursor = following.data.cursor;
follows = [...follows, ...following.data.follows];
if (!cursor)
break;
}
let resp = "";
for (const actor of follows) {
const [rkey, repo] = actor.viewer?.following?.split("/").reverse() || [];
resp += `Unfollowed ${actor.handle}\n`;
}
return new Response(resp, { headers: { "Content-Type": "text/text" } });
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
export const sendPostToBsky = async (
{ identifier, password, text, facets },
) => {
const { default: AtProto } = await import("npm:@atproto/api");
const { BskyAgent, RichText } = AtProto;
const bskyService = "https://bsky.social";
const agent = new BskyAgent({ service: bskyService });
if (identifier && password && text) {
await agent.login({
identifier,
password,
});
const rt = new RichText({ text, facets });
// only detectFacets if parameter did not assign it
if (!facets) {
await rt.detectFacets(agent);
}
await agent.post({
$type: "app.bsky.feed.post",
text: rt.text,
facets: rt.facets,
});
}
else {
console.log("ERR: Missing necessary data");
}
};
1
Next