├── .gitignore ├── README.md ├── package.json ├── plugin.json └── lib.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # nodebb-plugin-chat-perms 2 | Provides tighter control over chats in Nodebb 3 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nodebb-plugin-chat-perms", 3 | "version": "1.1.0", 4 | "description": "", 5 | "main": "lib.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/yossizahn/nodebb-plugin-chat-perms" 12 | }, 13 | "author": "Yossi Zahn ", 14 | "license": "MIT", 15 | "bugs": { 16 | "url": "https://github.com/yossizahn/nodebb-plugin-chat-perms/issues" 17 | }, 18 | "dependencies": { 19 | "moment": "^2.29.1" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /plugin.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "nodebb-plugin-chat-perms", 3 | "library": "./lib.js", 4 | "hooks": [ 5 | { "hook": "filter:messaging.canGetMessages", "method": "canGetMessages" }, 6 | { "hook": "filter:messaging.canGetRecentChats", "method": "canGetMessages" }, 7 | { "hook": "filter:messaging.canReply", "method": "canReply" }, 8 | { "hook": "static:messaging.canMessageUser", "method": "canMessageUser" }, 9 | { "hook": "static:messaging.canMessageRoom", "method": "canMessageRoom" }, 10 | { "hook": "filter:messaging.isUserInRoom", "method": "isUserInRoom" } 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /lib.js: -------------------------------------------------------------------------------- 1 | const User = require.main.require('./src/user'); 2 | const Groups = require.main.require('./src/groups'); 3 | const moment = require('moment'); 4 | 5 | let pluginSettings; 6 | try { 7 | pluginSettings = JSON.parse(process.env.CHAT_PERMS_PLUGIN_SETTINGS); 8 | } catch { 9 | pluginSettings = {}; 10 | } 11 | 12 | const ADMIN_UIDS = pluginSettings.ADMIN_UIDS || [1]; // ניתן להגדיר כאן את מזהה המשתמש שיוכל לצפות בצ'אטים של אחרים 13 | const ALLOW_CHAT_GROUP = pluginSettings.ALLOW_CHAT_GROUP || 'allowChat'; // ניתן להגדיר כאן את שם הקבוצה שיהיו מותרים להשתמש בצ'אט בלי תנאים 14 | const DENY_CHAT_GROUP = pluginSettings.DENY_CHAT_GROUP || 'denyChat'; // ניתן להגדיר כאן את שם הקבוצה שיהיו אסורים להשתמש בצ'אט בלי תנאים 15 | const MIN_REPUTATION = pluginSettings.MIN_REPUTATION ?? 10; // ניתן להגדיר כאן את המוניטין שצריך לצבור כדי להשתשמש בצא'ט 16 | const MIN_POSTS = pluginSettings.MIN_POSTS ?? 5; // ניתן להגדיר כאן את כמות הפוסטים שצריך לצבור כדי להשתשמש בצא'ט 17 | const CHAT_NOT_YET_ALLOWED_MESSAGE = pluginSettings.CHAT_NOT_YET_ALLOWED_MESSAGE || 'CHAT_NOT_YET_ALLOWED_MESSAGE'; // כאן ניתן להגדיר את ההודעה שמשתמש שעוד לא צבר מספיק וותק יקבל אם ינסה לפתוח צ'אט 18 | const CHAT_DENIED_MESSAGE = pluginSettings.CHAT_DENIED_MESSAGE || 'CHAT_DENIED_MESSAGE'; // כאן ניתן להגדיר את ההודעה שמשתמש חסום יקבל אם ינסה לפתוח צ'אט 19 | 20 | module.exports = { 21 | async canGetMessages (data) { 22 | data.canGet = true; 23 | const userData = await User.getUserData(data.callerUid); 24 | const userGroups = await Groups.getUserGroupsFromSet('groups:createtime', [data.callerUid]); 25 | if ( 26 | (userData.reputation < MIN_REPUTATION || userData.postcount < MIN_POSTS || moment(userData.joindate).isAfter(moment() /* .subtract(1, 'month') */)) && 27 | !userGroups[0].find(group => [ 28 | 'administrators', 29 | 'Global Moderators', 30 | ALLOW_CHAT_GROUP 31 | ].includes(group.name)) 32 | ) { 33 | throw new Error(CHAT_NOT_YET_ALLOWED_MESSAGE); 34 | } 35 | if (userGroups[0].find(group => group.name === DENY_CHAT_GROUP)) { 36 | throw new Error(CHAT_DENIED_MESSAGE); 37 | } 38 | if (data.callerUid !== data.uid && !ADMIN_UIDS.includes(data.callerUid)) throw new Error('אין גישה!'); 39 | return data; 40 | }, 41 | async canReply (data) { return data; }, 42 | async canMessageUser (data) { 43 | const userData = await User.getUserData(data.uid); 44 | const userGroups = await Groups.getUserGroupsFromSet('groups:createtime', [data.uid]); 45 | if ( 46 | (userData.reputation < MIN_REPUTATION || userData.postcount < MIN_POSTS || moment(userData.joindate).isAfter(moment() /* .subtract(1, 'month') */)) && 47 | !userGroups[0].find(group => [ 48 | 'administrators', 49 | 'Global Moderators', 50 | ALLOW_CHAT_GROUP 51 | ].includes(group.name)) 52 | ) { 53 | throw new Error(CHAT_NOT_YET_ALLOWED_MESSAGE); 54 | } 55 | if (userGroups[0].find(group => group.name === DENY_CHAT_GROUP)) { 56 | throw new Error(CHAT_DENIED_MESSAGE); 57 | } 58 | }, 59 | async canMessageRoom () {}, 60 | async isUserInRoom (data) { 61 | if (ADMIN_UIDS.includes(data.uid)) { data.inRoom = true; } 62 | return data; 63 | } 64 | }; 65 | --------------------------------------------------------------------------------