Browse Source

more handling

dependabot/npm_and_yarn/ini-1.3.7
Evan Feenstra 4 years ago
parent
commit
4a69ceb11e
  1. 83
      dist/src/builtin/loop.js
  2. 2
      dist/src/builtin/loop.js.map
  3. 8
      dist/src/network/intercept.js
  4. 2
      dist/src/network/intercept.js.map
  5. 86
      src/builtin/loop.ts
  6. 8
      src/network/intercept.ts

83
dist/src/builtin/loop.js

@ -134,7 +134,7 @@ function init() {
console.log("LOOPBOT stdout:", stdout); console.log("LOOPBOT stdout:", stdout);
if (stdout) { if (stdout) {
console.log('=> LOOPBOT stdout', stdout); console.log('=> LOOPBOT stdout', stdout);
if (stdout.startsWith('CONTINUE SWAP?')) { if (stdout.includes('CONTINUE SWAP?')) {
childProcess.stdin.write('y\n'); childProcess.stdin.write('y\n');
} }
if (stdout.startsWith('Swap initiated')) { if (stdout.startsWith('Swap initiated')) {
@ -147,51 +147,58 @@ function init() {
} }
} }
}); });
childProcess.stderr.on('data', function (data) {
console.log("STDERR:", data.toString());
});
childProcess.on('error', (error) => { childProcess.on('error', (error) => {
console.log(error.toString()); console.log("error", error.toString());
});
childProcess.on('close', (code) => {
console.log("CHILD PROCESS closed", code);
}); });
} }
catch (e) { catch (e) {
console.log('LoopBot error', e); console.log('LoopBot error', e);
} }
return; // return here
} }
const cmd = arr[1]; else {
const isAdmin = message.member.roles.find(role => role.name === 'Admin'); const cmd = arr[1];
if (isAdmin && cmd.startsWith('setchan=')) { const isAdmin = message.member.roles.find(role => role.name === 'Admin');
const bot = yield getBot(message.channel.id); if (isAdmin && cmd.startsWith('setchan=')) {
const arr = cmd.split('='); const bot = yield getBot(message.channel.id);
if (bot && arr.length > 1) { const arr = cmd.split('=');
const chan = arr[1]; if (bot && arr.length > 1) {
yield bot.update({ meta: chan }); const chan = arr[1];
const embed = new Sphinx.MessageEmbed() yield bot.update({ meta: chan });
.setAuthor('LoopBot') const embed = new Sphinx.MessageEmbed()
.setDescription('Channel updated to ' + chan) .setAuthor('LoopBot')
.setThumbnail(botSVG); .setDescription('Channel updated to ' + chan)
message.channel.send({ embed }); .setThumbnail(botSVG);
return; message.channel.send({ embed });
return;
}
} }
} switch (cmd) {
switch (cmd) { case 'help':
case 'help': const embed = new Sphinx.MessageEmbed()
const embed = new Sphinx.MessageEmbed() .setAuthor('LoopBot')
.setAuthor('LoopBot') .setTitle('LoopBot Commands:')
.setTitle('LoopBot Commands:') .addFields([
.addFields([ { name: 'Send to your on-chain address', value: '/loopout {ADDRESS} {AMOUNT}' },
{ name: 'Send to your on-chain address', value: '/loopout {ADDRESS} {AMOUNT}' }, { name: 'Set Channel', value: '/loopout setchan=***' },
{ name: 'Set Channel', value: '/loopout setchan=***' }, { name: 'Help', value: '/loopout help' },
{ name: 'Help', value: '/loopout help' }, ])
]) .setThumbnail(botSVG);
.setThumbnail(botSVG); message.channel.send({ embed });
message.channel.send({ embed }); return;
return; default:
default: const embed2 = new Sphinx.MessageEmbed()
const embed2 = new Sphinx.MessageEmbed() .setAuthor('LoopBot')
.setAuthor('LoopBot') .setDescription('Command not recognized');
.setDescription('Command not recognized'); message.channel.send({ embed: embed2 });
message.channel.send({ embed: embed2 }); return;
return; }
} } // end else
})); }));
} }
exports.init = init; exports.init = init;

2
dist/src/builtin/loop.js.map

File diff suppressed because one or more lines are too long

8
dist/src/network/intercept.js

@ -21,31 +21,26 @@ restrictions (be able to toggle, or dont show chat)
// return bool whether to skip forwarding to tribe // return bool whether to skip forwarding to tribe
function isBotMsg(msg, sentByMe) { function isBotMsg(msg, sentByMe) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
console.log('=> is bot msg');
const txt = msg.message && msg.message.content; const txt = msg.message && msg.message.content;
const msgType = msg.type; const msgType = msg.type;
if (msgType === constants_1.default.message_types.bot_res) { if (msgType === constants_1.default.message_types.bot_res) {
return false; // bot res msg type not for processing return false; // bot res msg type not for processing
} }
console.log('=> is bot msg 2');
const uuid = msg.chat && msg.chat.uuid; const uuid = msg.chat && msg.chat.uuid;
if (!uuid) if (!uuid)
return false; return false;
console.log('=> is bot msg 3');
const chat = yield models_1.models.Chat.findOne({ const chat = yield models_1.models.Chat.findOne({
where: { uuid } where: { uuid }
}); });
if (!chat) if (!chat)
return false; return false;
let didEmit = false; let didEmit = false;
console.log('=> is bot msg 4');
if (txt && txt.startsWith('/bot ')) { if (txt && txt.startsWith('/bot ')) {
builtin_1.builtinBotEmit(msg); builtin_1.builtinBotEmit(msg);
didEmit = true; didEmit = true;
} }
if (didEmit) if (didEmit)
return didEmit; return didEmit;
console.log('=> is bot msg 5');
const botsInTribe = yield models_1.models.ChatBot.findAll({ const botsInTribe = yield models_1.models.ChatBot.findAll({
where: { where: {
chatId: chat.id chatId: chat.id
@ -54,7 +49,6 @@ function isBotMsg(msg, sentByMe) {
// console.log('=> botsInTribe', botsInTribe) // console.log('=> botsInTribe', botsInTribe)
if (!(botsInTribe && botsInTribe.length)) if (!(botsInTribe && botsInTribe.length))
return false; return false;
console.log('=> is bot msg 6');
yield asyncForEach(botsInTribe, (botInTribe) => __awaiter(this, void 0, void 0, function* () { yield asyncForEach(botsInTribe, (botInTribe) => __awaiter(this, void 0, void 0, function* () {
if (botInTribe.msgTypes) { if (botInTribe.msgTypes) {
// console.log('=> botInTribe.msgTypes', botInTribe) // console.log('=> botInTribe.msgTypes', botInTribe)
@ -64,7 +58,6 @@ function isBotMsg(msg, sentByMe) {
const isMsgAndHasText = msgType === constants_1.default.message_types.message && txt && txt.startsWith(`${botInTribe.botPrefix} `); const isMsgAndHasText = msgType === constants_1.default.message_types.message && txt && txt.startsWith(`${botInTribe.botPrefix} `);
const isNotMsg = msgType !== constants_1.default.message_types.message; const isNotMsg = msgType !== constants_1.default.message_types.message;
if (isMsgAndHasText || isNotMsg) { if (isMsgAndHasText || isNotMsg) {
console.log('=> is bot msg emitMessageToBot', msg, botInTribe.dataValues);
didEmit = yield emitMessageToBot(msg, botInTribe.dataValues); didEmit = yield emitMessageToBot(msg, botInTribe.dataValues);
} }
} }
@ -73,7 +66,6 @@ function isBotMsg(msg, sentByMe) {
} }
else { // no message types defined, do all? else { // no message types defined, do all?
if (txt && txt.startsWith(`${botInTribe.botPrefix} `)) { if (txt && txt.startsWith(`${botInTribe.botPrefix} `)) {
console.log('=> is bot msg emitMessageToBot2', msg, botInTribe.dataValues);
// console.log('=> botInTribe.msgTypes else', botInTribe.dataValues) // console.log('=> botInTribe.msgTypes else', botInTribe.dataValues)
didEmit = yield emitMessageToBot(msg, botInTribe.dataValues); didEmit = yield emitMessageToBot(msg, botInTribe.dataValues);
} }

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

@ -1 +1 @@
{"version":3,"file":"intercept.js","sourceRoot":"","sources":["../../../src/network/intercept.ts"],"names":[],"mappings":";;;;;;;;;;;AACA,sCAAkC;AAClC,wCAA2C;AAC3C,8CAAoE;AACpE,wCAAuC;AACvC,4CAAoC;AAEpC;;;EAGE;AAEF,kDAAkD;AAClD,SAAsB,QAAQ,CAAC,GAAQ,EAAE,QAAiB;;QACxD,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAA;QAC5B,MAAM,GAAG,GAAG,GAAG,CAAC,OAAO,IAAI,GAAG,CAAC,OAAO,CAAC,OAAO,CAAA;QAE9C,MAAM,OAAO,GAAG,GAAG,CAAC,IAAI,CAAA;QACxB,IAAI,OAAO,KAAK,mBAAS,CAAC,aAAa,CAAC,OAAO,EAAE;YAC/C,OAAO,KAAK,CAAA,CAAC,sCAAsC;SACpD;QACD,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAA;QAC9B,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,IAAI,CAAC,IAAI,CAAA;QACtC,IAAG,CAAC,IAAI;YAAE,OAAO,KAAK,CAAA;QAEtB,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAA;QAC9B,MAAM,IAAI,GAAG,MAAM,eAAM,CAAC,IAAI,CAAC,OAAO,CAAC;YACrC,KAAK,EAAE,EAAC,IAAI,EAAC;S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CAAC;CAAA;AAtDD,4BAsDC;AAED,SAAe,gBAAgB,CAAC,GAAG,EAAE,UAAU;;QAC7C,gEAAgE;QAChE,QAAQ,UAAU,CAAC,OAAO,EAAE;YAC1B,KAAK,mBAAS,CAAC,SAAS,CAAC,OAAO;gBAC9B,wBAAc,CAAC,GAAG,CAAC,CAAA;gBACnB,OAAO,IAAI,CAAA;YACb,KAAK,mBAAS,CAAC,SAAS,CAAC,KAAK;gBAC5B,MAAM,GAAG,GAAG,MAAM,eAAM,CAAC,GAAG,CAAC,OAAO,CAAC;oBACnC,KAAK,EAAE;wBACL,IAAI,EAAE,UAAU,CAAC,OAAO;qBACzB;iBACF,CAAC,CAAA;gBACF,OAAO,sBAAe,CAAC,GAAG,EAAE,GAAG,EAAE,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAA;YAC9D,KAAK,mBAAS,CAAC,SAAS,CAAC,MAAM;gBAC7B,OAAO,oBAAa,CAAC,GAAG,EAAE,UAAU,CAAC,CAAA;YACvC;gBACE,OAAO,KAAK,CAAA;SACf;IACH,CAAC;CAAA;AAED,SAAe,YAAY,CAAC,KAAK,EAAE,QAAQ;;QACzC,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;IACH,CAAC;CAAA"}

86
src/builtin/loop.ts

@ -130,7 +130,7 @@ export function init() {
console.log("LOOPBOT stdout:",stdout) console.log("LOOPBOT stdout:",stdout)
if(stdout){ if(stdout){
console.log('=> LOOPBOT stdout',stdout) console.log('=> LOOPBOT stdout',stdout)
if(stdout.startsWith('CONTINUE SWAP?')) { if(stdout.includes('CONTINUE SWAP?')) {
childProcess.stdin.write('y\n') childProcess.stdin.write('y\n')
} }
if(stdout.startsWith('Swap initiated')) { if(stdout.startsWith('Swap initiated')) {
@ -143,53 +143,61 @@ export function init() {
} }
} }
}) })
childProcess.stderr.on('data', function (data) {
console.log("STDERR:",data.toString())
});
childProcess.on('error', (error) => { childProcess.on('error', (error) => {
console.log(error.toString()); console.log("error",error.toString());
});
childProcess.on('close', (code) => {
console.log("CHILD PROCESS closed",code)
}); });
} catch (e) { } catch (e) {
console.log('LoopBot error', e) console.log('LoopBot error', e)
} }
return // return here } else {
}
const cmd = arr[1] const cmd = arr[1]
const isAdmin = message.member.roles.find(role => role.name === 'Admin') const isAdmin = message.member.roles.find(role => role.name === 'Admin')
if (isAdmin && cmd.startsWith('setchan=')) { if (isAdmin && cmd.startsWith('setchan=')) {
const bot = await getBot(message.channel.id) const bot = await getBot(message.channel.id)
const arr = cmd.split('=') const arr = cmd.split('=')
if (bot && arr.length > 1) { if (bot && arr.length > 1) {
const chan = arr[1] const chan = arr[1]
await bot.update({ meta: chan }) await bot.update({ meta: chan })
const embed = new Sphinx.MessageEmbed() const embed = new Sphinx.MessageEmbed()
.setAuthor('LoopBot') .setAuthor('LoopBot')
.setDescription('Channel updated to ' + chan) .setDescription('Channel updated to ' + chan)
.setThumbnail(botSVG) .setThumbnail(botSVG)
message.channel.send({ embed }) message.channel.send({ embed })
return return
}
} }
} switch (cmd) {
switch (cmd) { case 'help':
case 'help': const embed = new Sphinx.MessageEmbed()
const embed = new Sphinx.MessageEmbed() .setAuthor('LoopBot')
.setAuthor('LoopBot') .setTitle('LoopBot Commands:')
.setTitle('LoopBot Commands:') .addFields([
.addFields([ { name: 'Send to your on-chain address', value: '/loopout {ADDRESS} {AMOUNT}' },
{ name: 'Send to your on-chain address', value: '/loopout {ADDRESS} {AMOUNT}' }, { name: 'Set Channel', value: '/loopout setchan=***' },
{ name: 'Set Channel', value: '/loopout setchan=***' }, { name: 'Help', value: '/loopout help' },
{ name: 'Help', value: '/loopout help' }, ])
]) .setThumbnail(botSVG)
.setThumbnail(botSVG) message.channel.send({ embed })
message.channel.send({ embed }) return
return default:
default: const embed2 = new Sphinx.MessageEmbed()
const embed2 = new Sphinx.MessageEmbed() .setAuthor('LoopBot')
.setAuthor('LoopBot') .setDescription('Command not recognized')
.setDescription('Command not recognized') message.channel.send({ embed: embed2 })
message.channel.send({ embed: embed2 }) return
return }
}
} // end else
}) })
} }

8
src/network/intercept.ts

@ -12,18 +12,15 @@ restrictions (be able to toggle, or dont show chat)
// return bool whether to skip forwarding to tribe // return bool whether to skip forwarding to tribe
export async function isBotMsg(msg: Msg, sentByMe: boolean): Promise<boolean> { export async function isBotMsg(msg: Msg, sentByMe: boolean): Promise<boolean> {
console.log('=> is bot msg')
const txt = msg.message && msg.message.content const txt = msg.message && msg.message.content
const msgType = msg.type const msgType = msg.type
if (msgType === constants.message_types.bot_res) { if (msgType === constants.message_types.bot_res) {
return false // bot res msg type not for processing return false // bot res msg type not for processing
} }
console.log('=> is bot msg 2')
const uuid = msg.chat && msg.chat.uuid const uuid = msg.chat && msg.chat.uuid
if(!uuid) return false if(!uuid) return false
console.log('=> is bot msg 3')
const chat = await models.Chat.findOne({ const chat = await models.Chat.findOne({
where: {uuid} where: {uuid}
}) })
@ -31,14 +28,12 @@ export async function isBotMsg(msg: Msg, sentByMe: boolean): Promise<boolean> {
let didEmit = false let didEmit = false
console.log('=> is bot msg 4')
if (txt && txt.startsWith('/bot ')) { if (txt && txt.startsWith('/bot ')) {
builtinBotEmit(msg) builtinBotEmit(msg)
didEmit = true didEmit = true
} }
if (didEmit) return didEmit if (didEmit) return didEmit
console.log('=> is bot msg 5')
const botsInTribe = await models.ChatBot.findAll({ const botsInTribe = await models.ChatBot.findAll({
where: { where: {
chatId: chat.id chatId: chat.id
@ -48,7 +43,6 @@ export async function isBotMsg(msg: Msg, sentByMe: boolean): Promise<boolean> {
if (!(botsInTribe && botsInTribe.length)) return false if (!(botsInTribe && botsInTribe.length)) return false
console.log('=> is bot msg 6')
await asyncForEach(botsInTribe, async botInTribe => { await asyncForEach(botsInTribe, async botInTribe => {
if (botInTribe.msgTypes) { if (botInTribe.msgTypes) {
// console.log('=> botInTribe.msgTypes', botInTribe) // console.log('=> botInTribe.msgTypes', botInTribe)
@ -58,14 +52,12 @@ export async function isBotMsg(msg: Msg, sentByMe: boolean): Promise<boolean> {
const isMsgAndHasText = msgType === constants.message_types.message && txt && txt.startsWith(`${botInTribe.botPrefix} `) const isMsgAndHasText = msgType === constants.message_types.message && txt && txt.startsWith(`${botInTribe.botPrefix} `)
const isNotMsg = msgType !== constants.message_types.message const isNotMsg = msgType !== constants.message_types.message
if (isMsgAndHasText || isNotMsg) { if (isMsgAndHasText || isNotMsg) {
console.log('=> is bot msg emitMessageToBot',msg,botInTribe.dataValues)
didEmit = await emitMessageToBot(msg, botInTribe.dataValues) didEmit = await emitMessageToBot(msg, botInTribe.dataValues)
} }
} }
} catch (e) { } } catch (e) { }
} else { // no message types defined, do all? } else { // no message types defined, do all?
if (txt && txt.startsWith(`${botInTribe.botPrefix} `)) { if (txt && txt.startsWith(`${botInTribe.botPrefix} `)) {
console.log('=> is bot msg emitMessageToBot2',msg,botInTribe.dataValues)
// console.log('=> botInTribe.msgTypes else', botInTribe.dataValues) // console.log('=> botInTribe.msgTypes else', botInTribe.dataValues)
didEmit = await emitMessageToBot(msg, botInTribe.dataValues) didEmit = await emitMessageToBot(msg, botInTribe.dataValues)
} }

Loading…
Cancel
Save