Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const config = loadConfig(configFilename);
const prefix = configFilename.replace(".json", "").replace("config-", "");
const storageDir = path.join("data", prefix);
if (!fs.existsSync("./data")) {
fs.mkdirSync("./data");
}
if (!fs.existsSync(storageDir)) {
fs.mkdirSync(storageDir);
}
// 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
constructor() {
this.client = new MatrixClient(
config.homeserver.clientServerUrl,
config.homeserver.accessToken,
new SimpleFsStorageProvider(config.database.botData));
this.client.setJoinStrategy(new SimpleRetryJoinStrategy());
this.client.on("room.event", this.onEvent.bind(this));
AutojoinUpgradedRoomsMixin.setupOnClient(this.client);
}
(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 } = {};