mirror of
https://github.com/stakwork/sphinx-relay.git
synced 2026-08-13 12:33:24 +02:00
commit
c0962f5f27
9 changed files with 75 additions and 27 deletions
3
dist/src/builtin/kick.js
vendored
3
dist/src/builtin/kick.js
vendored
|
|
@ -168,7 +168,8 @@ function init() {
|
|||
},
|
||||
{ name: 'Help', value: '/kick help' },
|
||||
])
|
||||
.setThumbnail(botSVG);
|
||||
.setThumbnail(botSVG)
|
||||
.setOnlyOwner(true);
|
||||
message.channel.send({ embed });
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
2
dist/src/builtin/kick.js.map
vendored
2
dist/src/builtin/kick.js.map
vendored
File diff suppressed because one or more lines are too long
21
dist/src/builtin/mother.js
vendored
21
dist/src/builtin/mother.js
vendored
|
|
@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.init = void 0;
|
||||
exports.init = exports.adminsOnlyBot = void 0;
|
||||
// import * as SphinxBot from '../../../sphinx-bot'
|
||||
const Sphinx = require("sphinx-bot");
|
||||
const botapi_1 = require("../controllers/botapi");
|
||||
|
|
@ -79,6 +79,7 @@ const builtInBotNames = {
|
|||
spam_gone: 'SpamGoneBot',
|
||||
[`${ml_1.ML_PREFIX.substring(1)}`]: ml_1.ML_BOTNAME,
|
||||
};
|
||||
exports.adminsOnlyBot = ['kick'];
|
||||
function init() {
|
||||
const client = new Sphinx.Client();
|
||||
client.login('_', botapi_1.finalAction);
|
||||
|
|
@ -108,7 +109,8 @@ function init() {
|
|||
if (existing) {
|
||||
const embed = new Sphinx.MessageEmbed()
|
||||
.setAuthor('MotherBot')
|
||||
.setDescription(botName + ' already installed');
|
||||
.setDescription(botName + ' already installed')
|
||||
.setOnlyOwner(exports.adminsOnlyBot.includes(botName) || false);
|
||||
return message.channel.send({ embed });
|
||||
}
|
||||
const msgTypes = builtInBotMsgTypes[botName] || [
|
||||
|
|
@ -132,7 +134,8 @@ function init() {
|
|||
const theName = builtInBotNames[botName] || 'Bot';
|
||||
const embed = new Sphinx.MessageEmbed()
|
||||
.setAuthor('MotherBot')
|
||||
.setDescription(theName + ' has been installed!');
|
||||
.setDescription(theName + ' has been installed!')
|
||||
.setOnlyOwner(exports.adminsOnlyBot.includes(botName) || false);
|
||||
message.channel.send({ embed });
|
||||
}
|
||||
else {
|
||||
|
|
@ -144,7 +147,8 @@ function init() {
|
|||
if (existing) {
|
||||
const embed = new Sphinx.MessageEmbed()
|
||||
.setAuthor('MotherBot')
|
||||
.setDescription(botName + ' already installed');
|
||||
.setDescription(botName + ' already installed')
|
||||
.setOnlyOwner(exports.adminsOnlyBot.includes(botName) || false);
|
||||
return message.channel.send({ embed });
|
||||
}
|
||||
// bot from tribes registry
|
||||
|
|
@ -159,7 +163,8 @@ function init() {
|
|||
else {
|
||||
const embed = new Sphinx.MessageEmbed()
|
||||
.setAuthor('MotherBot')
|
||||
.setDescription('No bot with that name');
|
||||
.setDescription('No bot with that name')
|
||||
.setOnlyOwner(exports.adminsOnlyBot.includes(botName) || false);
|
||||
message.channel.send({ embed });
|
||||
}
|
||||
}
|
||||
|
|
@ -182,13 +187,15 @@ function init() {
|
|||
yield existing2.destroy();
|
||||
const embed = new Sphinx.MessageEmbed()
|
||||
.setAuthor('MotherBot')
|
||||
.setDescription(botName2 + ' has been removed');
|
||||
.setDescription(botName2 + ' has been removed')
|
||||
.setOnlyOwner(exports.adminsOnlyBot.includes(botName2) || false);
|
||||
return message.channel.send({ embed });
|
||||
}
|
||||
else {
|
||||
const embed = new Sphinx.MessageEmbed()
|
||||
.setAuthor('MotherBot')
|
||||
.setDescription('Cant find a bot by that name');
|
||||
.setDescription('Cant find a bot by that name')
|
||||
.setOnlyOwner(exports.adminsOnlyBot.includes(botName2) || false);
|
||||
return message.channel.send({ embed });
|
||||
}
|
||||
case 'search':
|
||||
|
|
|
|||
2
dist/src/builtin/mother.js.map
vendored
2
dist/src/builtin/mother.js.map
vendored
File diff suppressed because one or more lines are too long
27
dist/src/network/send.js
vendored
27
dist/src/network/send.js
vendored
|
|
@ -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,27 +424,41 @@ 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] &&
|
||||
bot.hiddenCommands &&
|
||||
JSON.parse(bot.hiddenCommands).includes(splitedContent[1]);
|
||||
const isPersonal = bot.botPrefix === ml_1.ML_PREFIX;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
2
dist/src/network/send.js.map
vendored
2
dist/src/network/send.js.map
vendored
File diff suppressed because one or more lines are too long
|
|
@ -178,6 +178,7 @@ export function init() {
|
|||
{ name: 'Help', value: '/kick help' },
|
||||
])
|
||||
.setThumbnail(botSVG)
|
||||
.setOnlyOwner(true)
|
||||
message.channel.send({ embed })
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,6 +75,8 @@ const builtInBotNames = {
|
|||
[`${ML_PREFIX.substring(1)}`]: ML_BOTNAME,
|
||||
}
|
||||
|
||||
export const adminsOnlyBot = ['kick']
|
||||
|
||||
export function init() {
|
||||
const client = new Sphinx.Client()
|
||||
client.login('_', finalAction)
|
||||
|
|
@ -105,6 +107,7 @@ export function init() {
|
|||
const embed = new Sphinx.MessageEmbed()
|
||||
.setAuthor('MotherBot')
|
||||
.setDescription(botName + ' already installed')
|
||||
.setOnlyOwner(adminsOnlyBot.includes(botName) || false)
|
||||
return message.channel.send({ embed })
|
||||
}
|
||||
const msgTypes = builtInBotMsgTypes[botName] || [
|
||||
|
|
@ -129,6 +132,7 @@ export function init() {
|
|||
const embed = new Sphinx.MessageEmbed()
|
||||
.setAuthor('MotherBot')
|
||||
.setDescription(theName + ' has been installed!')
|
||||
.setOnlyOwner(adminsOnlyBot.includes(botName) || false)
|
||||
message.channel.send({ embed })
|
||||
} else {
|
||||
const chat = await getTribeOwnersChatByUUID(message.channel.id)
|
||||
|
|
@ -141,6 +145,7 @@ export function init() {
|
|||
const embed = new Sphinx.MessageEmbed()
|
||||
.setAuthor('MotherBot')
|
||||
.setDescription(botName + ' already installed')
|
||||
.setOnlyOwner(adminsOnlyBot.includes(botName) || false)
|
||||
return message.channel.send({ embed })
|
||||
}
|
||||
// bot from tribes registry
|
||||
|
|
@ -155,6 +160,7 @@ export function init() {
|
|||
const embed = new Sphinx.MessageEmbed()
|
||||
.setAuthor('MotherBot')
|
||||
.setDescription('No bot with that name')
|
||||
.setOnlyOwner(adminsOnlyBot.includes(botName) || false)
|
||||
message.channel.send({ embed })
|
||||
}
|
||||
}
|
||||
|
|
@ -178,11 +184,13 @@ export function init() {
|
|||
const embed = new Sphinx.MessageEmbed()
|
||||
.setAuthor('MotherBot')
|
||||
.setDescription(botName2 + ' has been removed')
|
||||
.setOnlyOwner(adminsOnlyBot.includes(botName2) || false)
|
||||
return message.channel.send({ embed })
|
||||
} else {
|
||||
const embed = new Sphinx.MessageEmbed()
|
||||
.setAuthor('MotherBot')
|
||||
.setDescription('Cant find a bot by that name')
|
||||
.setOnlyOwner(adminsOnlyBot.includes(botName2) || false)
|
||||
return message.channel.send({ embed })
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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,11 +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
|
||||
|
|
@ -556,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]
|
||||
|
||||
|
|
@ -565,15 +585,11 @@ async function interceptTribeMsgForHiddenCmds(
|
|||
bot.botPrefix === splitedContent[0] &&
|
||||
bot.hiddenCommands &&
|
||||
JSON.parse(bot.hiddenCommands).includes(splitedContent[1])
|
||||
const isPersonal = bot.botPrefix === ML_PREFIX
|
||||
const isPersonal =
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue