Browse Source

bot install, builtin welcome bot

push-params
Evan Feenstra 4 years ago
parent
commit
d9f70598df
  1. 1
      api/bots/index.ts
  2. 22
      api/bots/mother.ts
  3. 22
      api/network/intercept.ts
  4. 1
      dist/api/bots/index.js
  5. 2
      dist/api/bots/index.js.map
  6. 21
      dist/api/bots/mother.js
  7. 2
      dist/api/bots/mother.js.map
  8. 22
      dist/api/network/intercept.js
  9. 2
      dist/api/network/intercept.js.map
  10. 12
      package-lock.json
  11. 2
      package.json

1
api/bots/index.ts

@ -13,6 +13,7 @@ function builtinBotEmit(msg:Msg){
id: msg.chat.uuid,
send:function(){},
},
reply:function(){},
content: msg.message.content,
type: msg.type,
})

22
api/bots/mother.ts

@ -1,8 +1,16 @@
// import * as SphinxBot from '../../../sphinx-bot'
import * as Sphinx from 'sphinx-bot'
import { finalAction } from '../controllers/actions'
import * as path from 'path'
import { models } from '../models'
const msg_types = Sphinx.MSG_TYPE
const constants = require(path.join(__dirname, '../../config/constants.json'))
const builtinBots = [
'welcome',
]
export function init() {
const client = new Sphinx.Client()
@ -17,8 +25,18 @@ export function init() {
case 'install':
if (arr.length < 3) return
console.log("INSTALL", arr[2])
// installBot(arr[2], botInTribe)
const botName = arr[2]
if(builtinBots.includes(botName)) {
console.log("INSTALL", botName)
const chatBot = {
chatID: message.channel.id,
botPrefix: '/'+botName,
botType:constants.bot_types.builtin
}
await models.ChatBot.create(chatBot)
} else {
message.reply('No built-in bot by that name')
}
return true
default:

22
api/network/intercept.ts

@ -2,9 +2,14 @@ import {Msg} from './interfaces'
import { models } from '../models'
import {builtinBotEmit} from '../bots'
// const defaultPrefixes = [
// '/bot', '/welcome'
// ]
const defaultPrefixes = [
'/bot' //, '/welcome'
]
/*
default show or not
restrictions (be able to toggle, or dont show chat)
*/
// return bool whether to skip forwarding to tribe
export async function isBotMsg(msg:Msg, sentByMe:boolean): Promise<boolean> {
@ -16,10 +21,13 @@ export async function isBotMsg(msg:Msg, sentByMe:boolean): Promise<boolean> {
let didEmit = false
if(txt.startsWith('/bot ')) {
builtinBotEmit(msg)
didEmit = true
}
defaultPrefixes.forEach(p=>{
if(txt.startsWith(`${p} `)) {
builtinBotEmit(msg)
didEmit = true
}
})
if(didEmit) return didEmit
const botsInTribe = await models.ChatBot.findAll({where:{
chatId: chat.id

1
dist/api/bots/index.js

@ -13,6 +13,7 @@ function builtinBotEmit(msg) {
id: msg.chat.uuid,
send: function () { },
},
reply: function () { },
content: msg.message.content,
type: msg.type,
});

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;AAGrC,SAAS,IAAI;IACT,SAAS,CAAC,IAAI,EAAE,CAAA;AACpB,CAAC;AAaO,oBAAI;AAXZ,SAAS,cAAc,CAAC,GAAO;IAC3B,SAAS,CAAC,KAAK,CAAC,SAAS,EAAqB;QAC1C,OAAO,EAAC;YACJ,EAAE,EAAE,GAAG,CAAC,IAAI,CAAC,IAAI;YACjB,IAAI,EAAC,cAAW,CAAC;SACpB;QACD,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,OAAO;QAC5B,IAAI,EAAE,GAAG,CAAC,IAAI;KACjB,CAAC,CAAA;AACN,CAAC;AAEY,wCAAc"}
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../api/bots/index.ts"],"names":[],"mappings":";;AAAA,mDAAmD;AACnD,wCAAuC;AACvC,sCAAqC;AAGrC,SAAS,IAAI;IACT,SAAS,CAAC,IAAI,EAAE,CAAA;AACpB,CAAC;AAcO,oBAAI;AAZZ,SAAS,cAAc,CAAC,GAAO;IAC3B,SAAS,CAAC,KAAK,CAAC,SAAS,EAAqB;QAC1C,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;KACjB,CAAC,CAAA;AACN,CAAC;AAEY,wCAAc"}

21
dist/api/bots/mother.js

@ -12,7 +12,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
// import * as SphinxBot from '../../../sphinx-bot'
const Sphinx = require("sphinx-bot");
const actions_1 = require("../controllers/actions");
const path = require("path");
const models_1 = require("../models");
const msg_types = Sphinx.MSG_TYPE;
const constants = require(path.join(__dirname, '../../config/constants.json'));
const builtinBots = [
'welcome',
];
function init() {
const client = new Sphinx.Client();
client.login('_', actions_1.finalAction);
@ -27,8 +33,19 @@ function init() {
case 'install':
if (arr.length < 3)
return;
console.log("INSTALL", arr[2]);
// installBot(arr[2], botInTribe)
const botName = arr[2];
if (builtinBots.includes(botName)) {
console.log("INSTALL", botName);
const chatBot = {
chatID: message.channel.id,
botPrefix: '/' + botName,
botType: constants.bot_types.builtin
};
yield models_1.models.ChatBot.create(chatBot);
}
else {
message.reply('No built-in bot by that name');
}
return true;
default:
const embed = new Sphinx.MessageEmbed()

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

@ -1 +1 @@
{"version":3,"file":"mother.js","sourceRoot":"","sources":["../../../api/bots/mother.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,oDAAoD;AACpD,qCAAoC;AACpC,oDAAoD;AACpD,MAAM,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAA;AAEjC,SAAgB,IAAI;IAElB,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,MAAM,EAAE,CAAA;IAClC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,qBAAW,CAAC,CAAA;IAE9B,MAAM,CAAC,EAAE,CAAC,SAAS,CAAC,OAAO,EAAE,CAAO,OAAuB,EAAE,EAAE;QAC7D,MAAM,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QACtC,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC;Y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AAE,wBAAwB,EAAE;oBAC9D,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE;iBACrC,CAAC;qBACD,YAAY,CAAC,MAAM,CAAC,CAAA;gBACvB,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,CAAC,CAAA;SAClC;IACH,CAAC,CAAA,CAAC,CAAA;AACJ,CAAC;AAxCD,oBAwCC;AAED,MAAM,MAAM,GAAG;;OAER,CAAA"}

22
dist/api/network/intercept.js

@ -11,9 +11,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
Object.defineProperty(exports, "__esModule", { value: true });
const models_1 = require("../models");
const bots_1 = require("../bots");
// const defaultPrefixes = [
// '/bot', '/welcome'
// ]
const defaultPrefixes = [
'/bot' //, '/welcome'
];
/*
default show or not
restrictions (be able to toggle, or dont show chat)
*/
// return bool whether to skip forwarding to tribe
function isBotMsg(msg, sentByMe) {
return __awaiter(this, void 0, void 0, function* () {
@ -24,10 +28,14 @@ function isBotMsg(msg, sentByMe) {
if (!chat)
return false;
let didEmit = false;
if (txt.startsWith('/bot ')) {
bots_1.builtinBotEmit(msg);
didEmit = true;
}
defaultPrefixes.forEach(p => {
if (txt.startsWith(`${p} `)) {
bots_1.builtinBotEmit(msg);
didEmit = true;
}
});
if (didEmit)
return didEmit;
const botsInTribe = yield models_1.models.ChatBot.findAll({ where: {
chatId: chat.id
} });

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

@ -1 +1 @@
{"version":3,"file":"intercept.js","sourceRoot":"","sources":["../../../api/network/intercept.ts"],"names":[],"mappings":";;;;;;;;;;;AACA,sCAAkC;AAClC,kCAAsC;AAEtC,4BAA4B;AAC5B,uBAAuB;AACvB,IAAI;AAEJ,kDAAkD;AAClD,SAAsB,QAAQ,CAAC,GAAO,EAAE,QAAgB;;QACtD,MAAM,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,OAAO,CAAA;QAC/B,MAAM,IAAI,GAAG,MAAM,eAA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AY,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"}

12
package-lock.json

@ -11203,9 +11203,9 @@
}
},
"sphinx-bot": {
"version": "0.1.21",
"resolved": "https://registry.npmjs.org/sphinx-bot/-/sphinx-bot-0.1.21.tgz",
"integrity": "sha512-t1+dKWOeKNEDiqJJ7HeobXh7Mpj/OjkbosuGAGbGv8yCWt5ghBkcl25qINuEDGekKhFJZhTM+DCPBAMPQFkxeg==",
"version": "0.1.22",
"resolved": "https://registry.npmjs.org/sphinx-bot/-/sphinx-bot-0.1.22.tgz",
"integrity": "sha512-Wtbtb11WrCVSPL+9qoSmnoXnloKryO9NEUzV9kFZ3XEhigWWh/3GSRlDAKB3z5SC51cUbCNCION1RcGJXAJMvw==",
"requires": {
"eventemitter3": "^4.0.7",
"isomorphic-dompurify": "^0.6.0"
@ -12965,9 +12965,9 @@
"integrity": "sha512-M4yMwr6mAnQz76TbJm914+gPpB/nCwvZbJU28cUD6dR004SAxDLOOSUaB1JDRqLtaOV/vi0IC5lEAGFgrjGv/g=="
},
"whatwg-url": {
"version": "8.2.1",
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-8.2.1.tgz",
"integrity": "sha512-ZmVCr6nfBeaMxEHALLEGy0LszYjpJqf6PVNQUQ1qd9Et+q7Jpygd4rGGDXgHjD8e99yLFseD69msHDM4YwPZ4A==",
"version": "8.2.2",
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-8.2.2.tgz",
"integrity": "sha512-PcVnO6NiewhkmzV0qn7A+UZ9Xx4maNTI+O+TShmfE4pqjoCMwUMjkvoNhNHPTvgR7QH9Xt3R13iHuWy2sToFxQ==",
"requires": {
"lodash.sortby": "^4.7.0",
"tr46": "^2.0.2",

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.21",
"sphinx-bot": "^0.1.22",
"tail": "^2.0.3",
"ts-node": "^8.5.4",
"tsc": "^1.20150623.0",

Loading…
Cancel
Save