mirror of
https://github.com/matrix-org/mjolnir.git
synced 2024-06-28 07:32:30 +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
|
||||
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
|
||||
# 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.
|
||||
|
|
|
@ -27,6 +27,7 @@ interface IConfig {
|
|||
};
|
||||
dataPath: string;
|
||||
autojoin: boolean;
|
||||
autojoinOnlyIfManager: boolean;
|
||||
managementRoom: string;
|
||||
verboseLogging: boolean;
|
||||
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 { Mjolnir } from "./Mjolnir";
|
||||
import { logMessage } from "./LogProxy";
|
||||
import { MembershipEvent } from "matrix-bot-sdk/lib/models/events/MembershipEvent";
|
||||
|
||||
config.RUNTIME = {client: null};
|
||||
|
||||
|
@ -51,7 +52,16 @@ LogService.info("index", "Starting bot...");
|
|||
config.RUNTIME.client = client;
|
||||
|
||||
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[] = [];
|
||||
|
|
Loading…
Reference in New Issue
Block a user