Add blogbot script
This commit is contained in:
parent
b7b189a82c
commit
c2108c4f83
7
blog-bot.json
Normal file
7
blog-bot.json
Normal 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
41
blogbot.ts
Normal 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!");
|
||||||
|
}
|
||||||
@ -27,6 +27,7 @@
|
|||||||
postgresql
|
postgresql
|
||||||
inotify-tools
|
inotify-tools
|
||||||
claude-code
|
claude-code
|
||||||
|
bun
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,7 +18,11 @@
|
|||||||
"@tailwindcss/vite": "^4.1.18",
|
"@tailwindcss/vite": "^4.1.18",
|
||||||
"astro": "^5.16.6",
|
"astro": "^5.16.6",
|
||||||
"clsx": "^2.1.1",
|
"clsx": "^2.1.1",
|
||||||
|
"matrix-bot-sdk": "^0.8.0",
|
||||||
"tailwind-merge": "^3.4.0",
|
"tailwind-merge": "^3.4.0",
|
||||||
"tailwindcss": "^4.1.18"
|
"tailwindcss": "^4.1.18"
|
||||||
}
|
},
|
||||||
|
"trustedDependencies": [
|
||||||
|
"@matrix-org/matrix-sdk-crypto-nodejs"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user