diff --git a/README.md b/README.md index 597e764..fef34b5 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Phase 1: * [x] Update lists with new bans/ACLs Phase 2: -* [ ] Pantalaimon support +* [x] Pantalaimon support * [ ] Redact messages on ban (optionally) * [ ] Less spam in management room * [ ] Vet rooms on startup option diff --git a/config/default.yaml b/config/default.yaml index 6230223..2a61f29 100644 --- a/config/default.yaml +++ b/config/default.yaml @@ -1,9 +1,23 @@ -# Where the homeserver is located (client-server URL) +# Where the homeserver is located (client-server URL). This should point at +# pantalaimon if you're using that. homeserverUrl: "https://matrix.org" -# The access token for the bot to use +# The access token for the bot to use. Do not populate if using Pantalaimon. accessToken: "YOUR_TOKEN_HERE" +# Pantalaimon options (https://github.com/matrix-org/pantalaimon) +pantalaimon: + # If true, accessToken above is ignored and the username/password below will be + # used instead. The access token of the bot will be stored in the dataPath. + use: false + + # The username to login with. + username: mjolnir + + # The password to login with. Can be removed after the bot has logged in once and + # stored the access token. + password: your_password + # The directory the bot should store various bits of information in dataPath: "/data/storage" diff --git a/src/config.ts b/src/config.ts index 8443955..701bb59 100644 --- a/src/config.ts +++ b/src/config.ts @@ -19,6 +19,11 @@ import * as config from "config"; interface IConfig { homeserverUrl: string; accessToken: string; + pantalaimon: { + use: boolean; + username: string; + password: string; + }; dataPath: string; autojoin: boolean; managementRoom: string; diff --git a/src/index.ts b/src/index.ts index af1237d..3e23cca 100644 --- a/src/index.ts +++ b/src/index.ts @@ -19,6 +19,7 @@ import { AutojoinRoomsMixin, LogService, MatrixClient, + PantalaimonClient, Permalinks, RichConsoleLogger, SimpleFsStorageProvider @@ -29,14 +30,21 @@ import { Mjolnir } from "./Mjolnir"; LogService.setLogger(new RichConsoleLogger()); -const storage = new SimpleFsStorageProvider(path.join(config.dataPath, "bot.json")); -const client = new MatrixClient(config.homeserverUrl, config.accessToken, storage); - -if (config.autojoin) { - AutojoinRoomsMixin.setupOnClient(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 } = {};