mjolnir/src/index.ts

63 lines
2.0 KiB
TypeScript
Raw Normal View History

2019-09-25 22:13:20 -04:00
/*
2020-06-12 10:03:08 -04:00
Copyright 2019, 2020 The Matrix.org Foundation C.I.C.
2019-09-25 22:13:20 -04:00
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import * as path from "path";
import {
LogLevel,
2019-09-25 22:13:20 -04:00
LogService,
MatrixClient,
PantalaimonClient,
2019-09-25 22:13:20 -04:00
RichConsoleLogger,
SimpleFsStorageProvider
} from "matrix-bot-sdk";
import config from "./config";
2019-11-06 20:46:49 -05:00
import { logMessage } from "./LogProxy";
2020-06-12 10:03:08 -04:00
import { Healthz } from "./health/healthz";
import { Mjolnir } from "./Mjolnir";
2019-11-06 20:46:49 -05:00
2021-07-22 02:38:44 -04:00
config.RUNTIME = {};
2019-09-25 22:13:20 -04:00
LogService.setLogger(new RichConsoleLogger());
LogService.setLevel(LogLevel.fromString(config.logLevel, LogLevel.DEBUG));
LogService.info("index", "Starting bot...");
2019-09-25 22:13:20 -04:00
2020-06-12 10:03:08 -04:00
Healthz.isHealthy = false; // start off unhealthy
if (config.health.healthz.enabled) {
Healthz.listen();
}
(async function () {
2021-09-24 05:12:18 -04:00
const storagePath = path.isAbsolute(config.dataPath) ? config.dataPath : path.join(__dirname, '../', config.dataPath);
const storage = new SimpleFsStorageProvider(path.join(storagePath, "bot.json"));
2019-09-25 22:13:20 -04:00
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);
}
2019-11-06 20:46:49 -05:00
config.RUNTIME.client = client;
let bot = await Mjolnir.setupMjolnirFromConfig(client);
2019-09-27 17:15:10 -04:00
await bot.start();
})().catch(err => {
logMessage(LogLevel.ERROR, "index", err);
process.exit(1);
});