2024-12-11 13:13:07 -06:00
|
|
|
import {
|
2024-12-11 19:33:36 -06:00
|
|
|
ActionTakenByUserValidator,
|
|
|
|
CreateSkeetAction,
|
2024-12-11 13:13:07 -06:00
|
|
|
DebugLog,
|
|
|
|
HandlerAgent,
|
|
|
|
JetstreamEventCommit,
|
|
|
|
JetstreamSubject,
|
2024-12-11 19:33:36 -06:00
|
|
|
JetstreamSubscription,
|
|
|
|
LogInputTextAction,
|
|
|
|
MessageHandler
|
2024-12-11 13:13:07 -06:00
|
|
|
} from 'bsky-event-handlers';
|
|
|
|
|
|
|
|
const testAgent = new HandlerAgent(
|
2024-12-11 13:17:20 -06:00
|
|
|
'user-tracker',
|
2024-12-11 13:13:07 -06:00
|
|
|
<string>Bun.env.TRACKER_BSKY_HANDLE,
|
|
|
|
<string>Bun.env.TRACKER_BSKY_PASSWORD
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Jetstream Subscription setup
|
|
|
|
*/
|
|
|
|
let jetstreamSubscription: JetstreamSubscription;
|
|
|
|
|
|
|
|
|
|
|
|
let handlers = {
|
|
|
|
post: {
|
|
|
|
c: [
|
|
|
|
new MessageHandler(
|
|
|
|
// @ts-ignore
|
|
|
|
[ActionTakenByUserValidator.make(<string>Bun.env.USER_DID)],
|
|
|
|
[
|
2024-12-11 19:29:15 -06:00
|
|
|
CreateSkeetAction.make(
|
|
|
|
(handler: HandlerAgent, commit: JetstreamEventCommit): string => {
|
|
|
|
// @ts-ignore
|
|
|
|
let text = "\"" + commit.commit.record?.text + "\"";
|
|
|
|
if(text.length > 300){
|
|
|
|
text = text.substring(1, 301)
|
|
|
|
}
|
|
|
|
return text;
|
|
|
|
},
|
|
|
|
undefined,
|
|
|
|
(handler: HandlerAgent, commit: JetstreamEventCommit): JetstreamSubject => {
|
|
|
|
return {
|
|
|
|
cid: MessageHandler.getCidFromMessage(handler, commit),
|
|
|
|
uri: MessageHandler.getUriFromMessage(handler, commit)
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
|
2024-12-11 13:13:07 -06:00
|
|
|
LogInputTextAction.make("Post")
|
|
|
|
],
|
|
|
|
testAgent
|
2024-12-11 15:50:44 -06:00
|
|
|
)
|
2024-12-11 13:13:07 -06:00
|
|
|
]
|
|
|
|
},
|
|
|
|
like: {
|
|
|
|
c: [
|
|
|
|
new MessageHandler(
|
|
|
|
// @ts-ignore
|
|
|
|
[ActionTakenByUserValidator.make(<string>Bun.env.USER_DID)],
|
|
|
|
[
|
2024-12-27 02:31:43 +00:00
|
|
|
CreateSkeetAction.make(<string>Bun.env.NAME +" liked:", undefined, (handler: HandlerAgent, commit: JetstreamEventCommit): JetstreamSubject => {
|
2024-12-11 13:13:07 -06:00
|
|
|
return commit.commit.record.subject as JetstreamSubject;
|
|
|
|
}),
|
|
|
|
LogInputTextAction.make("Like")
|
|
|
|
],
|
|
|
|
testAgent
|
|
|
|
)
|
|
|
|
]
|
|
|
|
},
|
|
|
|
repost: {
|
|
|
|
c: [
|
|
|
|
new MessageHandler(
|
|
|
|
// @ts-ignore
|
|
|
|
[ActionTakenByUserValidator.make(<string>Bun.env.USER_DID)],
|
|
|
|
[
|
2024-12-27 02:31:43 +00:00
|
|
|
CreateSkeetAction.make(<string>Bun.env.NAME + " reposted:", undefined, (handler: HandlerAgent, commit: JetstreamEventCommit): JetstreamSubject => {
|
2024-12-11 13:13:07 -06:00
|
|
|
return commit.commit.record.subject as JetstreamSubject;
|
|
|
|
}),
|
|
|
|
LogInputTextAction.make("Repost")
|
|
|
|
],
|
|
|
|
testAgent
|
|
|
|
)
|
|
|
|
]
|
|
|
|
},
|
|
|
|
block: {
|
|
|
|
c: [
|
|
|
|
new MessageHandler(
|
|
|
|
// @ts-ignore
|
|
|
|
[
|
|
|
|
ActionTakenByUserValidator.make(<string>Bun.env.USER_DID)
|
|
|
|
],
|
|
|
|
[
|
|
|
|
CreateSkeetAction.make((handler: HandlerAgent, event: JetstreamEventCommit): string => {
|
|
|
|
const blockedDid = event.commit.record.subject
|
|
|
|
return "Aaron blocked a user: " + blockedDid;
|
|
|
|
}, undefined, undefined),
|
|
|
|
LogInputTextAction.make("Block"),
|
|
|
|
],
|
|
|
|
testAgent
|
|
|
|
)
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function initialize() {
|
|
|
|
await testAgent.authenticate()
|
|
|
|
jetstreamSubscription = new JetstreamSubscription(
|
|
|
|
handlers,
|
2024-12-11 15:07:32 -06:00
|
|
|
<string>Bun.env.JETSTREAM_URL,
|
|
|
|
[<string>Bun.env.USER_DID]
|
2024-12-11 13:13:07 -06:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-12-11 19:29:15 -06:00
|
|
|
initialize().then(() => {
|
2024-12-11 13:13:07 -06:00
|
|
|
jetstreamSubscription.createSubscription()
|
|
|
|
DebugLog.info("INIT", 'Initialized!')
|
|
|
|
});
|
|
|
|
|
|
|
|
|