Browse Source

refactor MotherBot to sphinx.js format, three levels of bots builtin, internal, external, mock bot conn for builtin

push-params
Evan Feenstra 4 years ago
parent
commit
9758441036
  1. 23
      api/bots/index.ts
  2. 47
      api/bots/mother.ts
  3. 0
      api/bots/welcome.ts
  4. 86
      api/controllers/actions.ts
  5. 82
      api/controllers/bots.ts
  6. 7
      api/controllers/index.ts
  7. 3
      api/models/ts/bot.ts
  8. 32
      api/network/intercept.ts
  9. 1
      api/utils/setup.ts
  10. 26
      dist/api/bots/index.js
  11. 1
      dist/api/bots/index.js.map
  12. 54
      dist/api/bots/mother.js
  13. 1
      dist/api/bots/mother.js.map
  14. 1
      dist/api/bots/welcome.js
  15. 1
      dist/api/bots/welcome.js.map
  16. 84
      dist/api/controllers/actions.js
  17. 2
      dist/api/controllers/actions.js.map
  18. 89
      dist/api/controllers/bots.js
  19. 2
      dist/api/controllers/bots.js.map
  20. 7
      dist/api/controllers/index.js
  21. 2
      dist/api/controllers/index.js.map
  22. 4
      dist/api/models/ts/bot.js
  23. 2
      dist/api/models/ts/bot.js.map
  24. 31
      dist/api/network/intercept.js
  25. 2
      dist/api/network/intercept.js.map
  26. 1
      dist/api/utils/setup.js
  27. 2
      dist/api/utils/setup.js.map

23
api/bots/index.ts

@ -0,0 +1,23 @@
import * as Sphinx from '../../../sphinx-bot'
import * as MotherBot from './mother'
function init(){
MotherBot.init()
}
function emit(txt, chatUUID){
const arr = txt.split(' ')
if(arr.length<2) return false
// const cmd = arr[1]
Sphinx.EE.emit('message',{content:txt,chatUUID})
// switch(cmd) {
// case 'install':
// if(arr.length<3) return false
// // installBot(arr[2], botInTribe)
// return true
// default:
// Sphinx.EE.emit('message',cmd,chatUUID)
// }
}
export {init,emit,MotherBot}

47
api/bots/mother.ts

@ -0,0 +1,47 @@
import * as Sphinx from '../../../sphinx-bot'
import {Action, finalAction} from '../controllers/actions'
const msg_types = Sphinx.MSG_TYPE
export function init() {
const client = new Sphinx.Client()
client.login('_', embedToAction)
client.on(msg_types.MESSAGE, async (message:Sphinx.Message) => {
console.log("INCOMING MSG",message)
const embed = new Sphinx.MessageEmbed()
.setAuthor('MotherBot')
.setTitle('Bot Commands:')
.addFields([
{name:'Install a new bot',value:'/bot install {BOTNAME}'},
{name:'Help',value:'/bot help'}
])
message.channel.send({ embed })
})
}
function embedToAction(a){
let text = ''
let botName = 'Bot'
if(a.embed && a.embed.html) {
text = a.embed.html
botName = a.embed.author
} else if(typeof a==='string') {
text = a
}
finalAction(<Action>{
botName,
text, action:'broadcast',
})
}
// const helpHTML=`<div>
// <b>Bot commands:</b>
// <ul>
// <li><b>/bot install {BOTNAME}:</b>&nbsp;Install a new bot
// <li><b>/bot help:</b>&nbsp;Print out this help message
// </ul>
// <div>
// `

0
api/bots/welcome.ts

86
api/controllers/actions.ts

@ -1,13 +1,11 @@
import { success, failure } from '../utils/res'
import * as path from 'path'
import * as network from '../network'
import { models } from '../models'
import * as short from 'short-uuid'
import * as rsa from '../crypto/rsa'
import * as crypto from 'crypto'
import * as jsonUtils from '../utils/json'
import * as tribes from '../utils/tribes'
import * as socket from '../utils/socket'
import { success, failure } from '../utils/res'
/*
hexdump -n 8 -e '4/4 "%08X" 1 "\n"' /dev/random
@ -16,72 +14,9 @@ hexdump -n 16 -e '4/4 "%08X" 1 "\n"' /dev/random
const constants = require(path.join(__dirname, '../../config/constants.json'))
export const getBots = async (req, res) => {
try {
const bots = await models.Bot.findAll()
success(res, {
bots: bots.map(b=> jsonUtils.botToJson(b))
})
} catch(e) {
failure(res,'no bots')
}
}
export const getBotsForTribe = async (req, res) => {
const chat_id = req.params.chat_id
const chatId = parseInt(chat_id)
if(!chatId) return failure(res,'no chat id')
try {
const bots = await models.Bot.findAll({where:{chatId}})
success(res, {
bots: bots.map(b=> jsonUtils.botToJson(b))
})
} catch(e) {
failure(res,'no bots')
}
}
export const createBot = async (req, res) => {
const { chat_id, name, } = req.body
const chatId = parseInt(chat_id)
const chat = await models.Chat.findOne({where:{id:chatId}})
if(!chat) return failure(res,'no chat')
const owner = await models.Contact.findOne({where: {isOwner:true}})
const isTribeOwner = owner.publicKey===chat.ownerPubkey
if(!isTribeOwner) return failure(res, 'not tribe owner')
const uuid = await tribes.genSignedTimestamp()
const newBot = {
uuid,
id: crypto.randomBytes(16).toString('hex').toUpperCase(),
chatId: chat_id,
name: name,
secret: crypto.randomBytes(16).toString('hex').toUpperCase()
}
try {
const theBot = await models.Bot.create(newBot)
success(res, jsonUtils.botToJson(theBot))
} catch (e) {
failure(res, 'bot creation failed')
}
}
export const deleteBot = async (req, res) => {
const id = req.params.id
if (!id) return
try {
models.Bot.destroy({ where: { id } })
success(res, true)
} catch (e) {
console.log('ERROR deleteBot', e)
failure(res, e)
}
}
export interface Action {
action: string
chatID: number,
chatUUID: string
botName?: string
amount?: number
pubkey?: string
@ -103,6 +38,8 @@ export async function processAction(req, res) {
const bot = await models.Bot.findOne({ where: { id: bot_id } })
if (!bot) return failure(res, 'no bot')
const chat = await models.Chat.findOne({ where:{id:bot.chatId} })
if (!(bot.secret && bot.secret === bot_secret)) {
return failure(res, 'wrong secret')
}
@ -112,20 +49,19 @@ export async function processAction(req, res) {
const a:Action = {
action, pubkey, text, amount,
botName:bot.name, chatID: bot.chatId
botName:bot.name, chatUUID: chat.uuid
}
try {
const r = await finalActionProcess(a)
const r = await finalAction(a)
success(res, r)
} catch(e) {
failure(res, e)
}
}
export async function finalActionProcess(a:Action){
const {action,pubkey,amount,text,botName,chatID} = a
export async function finalAction(a:Action){
const {action,pubkey,amount,text,botName,chatUUID} = a
if (action === 'keysend') {
console.log('=> BOT KEYSEND')
@ -148,9 +84,9 @@ export async function finalActionProcess(a:Action){
} else if (action === 'broadcast') {
console.log('=> BOT BROADCAST')
if (!chatID || !text) throw 'no chatID or text'
if (!chatUUID || !text) throw 'no chatID or text'
const owner = await models.Contact.findOne({ where: { isOwner: true } })
const theChat = await models.Chat.findOne({ where: { id: chatID } })
const theChat = await models.Chat.findOne({ where: { uuid: chatUUID } })
if (!theChat || !owner) throw 'no chat'
if (!theChat.type === constants.chat_types.tribe) throw 'not a tribe'
@ -189,7 +125,7 @@ export async function finalActionProcess(a:Action){
throw e
}
})
} else {
throw 'no action'
}

82
api/controllers/bots.ts

@ -1,48 +1,74 @@
import * as path from 'path'
import {Msg} from '../network/interfaces'
import {Action,finalActionProcess} from './actions'
import * as tribes from '../utils/tribes'
import * as crypto from 'crypto'
import { models } from '../models'
import * as jsonUtils from '../utils/json'
import { success, failure } from '../utils/res'
import {emit as emitBotMsg} from '../bots'
const constants = require(path.join(__dirname, '../../config/constants.json'))
async function broadcastAction(chat,text){
const a:Action = {
action:'broadcast',
text, chatID: chat.id,
botName:'MotherBot'
export const getBots = async (req, res) => {
try {
const bots = await models.Bot.findAll()
success(res, {
bots: bots.map(b=> jsonUtils.botToJson(b))
})
} catch(e) {
failure(res,'no bots')
}
finalActionProcess(a)
}
// return whether this is legit to process
export const createBot = async (req, res) => {
const { name, webhook } = req.body
const uuid = await tribes.genSignedTimestamp()
const newBot = {
name, uuid, webhook,
id: crypto.randomBytes(12).toString('hex').toUpperCase(),
secret: crypto.randomBytes(16).toString('hex').toUpperCase()
}
try {
const theBot = await models.Bot.create(newBot)
// post to bots.sphinx.chat
success(res, jsonUtils.botToJson(theBot))
} catch (e) {
failure(res, 'bot creation failed')
}
}
export const deleteBot = async (req, res) => {
const id = req.params.id
if (!id) return
try {
models.Bot.destroy({ where: { id } })
success(res, true)
} catch (e) {
console.log('ERROR deleteBot', e)
failure(res, e)
}
}
// async function broadcastAction(chat,text){
// finalAction(<Action>{
// action:'broadcast',
// text, chatUUID: chat.uuid,
// botName:'MotherBot'
// })
// }
// return bool whether this is legit to process
export async function processBotMessage(msg:Msg, chat, botInTribe): Promise<boolean> {
const txt = msg.message.content
if(txt.startsWith('/bot ')){
const arr = txt.split(' ')
if(arr.length<2) return false
const cmd = arr[1]
switch(cmd) {
case 'install':
if(arr.length<3) return false
installBot(arr[2], botInTribe)
return true
default:
broadcastAction(chat,botHelpHTML)
}
emitBotMsg(txt, chat.uuid)
} else {
}
return true
}
const botHelpHTML=`<div>
<b>Bot commands:</b>
<ul>
<li><b>/bot install {BOTNAME}:</b>&nbsp;Install a new bot
<li><b>/bot help:</b>&nbsp;Print out this help message
</ul>
<div>
`
/* intercept */
export function installBot(botname,botInTribe) {

7
api/controllers/index.ts

@ -95,10 +95,9 @@ export async function set(app) {
app.get('/info', details.getNodeInfo)
app.post('/action', actions.processAction)
app.get('/bots', actions.getBots)
app.get('/bots/:chat_id',actions.getBotsForTribe)
app.post('/bot', actions.createBot)
app.delete('/bot/:id', actions.deleteBot)
app.get('/bots', bots.getBots)
app.post('/bot', bots.createBot)
app.delete('/bot/:id', bots.deleteBot)
app.get('/version', async function(req,res) {
const version = await checkTag()

3
api/models/ts/bot.ts

@ -13,9 +13,6 @@ export default class Bot extends Model<Bot> {
@Column
uuid: string
@Column(DataType.BIGINT)
chatId: number
@Column
name: string

32
api/network/intercept.ts

@ -2,6 +2,10 @@ import {processBotMessage} from '../controllers/bots'
import {Msg} from './interfaces'
import { models } from '../models'
// const defaultPrefixes = [
// '/bot', '/welcome'
// ]
// return bool whether to skip forwarding to tribe
export async function isBotMsg(msg:Msg, sentByMe:boolean): Promise<boolean> {
const txt = msg.message.content
@ -15,21 +19,23 @@ export async function isBotMsg(msg:Msg, sentByMe:boolean): Promise<boolean> {
return ok?true:false
}
const botInTribe = await models.ChatMember.findOne({where:{
const botsInTribe = await models.ChatMember.findAll({where:{
bot:true, chatId: chat.id
}})
if(!botInTribe) return false
if(!(botInTribe.botMakerPubkey && botInTribe.botUuid)) return false
if(txt.startsWith(`${botInTribe.botPrefix} `)){
const ok = await processBotMessage(msg, chat, botInTribe)
return ok?true:false
}
return false
if(!(botsInTribe && botsInTribe.length)) return false
// check if bot msg
// check my ChatMembers to see if its here
let ok = false
await asyncForEach(botsInTribe, async botInTribe=>{
if(txt.startsWith(`${botInTribe.botPrefix} `)){
ok = await processBotMessage(msg, chat, botInTribe)
}
})
// process it "bot_cmd"
return ok
}
async function asyncForEach(array, callback) {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array);
}
}

1
api/utils/setup.ts

@ -55,7 +55,6 @@ async function migrate(){
CREATE TABLE sphinx_bots (
id TEXT NOT NULL PRIMARY KEY,
name TEXT,
chat_id BIGINT,
secret TEXT,
created_at DATETIME,
updated_at DATETIME

26
dist/api/bots/index.js

@ -0,0 +1,26 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Sphinx = require("../../../sphinx-bot");
const MotherBot = require("./mother");
exports.MotherBot = MotherBot;
function init() {
MotherBot.init();
}
exports.init = init;
function emit(txt, chatUUID) {
const arr = txt.split(' ');
if (arr.length < 2)
return false;
// const cmd = arr[1]
Sphinx.EE.emit('message', { content: txt, chatUUID });
// switch(cmd) {
// case 'install':
// if(arr.length<3) return false
// // installBot(arr[2], botInTribe)
// return true
// default:
// Sphinx.EE.emit('message',cmd,chatUUID)
// }
}
exports.emit = emit;
//# sourceMappingURL=index.js.map

1
dist/api/bots/index.js.map

@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../api/bots/index.ts"],"names":[],"mappings":";;AAAA,8CAA6C;AAC7C,sCAAqC;AAqBnB,8BAAS;AAnB3B,SAAS,IAAI;IACT,SAAS,CAAC,IAAI,EAAE,CAAA;AACpB,CAAC;AAiBO,oBAAI;AAfZ,SAAS,IAAI,CAAC,GAAG,EAAE,QAAQ;IACvB,MAAM,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAC1B,IAAG,GAAG,CAAC,MAAM,GAAC,CAAC;QAAE,OAAO,KAAK,CAAA;IAC7B,qBAAqB;IACrB,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,EAAC,EAAC,OAAO,EAAC,GAAG,EAAC,QAAQ,EAAC,CAAC,CAAA;IAChD,gBAAgB;IAChB,oBAAoB;IACpB,oCAAoC;IACpC,wCAAwC;IACxC,kBAAkB;IAClB,aAAa;IACb,6CAA6C;IAC7C,KAAK;AACT,CAAC;AAEY,oBAAI"}

54
dist/api/bots/mother.js

@ -0,0 +1,54 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const Sphinx = require("../../../sphinx-bot");
const actions_1 = require("../controllers/actions");
const msg_types = Sphinx.MSG_TYPE;
function init() {
const client = new Sphinx.Client();
client.login('_', embedToAction);
client.on(msg_types.MESSAGE, (message) => __awaiter(this, void 0, void 0, function* () {
console.log("INCOMING MSG", message);
const embed = new Sphinx.MessageEmbed()
.setAuthor('MotherBot')
.setTitle('Bot Commands:')
.addFields([
{ name: 'Install a new bot', value: '/bot install {BOTNAME}' },
{ name: 'Help', value: '/bot help' }
]);
message.channel.send({ embed });
}));
}
exports.init = init;
function embedToAction(a) {
let text = '';
let botName = 'Bot';
if (a.embed && a.embed.html) {
text = a.embed.html;
botName = a.embed.author;
}
else if (typeof a === 'string') {
text = a;
}
actions_1.finalAction({
botName,
text, action: 'broadcast',
});
}
// const helpHTML=`<div>
// <b>Bot commands:</b>
// <ul>
// <li><b>/bot install {BOTNAME}:</b>&nbsp;Install a new bot
// <li><b>/bot help:</b>&nbsp;Print out this help message
// </ul>
// <div>
// `
//# sourceMappingURL=mother.js.map

1
dist/api/bots/mother.js.map

@ -0,0 +1 @@
{"version":3,"file":"mother.js","sourceRoot":"","sources":["../../../api/bots/mother.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,8CAA6C;AAC7C,oDAA0D;AAC1D,MAAM,SAAS,GAAG,MAA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,6DAA6D;AAC7D,UAAU;AACV,gBAAgB;AAChB,IAAI"}

1
dist/api/bots/welcome.js

@ -0,0 +1 @@
//# sourceMappingURL=welcome.js.map

1
dist/api/bots/welcome.js.map

@ -0,0 +1 @@
{"version":3,"file":"welcome.js","sourceRoot":"","sources":["../../../api/bots/welcome.ts"],"names":[],"mappings":""}

84
dist/api/controllers/actions.js

@ -9,86 +9,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const res_1 = require("../utils/res");
const path = require("path");
const network = require("../network");
const models_1 = require("../models");
const short = require("short-uuid");
const rsa = require("../crypto/rsa");
const crypto = require("crypto");
const jsonUtils = require("../utils/json");
const tribes = require("../utils/tribes");
const socket = require("../utils/socket");
const res_1 = require("../utils/res");
/*
hexdump -n 8 -e '4/4 "%08X" 1 "\n"' /dev/random
hexdump -n 16 -e '4/4 "%08X" 1 "\n"' /dev/random
*/
const constants = require(path.join(__dirname, '../../config/constants.json'));
exports.getBots = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
try {
const bots = yield models_1.models.Bot.findAll();
res_1.success(res, {
bots: bots.map(b => jsonUtils.botToJson(b))
});
}
catch (e) {
res_1.failure(res, 'no bots');
}
});
exports.getBotsForTribe = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
const chat_id = req.params.chat_id;
const chatId = parseInt(chat_id);
if (!chatId)
return res_1.failure(res, 'no chat id');
try {
const bots = yield models_1.models.Bot.findAll({ where: { chatId } });
res_1.success(res, {
bots: bots.map(b => jsonUtils.botToJson(b))
});
}
catch (e) {
res_1.failure(res, 'no bots');
}
});
exports.createBot = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
const { chat_id, name, } = req.body;
const chatId = parseInt(chat_id);
const chat = yield models_1.models.Chat.findOne({ where: { id: chatId } });
if (!chat)
return res_1.failure(res, 'no chat');
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } });
const isTribeOwner = owner.publicKey === chat.ownerPubkey;
if (!isTribeOwner)
return res_1.failure(res, 'not tribe owner');
const uuid = yield tribes.genSignedTimestamp();
const newBot = {
uuid,
id: crypto.randomBytes(16).toString('hex').toUpperCase(),
chatId: chat_id,
name: name,
secret: crypto.randomBytes(16).toString('hex').toUpperCase()
};
try {
const theBot = yield models_1.models.Bot.create(newBot);
res_1.success(res, jsonUtils.botToJson(theBot));
}
catch (e) {
res_1.failure(res, 'bot creation failed');
}
});
exports.deleteBot = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
const id = req.params.id;
if (!id)
return;
try {
models_1.models.Bot.destroy({ where: { id } });
res_1.success(res, true);
}
catch (e) {
console.log('ERROR deleteBot', e);
res_1.failure(res, e);
}
});
function processAction(req, res) {
return __awaiter(this, void 0, void 0, function* () {
let body = req.body;
@ -107,6 +40,7 @@ function processAction(req, res) {
const bot = yield models_1.models.Bot.findOne({ where: { id: bot_id } });
if (!bot)
return res_1.failure(res, 'no bot');
const chat = yield models_1.models.Chat.findOne({ where: { id: bot.chatId } });
if (!(bot.secret && bot.secret === bot_secret)) {
return res_1.failure(res, 'wrong secret');
}
@ -115,10 +49,10 @@ function processAction(req, res) {
}
const a = {
action, pubkey, text, amount,
botName: bot.name, chatID: bot.chatId
botName: bot.name, chatUUID: chat.uuid
};
try {
const r = yield finalActionProcess(a);
const r = yield finalAction(a);
res_1.success(res, r);
}
catch (e) {
@ -127,9 +61,9 @@ function processAction(req, res) {
});
}
exports.processAction = processAction;
function finalActionProcess(a) {
function finalAction(a) {
return __awaiter(this, void 0, void 0, function* () {
const { action, pubkey, amount, text, botName, chatID } = a;
const { action, pubkey, amount, text, botName, chatUUID } = a;
if (action === 'keysend') {
console.log('=> BOT KEYSEND');
if (!(pubkey && pubkey.length === 66 && amount)) {
@ -152,10 +86,10 @@ function finalActionProcess(a) {
}
else if (action === 'broadcast') {
console.log('=> BOT BROADCAST');
if (!chatID || !text)
if (!chatUUID || !text)
throw 'no chatID or text';
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } });
const theChat = yield models_1.models.Chat.findOne({ where: { id: chatID } });
const theChat = yield models_1.models.Chat.findOne({ where: { uuid: chatUUID } });
if (!theChat || !owner)
throw 'no chat';
if (!theChat.type === constants.chat_types.tribe)
@ -201,5 +135,5 @@ function finalActionProcess(a) {
}
});
}
exports.finalActionProcess = finalActionProcess;
exports.finalAction = finalAction;
//# sourceMappingURL=actions.js.map

2
dist/api/controllers/actions.js.map

File diff suppressed because one or more lines are too long

89
dist/api/controllers/bots.js

@ -10,36 +10,67 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
};
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path");
const actions_1 = require("./actions");
const tribes = require("../utils/tribes");
const crypto = require("crypto");
const models_1 = require("../models");
const jsonUtils = require("../utils/json");
const res_1 = require("../utils/res");
const bots_1 = require("../bots");
const constants = require(path.join(__dirname, '../../config/constants.json'));
function broadcastAction(chat, text) {
return __awaiter(this, void 0, void 0, function* () {
const a = {
action: 'broadcast',
text, chatID: chat.id,
botName: 'MotherBot'
};
actions_1.finalActionProcess(a);
});
}
// return whether this is legit to process
exports.getBots = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
try {
const bots = yield models_1.models.Bot.findAll();
res_1.success(res, {
bots: bots.map(b => jsonUtils.botToJson(b))
});
}
catch (e) {
res_1.failure(res, 'no bots');
}
});
exports.createBot = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
const { name, webhook } = req.body;
const uuid = yield tribes.genSignedTimestamp();
const newBot = {
name, uuid, webhook,
id: crypto.randomBytes(12).toString('hex').toUpperCase(),
secret: crypto.randomBytes(16).toString('hex').toUpperCase()
};
try {
const theBot = yield models_1.models.Bot.create(newBot);
// post to bots.sphinx.chat
res_1.success(res, jsonUtils.botToJson(theBot));
}
catch (e) {
res_1.failure(res, 'bot creation failed');
}
});
exports.deleteBot = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
const id = req.params.id;
if (!id)
return;
try {
models_1.models.Bot.destroy({ where: { id } });
res_1.success(res, true);
}
catch (e) {
console.log('ERROR deleteBot', e);
res_1.failure(res, e);
}
});
// async function broadcastAction(chat,text){
// finalAction(<Action>{
// action:'broadcast',
// text, chatUUID: chat.uuid,
// botName:'MotherBot'
// })
// }
// return bool whether this is legit to process
function processBotMessage(msg, chat, botInTribe) {
return __awaiter(this, void 0, void 0, function* () {
const txt = msg.message.content;
if (txt.startsWith('/bot ')) {
const arr = txt.split(' ');
if (arr.length < 2)
return false;
const cmd = arr[1];
switch (cmd) {
case 'install':
if (arr.length < 3)
return false;
installBot(arr[2], botInTribe);
return true;
default:
broadcastAction(chat, botHelpHTML);
}
bots_1.emit(txt, chat.uuid);
}
else {
}
@ -47,14 +78,6 @@ function processBotMessage(msg, chat, botInTribe) {
});
}
exports.processBotMessage = processBotMessage;
const botHelpHTML = `<div>
<b>Bot commands:</b>
<ul>
<li><b>/bot install {BOTNAME}:</b>&nbsp;Install a new bot
<li><b>/bot help:</b>&nbsp;Print out this help message
</ul>
<div>
`;
/* intercept */
function installBot(botname, botInTribe) {
console.log("INSTALL BOT NOW");

2
dist/api/controllers/bots.js.map

@ -1 +1 @@
{"version":3,"file":"bots.js","sourceRoot":"","sources":["../../../api/controllers/bots.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,6BAA4B;AAE5B,uCAAmD;AAEnD,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,6BAA6B,CAAC,CAAC,CAAA;AAE9E,SAAe,eAAe,CAAC,IAAI,EAAC,IAAI;;QACtC,MAAM,CAAC,GAAU;YACf,MAAM,EAAC,WAAW;YAClB,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;YACrB,OAAO,EAAC,WAAW;SACpB,CAAA;QACD,4BAAkB,CAAC,CAAC,CAAC,CAAA;IACvB,CAAC;CAAA;AAED,0CAA0C;AAC1C,SAAsB,iBAAiB,CAAC,GAAO,EAAE,IAAI,EAAE,UA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D,OAAO,IAAI,CAAA;IACb,CAAC;CAAA;AARD,8CAQC;AAED,eAAe;AAEf,SAAgB,UAAU,CAAC,OAAO,EAAC,UAAU;IAC3C,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAA;IAC9B,oCAAoC;IAEpC,iCAAiC;IACjC,gCAAgC;IAEhC,oCAAoC;IACpC,yCAAyC;AAC3C,CAAC;AATD,gCASC;AAED,SAAsB,iBAAiB,CAAC,OAAO;;QAC7C,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAA;QACnC,yCAAyC;QACzC,4CAA4C;QAC5C,mCAAmC;QAEnC,mDAAmD;QAEnD,0CAA0C;IAC5C,CAAC;CAAA;AATD,8CASC;AAED,oEAAoE;AAEpE,SAAsB,aAAa,CAAC,OAAO;;QACzC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,aAAa,CAAC,OAAO,CAAC,CAAA;IAC9C,CAAC;CAAA;AAFD,sCAEC;AAED,SAAsB,aAAa,CAAC,OAAO;;QACzC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,aAAa,CAAC,OAAO,CAAC,CAAA;IAC9C,CAAC;CAAA;AAFD,sCAEC"}

7
dist/api/controllers/index.js

@ -92,10 +92,9 @@ function set(app) {
app.get('/logs', details.getLogsSince);
app.get('/info', details.getNodeInfo);
app.post('/action', actions.processAction);
app.get('/bots', actions.getBots);
app.get('/bots/:chat_id', actions.getBotsForTribe);
app.post('/bot', actions.createBot);
app.delete('/bot/:id', actions.deleteBot);
app.get('/bots', bots.getBots);
app.post('/bot', bots.createBot);
app.delete('/bot/:id', bots.deleteBot);
app.get('/version', function (req, res) {
return __awaiter(this, void 0, void 0, function* () {
const version = yield gitinfo_1.checkTag();

2
dist/api/controllers/index.js.map

File diff suppressed because one or more lines are too long

4
dist/api/models/ts/bot.js

@ -24,10 +24,6 @@ __decorate([
sequelize_typescript_1.Column,
__metadata("design:type", String)
], Bot.prototype, "uuid", void 0);
__decorate([
sequelize_typescript_1.Column(sequelize_typescript_1.DataType.BIGINT),
__metadata("design:type", Number)
], Bot.prototype, "chatId", void 0);
__decorate([
sequelize_typescript_1.Column,
__metadata("design:type", String)

2
dist/api/models/ts/bot.js.map

@ -1 +1 @@
{"version":3,"file":"bot.js","sourceRoot":"","sources":["../../../../api/models/ts/bot.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,+DAAsE;AAGtE,IAAqB,GAAG,GAAxB,MAAqB,GAAI,SAAQ,4BAAU;CA8B1C,CAAA;AAvBC;IALC,6BAAM,CAAC;QACN,IAAI,EAAE,+BAAQ,CAAC,IAAI;QACnB,UAAU,EAAE,IAAI;QAChB,MAAM,EAAE,IAAI;KACb,CAAC;;+BACQ;AAGV;IADC,6BAAM;;iCACK;AAGZ;IADC,6BAAM,CAAC,+BAAQ,CAAC,MAAM,CAAC;;mCACV;AAGd;IADC,6BAAM;;iCACK;AAGZ;IADC,6BAAM;;mCACO;AAGd;IADC,6BAAM;;oCACQ;AAGf;IADC,6BAAM;8BACI,IAAI;sCAAA;AAGf;IADC,6BAAM;8BACI,IAAI;sCAAA;AA5BI,GAAG;IADvB,4BAAK,CAAC,EAAC,SAAS,EAAE,aAAa,EAAE,WAAW,EAAE,IAAI,EAAC,CAAC;GAChC,GAAG,CA8BvB;kBA9BoB,GAAG"}
{"version":3,"file":"bot.js","sourceRoot":"","sources":["../../../../api/models/ts/bot.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,+DAAsE;AAGtE,IAAqB,GAAG,GAAxB,MAAqB,GAAI,SAAQ,4BAAU;CA2B1C,CAAA;AApBC;IALC,6BAAM,CAAC;QACN,IAAI,EAAE,+BAAQ,CAAC,IAAI;QACnB,UAAU,EAAE,IAAI;QAChB,MAAM,EAAE,IAAI;KACb,CAAC;;+BACQ;AAGV;IADC,6BAAM;;iCACK;AAGZ;IADC,6BAAM;;iCACK;AAGZ;IADC,6BAAM;;mCACO;AAGd;IADC,6BAAM;;oCACQ;AAGf;IADC,6BAAM;8BACI,IAAI;sCAAA;AAGf;IADC,6BAAM;8BACI,IAAI;sCAAA;AAzBI,GAAG;IADvB,4BAAK,CAAC,EAAC,SAAS,EAAE,aAAa,EAAE,WAAW,EAAE,IAAI,EAAC,CAAC;GAChC,GAAG,CA2BvB;kBA3BoB,GAAG"}

31
dist/api/network/intercept.js

@ -11,6 +11,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
Object.defineProperty(exports, "__esModule", { value: true });
const bots_1 = require("../controllers/bots");
const models_1 = require("../models");
// const defaultPrefixes = [
// '/bot', '/welcome'
// ]
// return bool whether to skip forwarding to tribe
function isBotMsg(msg, sentByMe) {
return __awaiter(this, void 0, void 0, function* () {
@ -24,22 +27,26 @@ function isBotMsg(msg, sentByMe) {
const ok = bots_1.processBotMessage(msg, chat, null);
return ok ? true : false;
}
const botInTribe = yield models_1.models.ChatMember.findOne({ where: {
const botsInTribe = yield models_1.models.ChatMember.findAll({ where: {
bot: true, chatId: chat.id
} });
if (!botInTribe)
if (!(botsInTribe && botsInTribe.length))
return false;
if (!(botInTribe.botMakerPubkey && botInTribe.botUuid))
return false;
if (txt.startsWith(`${botInTribe.botPrefix} `)) {
const ok = yield bots_1.processBotMessage(msg, chat, botInTribe);
return ok ? true : false;
}
return false;
// check if bot msg
// check my ChatMembers to see if its here
// process it "bot_cmd"
let ok = false;
yield asyncForEach(botsInTribe, (botInTribe) => __awaiter(this, void 0, void 0, function* () {
if (txt.startsWith(`${botInTribe.botPrefix} `)) {
ok = yield bots_1.processBotMessage(msg, chat, botInTribe);
}
}));
return ok;
});
}
exports.isBotMsg = isBotMsg;
function asyncForEach(array, callback) {
return __awaiter(this, void 0, void 0, function* () {
for (let index = 0; index < array.length; index++) {
yield callback(array[index], index, array);
}
});
}
//# sourceMappingURL=intercept.js.map

2
dist/api/network/intercept.js.map

@ -1 +1 @@
{"version":3,"file":"intercept.js","sourceRoot":"","sources":["../../../api/network/intercept.ts"],"names":[],"mappings":";;;;;;;;;;;AAA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AC,CAAA;QAEF,OAAO,EAAE,CAAA;IACX,CAAC;CAAA;AAzBD,4BAyBC;AAED,SAAe,YAAY,CAAC,KAAK,EAAE,QAAQ;;QAC1C,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;YACjD,MAAM,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;SAC5C;IACF,CAAC;CAAA"}

1
dist/api/utils/setup.js

@ -66,7 +66,6 @@ function migrate() {
CREATE TABLE sphinx_bots (
id TEXT NOT NULL PRIMARY KEY,
name TEXT,
chat_id BIGINT,
secret TEXT,
created_at DATETIME,
updated_at DATETIME

2
dist/api/utils/setup.js.map

@ -1 +1 @@
{"version":3,"file":"setup.js","sourceRoot":"","sources":["../../../api/utils/setup.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,2CAA2C;AAC3C,sCAA2C;AAC3C,iDAAoC;AACpC,iCAAgC;AAChC,sCAAqC;AACrC,gDAAwC;AACxC,8CAA0D;AAE1D,MAAM,YAAY,GAAG,CAAC,CAAA;AAEtB,MAAM,aAAa,GAAG,GAAS,EAAE;IAC/B,OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAA;IACxC,MAAM,UAAU,EAAE,CAAA;IAClB,IAAI;QACF,MAAM,kBAAS,CAAC,IAAI,EAAE,CAAA;QACtB,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAA;KACpC;IAAC,OAAM,CAAC,EAAE;QACT,OAAO,CAAC,GAAG,CAAC,gBAAgB,EAAC,CAAC,CAAC,CAAA;KAChC;IACD,MAAM,OAAO,EAAE,CAAA;IACf,iBAAiB,EAAE,CAAA;IACnB,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAA;AACnC,CAAC,CAAA,CAAA;AAoIQ,sCAAa;AAlItB,SAAe,UAAU;;QACvB,IAAI;YACF,MAAM,kBAAS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