Skip to content
Extraits de code Groupes Projets
Valider d96388f6 rédigé par Christian Paul's avatar Christian Paul
Parcourir les fichiers

Add limits.roomCount

parent 1599249d
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -102,6 +102,8 @@ limits: ...@@ -102,6 +102,8 @@ limits:
# echos = (Copies of a sent message may arrive from discord before we've # echos = (Copies of a sent message may arrive from discord before we've
# fininished handling it, causing us to echo it back to the room) # fininished handling it, causing us to echo it back to the room)
discordSendDelay: 1500 discordSendDelay: 1500
# Set a maximum of rooms to be bridged.
# roomCount: 20
ghosts: ghosts:
# Pattern for the ghosts nick, available is :nick, :username, :tag and :id # Pattern for the ghosts nick, available is :nick, :username, :tag and :id
nickPattern: ":nick" nickPattern: ":nick"
......
...@@ -97,6 +97,8 @@ properties: ...@@ -97,6 +97,8 @@ properties:
type: "number" type: "number"
discordSendDelay: discordSendDelay:
type: "number" type: "number"
roomCount:
type: "number"
channel: channel:
type: "object" type: "object"
properties: properties:
......
...@@ -141,6 +141,7 @@ export class DiscordBridgeConfigChannelDeleteOptions { ...@@ -141,6 +141,7 @@ export class DiscordBridgeConfigChannelDeleteOptions {
class DiscordBridgeConfigLimits { class DiscordBridgeConfigLimits {
public roomGhostJoinDelay: number = 6000; public roomGhostJoinDelay: number = 6000;
public discordSendDelay: number = 1500; public discordSendDelay: number = 1500;
public roomCount: number = -1;
} }
export class LoggingFile { export class LoggingFile {
......
...@@ -84,6 +84,14 @@ export class MatrixCommandHandler { ...@@ -84,6 +84,14 @@ export class MatrixCommandHandler {
if (!guildId || !channelId) { if (!guildId || !channelId) {
return "Invalid syntax. For more information try `!discord help bridge`"; return "Invalid syntax. For more information try `!discord help bridge`";
} }
if (await this.provisioner.RoomCountLimitReached(this.config.limits.roomCount)) {
log.info(`Room count limit (value: ${this.config.limits.roomCount}) reached: Rejecting command to bridge new matrix room ${event.room_id} to ${guildId}/${channelId}`);
await this.bridge.botIntent.sendText(
event.room_id,
`This bridge has reached its room limit of ${this.config.limits.roomCount}. Unbridge another room to allow for new connections.`,
"m.notice",
);
}
try { try {
const discordResult = await this.discord.LookupRoom(guildId, channelId); const discordResult = await this.discord.LookupRoom(guildId, channelId);
const channel = discordResult.channel as Discord.TextChannel; const channel = discordResult.channel as Discord.TextChannel;
......
...@@ -40,6 +40,15 @@ export class Provisioner { ...@@ -40,6 +40,15 @@ export class Provisioner {
return this.roomStore.linkRooms(local, remote); return this.roomStore.linkRooms(local, remote);
} }
/**
* Returns if the room count limit has been reached.
* This can be set by the bridge admin and prevents new rooms from being bridged.
* @returns Has the limit been reached?
*/
public async RoomCountLimitReached(limit: number): Promise<boolean> {
return limit >= 0 || limit >= await this.roomStore.countEntries();
}
public async UnbridgeChannel(channel: Discord.TextChannel, rId?: string) { public async UnbridgeChannel(channel: Discord.TextChannel, rId?: string) {
const roomsRes = await this.roomStore.getEntriesByRemoteRoomData({ const roomsRes = await this.roomStore.getEntriesByRemoteRoomData({
discord_channel: channel.id, discord_channel: channel.id,
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter