Browse Source

roles in lumo msgs and bot processing, fix infinite loop

push-params
Evan Feenstra 4 years ago
parent
commit
2a425b0a7e
  1. 15
      api/bots/index.ts
  2. 3
      api/network/interfaces.ts
  3. 3
      api/network/receive.ts
  4. 13
      api/network/send.ts
  5. 16
      dist/api/bots/index.js
  6. 2
      dist/api/bots/index.js.map
  7. 2
      dist/api/network/receive.js
  8. 2
      dist/api/network/receive.js.map
  9. 13
      dist/api/network/send.js
  10. 2
      dist/api/network/send.js.map
  11. 6
      package-lock.json
  12. 2
      package.json

15
api/bots/index.ts

@ -22,7 +22,7 @@ async function init(){
}
function builtinBotEmit(msg:Msg){
SphinxBot._emit('message', <SphinxBot.Message>{
const m = <SphinxBot.Message>{
channel:{
id: msg.chat.uuid,
send:function(){},
@ -30,7 +30,18 @@ function builtinBotEmit(msg:Msg){
reply:function(){},
content: msg.message.content,
type: msg.type,
})
member: {
id:'_',
nickname: msg.sender.alias,
roles:[]
}
}
if(msg.sender.role===constants.chat_role.owner) {
if(m.member) m.member.roles=[{
name:'Admin'
}]
}
SphinxBot._emit('message', m)
}
export {init,builtinBotEmit}

3
api/network/interfaces.ts

@ -2,7 +2,7 @@
export interface Msg {
type: number,
message: {
content: string
content: string,
},
chat: {
uuid: string
@ -10,5 +10,6 @@ export interface Msg {
sender: {
pub_key: string,
alias: string,
role: number
}
}

3
api/network/receive.ts

@ -170,7 +170,8 @@ async function forwardMessageToTribe(ogpayload, sender){
type, message,
sender: {
...owner.dataValues,
...payload.sender&&payload.sender.alias && {alias:payload.sender.alias}
...payload.sender&&payload.sender.alias && {alias:payload.sender.alias},
role: constants.chat_roles.reader,
},
chat: chat,
skipPubKey: payload.sender.pub_key,

13
api/network/send.ts

@ -6,7 +6,7 @@ import * as path from 'path'
import * as tribes from '../utils/tribes'
import {tribeOwnerAutoConfirmation} from '../controllers/confirmations'
import {typesToForward} from './receive'
// import * as intercept from './intercept'
import * as intercept from './intercept'
const constants = require(path.join(__dirname,'../../config/constants.json'))
@ -49,11 +49,11 @@ export async function sendMessage(params) {
networkType = 'mqtt' // broadcast to all
// decrypt message.content and message.mediaKey w groupKey
msg = await decryptMessage(msg, chat)
// console.log("SEND.TS isBotMsg")
// const isBotMsg = await intercept.isBotMsg(msg, true)
// if(isBotMsg===true) {
// // return // DO NOT FORWARD TO TRIBE, forwarded to bot instead
// }
console.log("SEND.TS isBotMsg")
const isBotMsg = await intercept.isBotMsg(msg, true)
if(isBotMsg===true) {
// return // DO NOT FORWARD TO TRIBE, forwarded to bot instead
}
// post last_active to tribes server
tribes.putActivity(chat.uuid, chat.host)
} else {
@ -170,6 +170,7 @@ export function newmsg(type, chat, sender, message){
sender: {
pub_key: sender.publicKey,
alias: includeAlias ? sender.alias : '',
role: sender.role || constants.chat_roles.reader,
// ...includePhotoUrl && {photo_url: sender.photoUrl},
// ...sender.contactKey && {contact_key: sender.contactKey}
}

16
dist/api/bots/index.js

@ -32,7 +32,7 @@ function init() {
}
exports.init = init;
function builtinBotEmit(msg) {
SphinxBot._emit('message', {
const m = {
channel: {
id: msg.chat.uuid,
send: function () { },
@ -40,7 +40,19 @@ function builtinBotEmit(msg) {
reply: function () { },
content: msg.message.content,
type: msg.type,
});
member: {
id: '_',
nickname: msg.sender.alias,
roles: []
}
};
if (msg.sender.role === constants.chat_role.owner) {
if (m.member)
m.member.roles = [{
name: 'Admin'
}];
}
SphinxBot._emit('message', m);
}
exports.builtinBotEmit = builtinBotEmit;
//# sourceMappingURL=index.js.map

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

@ -1 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../api/bots/index.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,mDAAmD;AACnD,wCAAuC;AACvC,sCAAqC;AACrC,wCAAuC;AAEvC,6BAA4B;AAC5B,sCAAkC;AAElC,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,6BAA6B,CAAC,CAAC,CAAA;AAE9E,SAAe,IAAI;;QACf,SAAS,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,EAAC,CAAC,CAAA;QACH,IAAG,CAAC,CAAC,WAAW,IAAI,WAAW,CAAC,MAAM,CAAC;YAAE,OAAM;QAE/C,WAAW,CAAC,OAAO,CAAC,CAAC,CAAA,EAAE;YACnB,IAAG,CAAC,CAAC,SAAS,KAAG,UAAU;gBAAE,UAAU,CAAC,IAAI,EAAE,CAAA;QAClD,CAAC,CAAC,CAAA;IACN,CAAC;CAAA;AAyBO,oBAAI;AAvBZ,SAAS,cAAc,CAAC,GAAO;IAC3B,MAAM,CAAC,GAAsB;QACzB,OAAO,EAAC;YACJ,EAAE,EAAE,GAAG,CAAC,IAAI,CAAC,IAAI;YACjB,IAAI,EAAC,cAAW,CAAC;SACpB;QACD,KAAK,EAAC,cAAW,CAAC;QAClB,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,OAAO;QAC5B,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,MAAM,EAAE;YACJ,EAAE,EAAC,GAAG;YACN,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,KAAK;YAC1B,KAAK,EAAC,EAAE;SACX;KACJ,CAAA;IACD,IAAG,GAAG,CAAC,MAAM,CAAC,IAAI,KAAG,SAAS,CAAC,SAAS,CAAC,KAAK,EAAE;QAC5C,IAAG,CAAC,CAAC,MAAM;YAAE,CAAC,CAAC,MAAM,CAAC,KAAK,GAAC,CAAC;oBACzB,IAAI,EAAC,OAAO;iBACf,CAAC,CAAA;KACL;IACD,SAAS,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC,CAAA;AACjC,CAAC;AAEY,wCAAc"}

2
dist/api/network/receive.js

@ -189,7 +189,7 @@ function forwardMessageToTribe(ogpayload, sender) {
// ASK xref TABLE and put alias there too?
send_1.sendMessage({
type, message,
sender: Object.assign(Object.assign({}, owner.dataValues), payload.sender && payload.sender.alias && { alias: payload.sender.alias }),
sender: Object.assign(Object.assign(Object.assign({}, owner.dataValues), payload.sender && payload.sender.alias && { alias: payload.sender.alias }), { role: constants.chat_roles.reader }),
chat: chat,
skipPubKey: payload.sender.pub_key,
success: () => { },

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

File diff suppressed because one or more lines are too long

13
dist/api/network/send.js

@ -17,7 +17,7 @@ const path = require("path");
const tribes = require("../utils/tribes");
const confirmations_1 = require("../controllers/confirmations");
const receive_1 = require("./receive");
// import * as intercept from './intercept'
const intercept = require("./intercept");
const constants = require(path.join(__dirname, '../../config/constants.json'));
const MIN_SATS = 3;
function sendMessage(params) {
@ -54,11 +54,11 @@ function sendMessage(params) {
networkType = 'mqtt'; // broadcast to all
// decrypt message.content and message.mediaKey w groupKey
msg = yield msg_1.decryptMessage(msg, chat);
// console.log("SEND.TS isBotMsg")
// const isBotMsg = await intercept.isBotMsg(msg, true)
// if(isBotMsg===true) {
// // return // DO NOT FORWARD TO TRIBE, forwarded to bot instead
// }
console.log("SEND.TS isBotMsg");
const isBotMsg = yield intercept.isBotMsg(msg, true);
if (isBotMsg === true) {
// return // DO NOT FORWARD TO TRIBE, forwarded to bot instead
}
// post last_active to tribes server
tribes.putActivity(chat.uuid, chat.host);
}
@ -171,6 +171,7 @@ function newmsg(type, chat, sender, message) {
sender: {
pub_key: sender.publicKey,
alias: includeAlias ? sender.alias : '',
role: sender.role || constants.chat_roles.reader,
}
};
}

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

File diff suppressed because one or more lines are too long

6
package-lock.json

@ -11203,9 +11203,9 @@
}
},
"sphinx-bot": {
"version": "0.1.25",
"resolved": "https://registry.npmjs.org/sphinx-bot/-/sphinx-bot-0.1.25.tgz",
"integrity": "sha512-8c0ZRkpvEEHK06feSNyjjB5udSw0n3QsSfv7W53L+OSccgGcYC4ewIql/dwo3FkyhVhCFdqWvqbhSW5J7OKYAQ==",
"version": "0.1.26",
"resolved": "https://registry.npmjs.org/sphinx-bot/-/sphinx-bot-0.1.26.tgz",
"integrity": "sha512-Tb9uOLcvQhYugNOjFL1wwgdtU1sBVHuXE0hJEXAkyymQolksdHufkgdfQAbJEJnHbV1GiF1WKvkgEnB6LPT7fQ==",
"requires": {
"eventemitter3": "^4.0.7",
"isomorphic-dompurify": "^0.6.0"

2
package.json

@ -78,7 +78,7 @@
"short-uuid": "^3.1.1",
"sjcl": "^1.0.8",
"socket.io": "^2.3.0",
"sphinx-bot": "^0.1.25",
"sphinx-bot": "^0.1.26",
"tail": "^2.0.3",
"ts-node": "^8.5.4",
"tsc": "^1.20150623.0",

Loading…
Cancel
Save