diff --git a/example.js b/example.js index 771a2b3..931cb8c 100644 --- a/example.js +++ b/example.js @@ -31,6 +31,15 @@ searx.setRoomCooldowns(new Map([ searx.setSearxInstance("https://searx.example.com"); searx.setSearxParameters("disabled_engines=flickr__images"); +searxng.setRoomUserWhitelists(new Map([ + ["!blahblahblah:midov.pl", + [ + "@q:glowers.club", + "@midek:midov.pl" + ] + ] +])); + matrixClient.on("Room.timeline", function(event, room, toStartOfTimeline) { if (event.getTs() >= startupTime && event.getType() == "m.room.message" && event.getContent().body != null) { diff --git a/index.js b/index.js index 83eab13..213b843 100644 --- a/index.js +++ b/index.js @@ -5,6 +5,7 @@ function Searxng(matrixClient) { this.blacklistedUimgRooms = []; this.cooldownImmuneUsers = []; this.roomCooldowns = new Map(); + this.roomUserWhitelists = new Map(); this.searxngInstance = ""; this.searxngParameters = "enabled_engines=duckduckgo images__images,google images__images,bing images__images&disabled_engines=flickr__images,nyaa__images,qwant images__images,artic__images,deviantart__images,library of congress__images,unsplash__images,openverse__images" } @@ -14,6 +15,7 @@ Searxng.prototype.setBlacklistedImgRooms = function(blacklistedImgRooms){ this.b Searxng.prototype.setBlacklistedUimgRooms = function(blacklistedUimgRooms){ this.blacklistedUimgRooms = blacklistedUimgRooms; }; Searxng.prototype.setCooldownImmuneUsers = function(cooldownImmuneUsers){ this.cooldownImmuneUsers = cooldownImmuneUsers; }; Searxng.prototype.setRoomCooldowns = function(roomCooldowns){ this.roomCooldowns = roomCooldowns; }; +Searxng.prototype.setRoomUserWhitelists = function(roomUserWhitelists){ this.roomUserWhitelists = roomUserWhitelists; }; Searxng.prototype.setSearxngInstance = function(searxngInstance){ this.searxngInstance = searxngInstance; }; Searxng.prototype.setSearxngParameters = function(searxngParameters){ this.searxngParameters = searxngParameters; }; @@ -124,6 +126,10 @@ Searxng.prototype.handleMessage = function(event, room) { console.warn("Don't have permission to post in room "+room.roomId); return; } + else if (this.roomUserWhitelists.has(room.roomId) && this.roomUserWhitelists.get(room.roomId).indexOf(event.getSender()) < 0) { + this.matrixClient.sendNotice(room.roomId, "You are not on the whitelist for this room."); + return; + } else if (this.cooldownImmuneUsers.indexOf(event.getSender()) < 0) { const roomCooldown = this.roomCooldowns.get(room.roomId);