Skip to content

Commit

Permalink
major: Release 2.0.0 (#2)
Browse files Browse the repository at this point in the history
* update for latest beta

* feature: Added additional templates and gh action

* minor: update versions and remove comments

* major: Update to 2.0.0-beta.19

* patch: update dependencies

* update to 2.0.0
  • Loading branch information
juni-b-queer authored Dec 10, 2024
1 parent 558e633 commit f21a04d
Show file tree
Hide file tree
Showing 22 changed files with 474 additions and 9 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,15 @@ Simple command for scafolding a new bsky bot with bsky-event-handlers
bunx create-bsky-bot <name>
```

The final prompt will ask if you also want to include a github action workflow to build and publish your docker containers

### Available templates:

**default** : includes basic code for jetstream and interval subscriptions

**jetstream**: includes basic code for jetstream subscription

**interval**: includes basic code for jetstream subscription


For more bsky-event-handler information, see the docs [here](https://github.com/juni-b-queer/bsky-event-handlers)
35 changes: 34 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import { create } from 'create-create-app';
import { resolve } from 'path';
import * as fs from 'fs';
import * as path from 'path';

const templateRoot = resolve(__dirname, '..', 'templates');

Expand All @@ -12,9 +14,40 @@ Now go out and build a bot!`;

// See https://github.com/uetchy/create-create-app/blob/master/README.md for other options.


create('create-bsky-bot', {
templateRoot,
after: () => console.log(`Good to go!`),
after: (options) =>{
if(options.answers.buildaction){
const projectPath = options.packageDir;
const githubWorkflowsDir = path.join(projectPath, '.github', 'workflows');
if (!fs.existsSync(githubWorkflowsDir)){
fs.mkdirSync(githubWorkflowsDir, { recursive: true });
}

const defaultTemplateDir = options.templateDir;

const templatesDir = path.join(defaultTemplateDir, '..');

const workflowsTemplateDir = path.join(templatesDir, 'workflows');

const sourceFile = path.join(workflowsTemplateDir, 'buildandpublishtoghcr.yml');
const destFile = path.join(githubWorkflowsDir, 'buildandpublishtoghcr.yml');
fs.copyFileSync(sourceFile, destFile);
console.log("Added GH action")
}


console.log("Good to go")
},
extra: {
buildaction: {
type: 'confirm',
describe: 'Should include gh action to build the bot',
default: 'y',
prompt: 'always',
},
},
caveat,
skipGitInit: true,
skipNpmInstall: true
Expand Down
4 changes: 3 additions & 1 deletion templates/default/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ TEST_BSKY_PASSWORD=
DEBUG_LOG_ACTIVE=true
DEBUG_LOG_LEVEL=info

JETSTREAM_URL='ws://jetstream:6008/subscribe'
JETSTREAM_URL='ws://jetstream:6008/subscribe'

SESSION_DATA_PATH='/sessionData'
2 changes: 1 addition & 1 deletion templates/default/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM oven/bun:1.0.15 as base
FROM oven/bun:latest as base
WORKDIR /usr/src/app

# install dependencies into temp directory
Expand Down
3 changes: 3 additions & 0 deletions templates/default/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ services:
- jetstream
build: .
restart: unless-stopped
volumes:
- ./sessionData:/sessionData
env_file:
- .env
networks:
Expand All @@ -14,6 +16,7 @@ services:
jetstream:
image: "junibqueer/jetstream:main"
container_name: jetstream
restart: unless-stopped
environment:
- CURSOR_FILE=/data/cursor.json
ports:
Expand Down
4 changes: 2 additions & 2 deletions templates/default/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"typescript": "^5.0.0"
},
"dependencies": {
"bsky-event-handlers": "1.1.0",
"@atproto/api": "^0.12.7"
"bsky-event-handlers": "^2.0.0",
"@atproto/api": "^0.13.19"
},
"license": "{{license}}"
}
35 changes: 31 additions & 4 deletions templates/default/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import {
JetstreamSubscription,
LogMessageAction,
ReplyingToBotValidator,
ReplyToSkeetAction
MessageHandler,
IntervalSubscription,
IntervalSubscriptionHandlers,
AbstractHandler,
IsSpecifiedTimeValidator,
CreateSkeetAction
} from 'bsky-event-handlers';

const testAgent = new HandlerAgent(
Expand All @@ -17,14 +22,17 @@ const testAgent = new HandlerAgent(
<string>Bun.env.TEST_BSKY_PASSWORD
);

/**
* Jetstream Subscription setup
*/
let jetstreamSubscription: JetstreamSubscription;

let handlers = {
post: {
c: [
new CreateSkeetHandler(
[new ReplyingToBotValidator(), new InputEqualsValidator("Hello")],
[new LogMessageAction(), new ReplyToSkeetAction("World!")],
new MessageHandler(
[ReplyingToBotValidator().make(), InputEqualsValidator("Hello").make()],
[LogMessageAction().make(), CreateSkeetAction.make('World!', MessageHandler.generateReplyFromMessage)],
testAgent
),
new GoodBotHandler(testAgent),
Expand All @@ -33,16 +41,35 @@ let handlers = {
}
}

let intervalSubscription: IntervalSubscription;

const intervalSubscriptionHandlers: IntervalSubscriptionHandlers = [
{
intervalSeconds: 60,
handlers:[
new AbstractHandler(
[IsSpecifiedTimeValidator.make("04:20", "16:20")],
[CreateSkeetAction.make("It's 4:20 somewhere!")],
testAgent)
]
}
]


async function initialize() {
await testAgent.authenticate()
jetstreamSubscription = new JetstreamSubscription(
handlers,
<string>Bun.env.JETSTREAM_URL
);
intervalSubscription = new IntervalSubscription(
intervalSubscriptionHandlers
)
}

initialize().then(() =>{
jetstreamSubscription.createSubscription()
intervalSubscription.createSubscription()
DebugLog.info("INIT", 'Initialized!')
});

Expand Down
4 changes: 4 additions & 0 deletions templates/interval/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
TEST_BSKY_HANDLE=
TEST_BSKY_PASSWORD=
DEBUG_LOG_ACTIVE=true
DEBUG_LOG_LEVEL=info
35 changes: 35 additions & 0 deletions templates/interval/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
FROM oven/bun:latest as base
WORKDIR /usr/src/app

# install dependencies into temp directory
# this will cache them and speed up future builds
FROM base AS install
RUN mkdir -p /temp/dev
COPY package.json bun.lockb /temp/dev/
RUN cd /temp/dev && bun install --frozen-lockfile

# install with --production (exclude devDependencies)
RUN mkdir -p /temp/prod
COPY package.json bun.lockb /temp/prod/
RUN cd /temp/prod && bun install --frozen-lockfile --production

# copy node_modules from temp directory
# then copy all (non-ignored) project files into the image
FROM install AS prerelease
COPY --from=install /temp/dev/node_modules node_modules
COPY . .

# [optional] tests & build
ENV NODE_ENV=production
RUN bun test
RUN bun run build

# copy production dependencies and source code into final image
FROM base AS release
COPY --from=install /temp/prod/node_modules node_modules
COPY --from=prerelease /usr/src/app/build/index.ts .
COPY --from=prerelease /usr/src/app/package.json .

# run the app
USER bun
ENTRYPOINT [ "bun", "run", "index.ts" ]
15 changes: 15 additions & 0 deletions templates/interval/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# {{name}}

{{description}}

# Quickstart
- [ ] Install Bun
- [ ] Install Docker
- [ ] Fill in .env with your handle and **app** password (do not use your real password)
- [ ] Run `make up`
- [ ] Be free and create to your hearts content!


## Development

Check out the bsky-event-handler docs [here](https://github.com/juni-b-queer/bsky-event-handlers)
15 changes: 15 additions & 0 deletions templates/interval/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: "3.8"
services:
bskybot:
build: .
restart: unless-stopped
volumes:
- ./sessionData:/sessionData
env_file:
- .env
networks:
- bun

networks:
bun:
driver: bridge
19 changes: 19 additions & 0 deletions templates/interval/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.PHONY: *

dev:
bun run src/index.ts

build:
docker compose build

up:
docker compose up -d

down:
docker compose down

logs:
docker compose logs -f

install:
bun install
22 changes: 22 additions & 0 deletions templates/interval/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "{{kebab name}}",
"description": "{{description}}",
"version": "0.0.0",
"author": "{{contact}}",
"module": "src/index.ts",
"type": "module",
"scripts": {
"build": "bun build --target=bun ./src/index.ts --outfile=./build/index.ts"
},
"devDependencies": {
"bun-types": "latest"
},
"peerDependencies": {
"typescript": "^5.0.0"
},
"dependencies": {
"bsky-event-handlers": "^2.0.0",
"@atproto/api": "^0.13.19"
},
"license": "{{license}}"
}
44 changes: 44 additions & 0 deletions templates/interval/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import {
DebugLog,
HandlerAgent,
IntervalSubscription,
IntervalSubscriptionHandlers,
AbstractHandler,
IsSpecifiedTimeValidator,
CreateSkeetAction
} from 'bsky-event-handlers';

const testAgent = new HandlerAgent(
'test-bot',
<string>Bun.env.TEST_BSKY_HANDLE,
<string>Bun.env.TEST_BSKY_PASSWORD
);

let intervalSubscription: IntervalSubscription;

const intervalSubscriptionHandlers: IntervalSubscriptionHandlers = [
{
intervalSeconds: 60,
handlers:[
new AbstractHandler(
[IsSpecifiedTimeValidator.make("04:20", "16:20")],
[CreateSkeetAction.make("It's 4:20 somewhere!")],
testAgent)
]
}
]


async function initialize() {
await testAgent.authenticate()
intervalSubscription = new IntervalSubscription(
intervalSubscriptionHandlers
)
}

initialize().then(() =>{
intervalSubscription.createSubscription()
DebugLog.info("INIT", 'Initialized!')
});


8 changes: 8 additions & 0 deletions templates/jetstream/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
TEST_BSKY_HANDLE=
TEST_BSKY_PASSWORD=
DEBUG_LOG_ACTIVE=true
DEBUG_LOG_LEVEL=info

JETSTREAM_URL='ws://jetstream:6008/subscribe'

SESSION_DATA_PATH='/sessionData'
35 changes: 35 additions & 0 deletions templates/jetstream/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
FROM oven/bun:1.0.15 as base
WORKDIR /usr/src/app

# install dependencies into temp directory
# this will cache them and speed up future builds
FROM base AS install
RUN mkdir -p /temp/dev
COPY package.json bun.lockb /temp/dev/
RUN cd /temp/dev && bun install --frozen-lockfile

# install with --production (exclude devDependencies)
RUN mkdir -p /temp/prod
COPY package.json bun.lockb /temp/prod/
RUN cd /temp/prod && bun install --frozen-lockfile --production

# copy node_modules from temp directory
# then copy all (non-ignored) project files into the image
FROM install AS prerelease
COPY --from=install /temp/dev/node_modules node_modules
COPY . .

# [optional] tests & build
ENV NODE_ENV=production
RUN bun test
RUN bun run build

# copy production dependencies and source code into final image
FROM base AS release
COPY --from=install /temp/prod/node_modules node_modules
COPY --from=prerelease /usr/src/app/build/index.ts .
COPY --from=prerelease /usr/src/app/package.json .

# run the app
USER bun
ENTRYPOINT [ "bun", "run", "index.ts" ]
Loading

0 comments on commit f21a04d

Please sign in to comment.