update: ensured install and uninstall commands entered by the admin is not visible to users

This commit is contained in:
Oluwatobi Bamidele 2024-03-27 21:01:24 +01:00
parent f54d2f5bbb
commit 48d023e96b
3 changed files with 41 additions and 15 deletions

View file

@ -24,6 +24,7 @@ const proxy_1 = require("../utils/proxy");
const ml_1 = require("../builtin/ml");
const intercept = require("./intercept");
const receive_1 = require("./receive");
const mother_1 = require("../builtin/mother");
const config = (0, config_1.loadConfig)();
/**
* Sends a message to a chat.
@ -423,18 +424,32 @@ function compareAliases(alias1, alias2) {
});
return match;
}
function updateMessageToIsOnlyOwner(uuid, tenant) {
return __awaiter(this, void 0, void 0, function* () {
yield models_1.models.Message.update({
onlyOwner: true,
}, { where: { uuid, tenant } });
});
}
function interceptTribeMsgForHiddenCmds(msg, tenant) {
return __awaiter(this, void 0, void 0, function* () {
const hideAllCommandsBot = ['/kick'];
try {
const content = msg.message.content;
const splitedContent = (content && content.split(' ')) || [];
if (splitedContent[0] === '/bot') {
if (mother_1.adminsOnlyBot.includes(splitedContent[2])) {
yield updateMessageToIsOnlyOwner(msg.message.uuid, tenant);
return true;
}
return false;
}
const newChat = (yield models_1.models.Chat.findOne({
where: { uuid: msg.chat.uuid },
}));
const bots = (yield models_1.models.ChatBot.findAll({
where: { tenant, chatId: newChat.id },
}));
const content = msg.message.content;
const splitedContent = (content && content.split(' ')) || [];
for (let i = 0; i < bots.length; i++) {
const bot = bots[i];
const isHidden = bot.botPrefix === splitedContent[0] &&
@ -443,9 +458,7 @@ function interceptTribeMsgForHiddenCmds(msg, tenant) {
const isPersonal = bot.botPrefix === ml_1.ML_PREFIX ||
hideAllCommandsBot.includes(bot.botPrefix);
if (isHidden || isPersonal) {
yield models_1.models.Message.update({
onlyOwner: true,
}, { where: { uuid: msg.message.uuid, tenant } });
yield updateMessageToIsOnlyOwner(msg.message.uuid, tenant);
return true;
}
}

File diff suppressed because one or more lines are too long

View file

@ -26,6 +26,7 @@ import { ML_PREFIX } from '../builtin/ml'
import { Msg, MessageContent, ChatMember } from './interfaces'
import * as intercept from './intercept'
import { typesToForward, receiveCoTenantMessage } from './receive'
import { adminsOnlyBot } from '../builtin/mother'
const config = loadConfig()
@ -543,12 +544,32 @@ function compareAliases(alias1: string, alias2: string): boolean {
return match
}
async function updateMessageToIsOnlyOwner(uuid: string, tenant: number) {
await models.Message.update(
{
onlyOwner: true,
},
{ where: { uuid, tenant } }
)
}
async function interceptTribeMsgForHiddenCmds(
msg: Msg,
tenant: number
): Promise<boolean> {
const hideAllCommandsBot = ['/kick']
try {
const content = msg.message.content as string
const splitedContent = (content && content.split(' ')) || []
if (splitedContent[0] === '/bot') {
if (adminsOnlyBot.includes(splitedContent[2])) {
await updateMessageToIsOnlyOwner(msg.message.uuid, tenant)
return true
}
return false
}
const newChat = (await models.Chat.findOne({
where: { uuid: msg.chat.uuid },
})) as ChatRecord
@ -557,8 +578,6 @@ async function interceptTribeMsgForHiddenCmds(
where: { tenant, chatId: newChat.id },
})) as ChatBotRecord[]
const content = msg.message.content as string
const splitedContent = (content && content.split(' ')) || []
for (let i = 0; i < bots.length; i++) {
const bot = bots[i]
@ -570,13 +589,7 @@ async function interceptTribeMsgForHiddenCmds(
bot.botPrefix === ML_PREFIX ||
hideAllCommandsBot.includes(bot.botPrefix)
if (isHidden || isPersonal) {
await models.Message.update(
{
onlyOwner: true,
},
{ where: { uuid: msg.message.uuid, tenant } }
)
await updateMessageToIsOnlyOwner(msg.message.uuid, tenant)
return true
}
}