mirror of
https://github.com/matrix-org/mjolnir.git
synced 2024-06-30 16:41:29 +00:00
Add an option to only autojoin invites from bot managers
This commit is contained in:
parent
38e22ee155
commit
97d02b3816
|
@ -24,6 +24,12 @@ dataPath: "/data/storage"
|
||||||
# Whether the bot should autojoin rooms it is invited to or not
|
# Whether the bot should autojoin rooms it is invited to or not
|
||||||
autojoin: true
|
autojoin: true
|
||||||
|
|
||||||
|
# If `autojoin` is true, this defines whether anyone can invite the bot (the
|
||||||
|
# default), or only those in the `managementRoom` below. Generally this option
|
||||||
|
# should be set to true (only allow people in the management room to do invites)
|
||||||
|
# when using autojoin.
|
||||||
|
autojoinOnlyIfManager: false
|
||||||
|
|
||||||
# The room ID where people can use the bot. The bot has no access controls, so
|
# The room ID where people can use the bot. The bot has no access controls, so
|
||||||
# anyone in this room can use the bot - secure your room!
|
# anyone in this room can use the bot - secure your room!
|
||||||
# This should be a room alias or room ID - not a matrix.to URL.
|
# This should be a room alias or room ID - not a matrix.to URL.
|
||||||
|
|
|
@ -27,6 +27,7 @@ interface IConfig {
|
||||||
};
|
};
|
||||||
dataPath: string;
|
dataPath: string;
|
||||||
autojoin: boolean;
|
autojoin: boolean;
|
||||||
|
autojoinOnlyIfManager: boolean;
|
||||||
managementRoom: string;
|
managementRoom: string;
|
||||||
verboseLogging: boolean;
|
verboseLogging: boolean;
|
||||||
logLevel: "DEBUG" | "INFO" | "WARN" | "ERROR";
|
logLevel: "DEBUG" | "INFO" | "WARN" | "ERROR";
|
||||||
|
|
12
src/index.ts
12
src/index.ts
|
@ -29,6 +29,7 @@ import config from "./config";
|
||||||
import BanList from "./models/BanList";
|
import BanList from "./models/BanList";
|
||||||
import { Mjolnir } from "./Mjolnir";
|
import { Mjolnir } from "./Mjolnir";
|
||||||
import { logMessage } from "./LogProxy";
|
import { logMessage } from "./LogProxy";
|
||||||
|
import { MembershipEvent } from "matrix-bot-sdk/lib/models/events/MembershipEvent";
|
||||||
|
|
||||||
config.RUNTIME = {client: null};
|
config.RUNTIME = {client: null};
|
||||||
|
|
||||||
|
@ -51,7 +52,16 @@ LogService.info("index", "Starting bot...");
|
||||||
config.RUNTIME.client = client;
|
config.RUNTIME.client = client;
|
||||||
|
|
||||||
if (config.autojoin) {
|
if (config.autojoin) {
|
||||||
AutojoinRoomsMixin.setupOnClient(client);
|
if (config.autojoinOnlyIfManager) {
|
||||||
|
client.on("room.invite", async (roomId: string, inviteEvent: any) => {
|
||||||
|
const membershipEvent = new MembershipEvent(inviteEvent);
|
||||||
|
const managers = await client.getJoinedRoomMembers(config.managementRoom);
|
||||||
|
if (!managers.includes(membershipEvent.sender)) return; // ignore invite
|
||||||
|
return client.joinRoom(roomId);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
AutojoinRoomsMixin.setupOnClient(client);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const banLists: BanList[] = [];
|
const banLists: BanList[] = [];
|
||||||
|
|
Loading…
Reference in New Issue
Block a user