Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
// We'll want to make sure the bot doesn't have to do an initial sync every
// time it restarts, so we need to prepare a storage provider. Here we use
// a simple JSON database.
const storage = new SimpleFsStorageProvider(
path.join(storageDir, "matrix.json")
);
// Now we can create the client and set it up to automatically join rooms.
const client = new MatrixClient(
config.homeserverUrl,
config.accessToken,
storage
);
AutojoinRoomsMixin.setupOnClient(client);
// We also want to make sure we can receive events - this is where we will
// handle our command.
client.on("room.message", makeHandleCommand(client, config));
// Now that the client is all set up and the event handler is registered, start the
// client up. This will start it syncing.
await client.start();
console.log("Client started!");
}
(async function () {
const storage = new SimpleFsStorageProvider(path.join(config.dataPath, "bot.json"));
let client: MatrixClient;
if (config.pantalaimon.use) {
const pantalaimon = new PantalaimonClient(config.homeserverUrl, storage);
client = await pantalaimon.createClientWithCredentials(config.pantalaimon.username, config.pantalaimon.password);
} else {
client = new MatrixClient(config.homeserverUrl, config.accessToken, storage);
}
if (config.autojoin) {
AutojoinRoomsMixin.setupOnClient(client);
}
const banLists: BanList[] = [];
const protectedRooms: { [roomId: string]: string } = {};
const joinedRooms = await client.getJoinedRooms();
// Ensure we're also joined to the rooms we're protecting
for (const roomRef of config.protectedRooms) {
const permalink = Permalinks.parseUrl(roomRef);
if (!permalink.roomIdOrAlias) continue;
let roomId = await client.resolveRoom(permalink.roomIdOrAlias);
if (!joinedRooms.includes(roomId)) {
roomId = await client.joinRoom(permalink.roomIdOrAlias, permalink.viaServers);
}