Adding per-room whitelists to only allow some users to search

This commit is contained in:
q 2024-04-27 14:00:42 -04:00
parent 4bd43a9630
commit 3dc55070f7
2 changed files with 15 additions and 0 deletions

View File

@ -31,6 +31,15 @@ searx.setRoomCooldowns(new Map([
searx.setSearxInstance("https://searx.example.com"); searx.setSearxInstance("https://searx.example.com");
searx.setSearxParameters("disabled_engines=flickr__images"); 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) { matrixClient.on("Room.timeline", function(event, room, toStartOfTimeline) {
if (event.getTs() >= startupTime && event.getType() == "m.room.message" && event.getContent().body != null) { if (event.getTs() >= startupTime && event.getType() == "m.room.message" && event.getContent().body != null) {

View File

@ -5,6 +5,7 @@ function Searxng(matrixClient) {
this.blacklistedUimgRooms = []; this.blacklistedUimgRooms = [];
this.cooldownImmuneUsers = []; this.cooldownImmuneUsers = [];
this.roomCooldowns = new Map(); this.roomCooldowns = new Map();
this.roomUserWhitelists = new Map();
this.searxngInstance = ""; 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" 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.setBlacklistedUimgRooms = function(blacklistedUimgRooms){ this.blacklistedUimgRooms = blacklistedUimgRooms; };
Searxng.prototype.setCooldownImmuneUsers = function(cooldownImmuneUsers){ this.cooldownImmuneUsers = cooldownImmuneUsers; }; Searxng.prototype.setCooldownImmuneUsers = function(cooldownImmuneUsers){ this.cooldownImmuneUsers = cooldownImmuneUsers; };
Searxng.prototype.setRoomCooldowns = function(roomCooldowns){ this.roomCooldowns = roomCooldowns; }; 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.setSearxngInstance = function(searxngInstance){ this.searxngInstance = searxngInstance; };
Searxng.prototype.setSearxngParameters = function(searxngParameters){ this.searxngParameters = searxngParameters; }; 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); console.warn("Don't have permission to post in room "+room.roomId);
return; 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) { else if (this.cooldownImmuneUsers.indexOf(event.getSender()) < 0) {
const roomCooldown = this.roomCooldowns.get(room.roomId); const roomCooldown = this.roomCooldowns.get(room.roomId);