Add blogbot script

This commit is contained in:
ryan 2026-01-20 11:09:22 -08:00
parent b7b189a82c
commit c2108c4f83
5 changed files with 1353 additions and 1 deletions

7
blog-bot.json Normal file
View File

@ -0,0 +1,7 @@
{
"syncToken": "s15_108_10_8_22_1_32_28_0_1_1",
"filter": null,
"appserviceUsers": {},
"appserviceTransactions": {},
"kvStore": {}
}

41
blogbot.ts Normal file
View File

@ -0,0 +1,41 @@
import {
MatrixAuth,
MatrixClient,
SimpleFsStorageProvider,
AutojoinRoomsMixin,
} from "matrix-bot-sdk";
const homeserverUrl = "https://chat.ryanpandya.com";
const auth = new MatrixAuth(homeserverUrl);
const loginClient = await auth.passwordLogin("blogbot", "pleasework");
const blogbotToken = loginClient.accessToken;
console.log(blogbotToken);
const storage = new SimpleFsStorageProvider("blog-bot.json");
const client = new MatrixClient(homeserverUrl, blogbotToken, storage);
AutojoinRoomsMixin.setupOnClient(client);
// Before we start the bot, register our command handler
client.on("room.message", handleCommand);
// Now that everything is set up, start the bot. This will start the sync loop and run until killed.
client.start().then(() => console.log("Bot started!"));
// This is the command handler we registered a few lines up
async function handleCommand(roomId: string, event: any) {
console.log(roomId);
console.log(event);
// Don't handle unhelpful events (ones that aren't text messages, are redacted, or sent by us)
if (event['content']?.['msgtype'] !== 'm.text') return;
if (event['sender'] === await client.getUserId()) return;
// Check to ensure that the `!hello` command is being run
const body = event['content']['body'];
if (!body?.startsWith("!hello")) return;
// Now that we've passed all the checks, we can actually act upon the command
await client.replyNotice(roomId, event, "Hello world!");
}

1299
bun.lock Normal file

File diff suppressed because it is too large Load Diff

View File

@ -27,6 +27,7 @@
postgresql
inotify-tools
claude-code
bun
];
};
}

View File

@ -18,7 +18,11 @@
"@tailwindcss/vite": "^4.1.18",
"astro": "^5.16.6",
"clsx": "^2.1.1",
"matrix-bot-sdk": "^0.8.0",
"tailwind-merge": "^3.4.0",
"tailwindcss": "^4.1.18"
}
},
"trustedDependencies": [
"@matrix-org/matrix-sdk-crypto-nodejs"
]
}