Re-work invite settings to better support practical use cases

This commit is contained in:
Travis Ralston 2020-03-05 15:29:30 -07:00
parent f5763803d9
commit 7314df7379
3 changed files with 20 additions and 20 deletions

View File

@ -21,14 +21,13 @@ pantalaimon:
# The directory the bot should store various bits of information in
dataPath: "/data/storage"
# Whether the bot should autojoin rooms it is invited to or not
autojoin: true
# If true (the default), only users in the `managementRoom` can invite the bot
# to new rooms.
autojoinOnlyIfManager: 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
# If `autojoinOnlyIfManager` is false, only the members in this group can invite
# the bot to new rooms.
acceptInvitesFromGroup: '+example:example.org'
# 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!

View File

@ -26,7 +26,7 @@ interface IConfig {
password: string;
};
dataPath: string;
autojoin: boolean;
acceptInvitesFromGroup: string;
autojoinOnlyIfManager: boolean;
managementRoom: string;
verboseLogging: boolean;
@ -66,7 +66,7 @@ const defaultConfig: IConfig = {
password: "",
},
dataPath: "/data/storage",
autojoin: false,
acceptInvitesFromGroup: '+example:example.org',
autojoinOnlyIfManager: false,
managementRoom: "!noop:example.org",
verboseLogging: false,

View File

@ -16,7 +16,6 @@ limitations under the License.
import * as path from "path";
import {
AutojoinRoomsMixin,
LogLevel,
LogService,
MatrixClient,
@ -30,7 +29,7 @@ import BanList from "./models/BanList";
import { Mjolnir } from "./Mjolnir";
import { logMessage } from "./LogProxy";
import { MembershipEvent } from "matrix-bot-sdk/lib/models/events/MembershipEvent";
import {BanListServer} from "./server/BanListServer";
import { BanListServer } from "./server/BanListServer";
config.RUNTIME = {client: null};
@ -52,18 +51,20 @@ LogService.info("index", "Starting bot...");
config.RUNTIME.client = client;
if (config.autojoin) {
client.on("room.invite", async (roomId: string, inviteEvent: any) => {
const membershipEvent = new MembershipEvent(inviteEvent);
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);
});
const managers = await client.getJoinedRoomMembers(config.managementRoom);
if (!managers.includes(membershipEvent.sender)) return; // ignore invite
} else {
AutojoinRoomsMixin.setupOnClient(client);
const groupMembers = await client.unstableApis.getGroupUsers(config.acceptInvitesFromGroup);
const userIds = groupMembers.map(m => m.user_id);
if (!userIds.includes(membershipEvent.sender)) return; // ignore invite
}
}
return client.joinRoom(roomId);
});
const banLists: BanList[] = [];
const protectedRooms: { [roomId: string]: string } = {};