Browse Source

bot fees, organize bot utils, log

push-params
Evan Feenstra 4 years ago
parent
commit
dcf1ea1325
  1. 4
      api/controllers/bots.ts
  2. 1
      api/controllers/chats.ts
  3. 91
      api/utils/tribeBots.ts
  4. 96
      api/utils/tribes.ts
  5. 4
      dist/api/controllers/bots.js
  6. 2
      dist/api/controllers/bots.js.map
  7. 1
      dist/api/controllers/chats.js
  8. 2
      dist/api/controllers/chats.js.map
  9. 95
      dist/api/utils/tribeBots.js
  10. 1
      dist/api/utils/tribeBots.js.map
  11. 87
      dist/api/utils/tribes.js
  12. 2
      dist/api/utils/tribes.js.map

4
api/controllers/bots.ts

@ -129,9 +129,11 @@ export async function keysendBotInstall(b, chat_uuid:string): Promise<boolean> {
}
export async function keysendBotCmd(msg, b): Promise<boolean> {
const amount = msg.message.amount||0
const amt = Math.max(amount, b.pricePerUse)
return await botKeysend(
constants.message_types.bot_cmd,
b.botUuid, b.botMakerPubkey, b.pricePerUse,
b.botUuid, b.botMakerPubkey, amt,
msg.chat.uuid,
msg.message.content,
)

1
api/controllers/chats.ts

@ -283,6 +283,7 @@ export const deleteChat = async (req, res) => {
message: {},
type: constants.message_types.tribe_delete,
success: function () {
console.log("=> delete tribe", chat.uuid)
tribes.delete_tribe(chat.uuid)
},
failure: function(){

91
api/utils/tribeBots.ts

@ -0,0 +1,91 @@
import { models } from '../models'
import {getHost} from './tribes'
export async function declare_bot({ uuid, name, description, tags, img, price_per_use, owner_pubkey, unlisted, deleted }) {
const host = getHost()
try {
await fetch('https://' + host + '/bots', {
method: 'POST',
body: JSON.stringify({
uuid, owner_pubkey,
name, description, tags, img: img || '',
price_per_use: price_per_use || 0,
unlisted: unlisted || false,
deleted: deleted || false,
}),
headers: { 'Content-Type': 'application/json' }
})
// const j = await r.json()
// console.log('=> j',j)
} catch (e) {
console.log('[tribes] unauthorized to declare')
throw e
}
}
export async function makeBotsJSON(tribeID) {
const bots = await models.ChatBot.findAll({
where: {
chatId: tribeID
}
})
if (!bots) return []
if (!bots.length) return []
return bots.map(b => {
const bot = b.dataValues
if (bot.botPrefix === '/loopout') {
return loopoutBotJSON()
}
if (bot.botPrefix === '/testbot') {
return testBotJSON()
}
return <BotJSON>{
prefix: bot.botPrefix,
price: bot.pricePerUse||0,
commands: null,
}
})
}
interface BotJSON {
prefix: string,
price: number,
commands: BotCommand[] | null,
}
interface BotCommand {
command: string,
price: number,
min_price: number,
max_price: number,
price_index: number,
admin_only: boolean,
}
function loopoutBotJSON(): BotJSON {
return <BotJSON>{
prefix: '/loopout',
price: 0,
commands: [{
command: '*',
price: 0,
min_price: 250000,
max_price: 16777215,
price_index: 2,
admin_only: false
}]
}
}
function testBotJSON(): BotJSON {
return <BotJSON>{
prefix: '/testbot',
price: 0,
commands: [{
command: '*',
price: 0,
min_price: 20,
max_price: 50,
price_index: 1,
admin_only: false
}]
}
}

96
api/utils/tribes.ts

@ -6,6 +6,9 @@ import * as path from 'path'
import * as mqtt from 'mqtt'
import fetch from 'node-fetch'
import { models } from '../models'
import {makeBotsJSON, declare_bot} from './tribeBots'
export {declare_bot}
const env = process.env.NODE_ENV || 'development'
const config = require(path.join(__dirname, '../../config/app.json'))[env]
@ -101,28 +104,6 @@ export async function declare({ uuid, name, description, tags, img, group_key, h
}
}
export async function declare_bot({ uuid, name, description, tags, img, price_per_use, owner_pubkey, unlisted, deleted }) {
const host = getHost()
try {
await fetch('https://' + host + '/bots', {
method: 'POST',
body: JSON.stringify({
uuid, owner_pubkey,
name, description, tags, img: img || '',
price_per_use: price_per_use || 0,
unlisted: unlisted || false,
deleted: deleted || false,
}),
headers: { 'Content-Type': 'application/json' }
})
// const j = await r.json()
// console.log('=> j',j)
} catch (e) {
console.log('[tribes] unauthorized to declare')
throw e
}
}
export async function edit({ uuid, host, name, description, tags, img, price_per_message, price_to_join, owner_alias, escrow_amount, escrow_millis, unlisted, is_private, app_url, deleted }) {
try {
const token = await genSignedTimestamp()
@ -150,12 +131,12 @@ export async function edit({ uuid, host, name, description, tags, img, price_per
}
}
export async function delete_tribe({ uuid }) {
const host = getHost()
try {
const token = await genSignedTimestamp()
await fetch(`https://${host}/tribe/${uuid}?token=` + token, {
console.log('=> delete_tribe', `https://${host}/tribe/${uuid}?token=${token}`)
await fetch(`https://${host}/tribe/${uuid}?token=${token}`, {
method: 'DELETE',
})
// const j = await r.json()
@ -178,73 +159,6 @@ export async function putActivity(uuid: string, host: string) {
}
}
async function makeBotsJSON(tribeID) {
const bots = await models.ChatBot.findAll({
where: {
chatId: tribeID
}
})
if (!bots) return []
if (!bots.length) return []
return bots.map(b => {
const bot = b.dataValues
if (bot.botPrefix === '/loopout') {
return loopoutBotJSON()
}
if (bot.botPrefix === '/testbot') {
return testBotJSON()
}
return <BotJSON>{
prefix: bot.botPrefix,
price: bot.pricePerUse||0,
commands: null,
}
})
}
interface BotJSON {
prefix: string,
price: number,
commands: BotCommand[] | null,
}
interface BotCommand {
command: string,
price: number,
min_price: number,
max_price: number,
price_index: number,
admin_only: boolean,
}
function loopoutBotJSON(): BotJSON {
return <BotJSON>{
prefix: '/loopout',
price: 0,
commands: [{
command: '*',
price: 0,
min_price: 250000,
max_price: 16777215,
price_index: 2,
admin_only: false
}]
}
}
function testBotJSON(): BotJSON {
return <BotJSON>{
prefix: '/testbot',
price: 0,
commands: [{
command: '*',
price: 0,
min_price: 20,
max_price: 50,
price_index: 1,
admin_only: false
}]
}
}
export async function putstats({ uuid, host, member_count, chatId }) {
if (!uuid) return
const bots = await makeBotsJSON(chatId)

4
dist/api/controllers/bots.js

@ -139,7 +139,9 @@ function keysendBotInstall(b, chat_uuid) {
exports.keysendBotInstall = keysendBotInstall;
function keysendBotCmd(msg, b) {
return __awaiter(this, void 0, void 0, function* () {
return yield botKeysend(constants.message_types.bot_cmd, b.botUuid, b.botMakerPubkey, b.pricePerUse, msg.chat.uuid, msg.message.content);
const amount = msg.message.amount || 0;
const amt = Math.max(amount, b.pricePerUse);
return yield botKeysend(constants.message_types.bot_cmd, b.botUuid, b.botMakerPubkey, amt, msg.chat.uuid, msg.message.content);
});
}
exports.keysendBotCmd = keysendBotCmd;

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

File diff suppressed because one or more lines are too long

1
dist/api/controllers/chats.js

@ -277,6 +277,7 @@ exports.deleteChat = (req, res) => __awaiter(void 0, void 0, void 0, function* (
message: {},
type: constants.message_types.tribe_delete,
success: function () {
console.log("=> delete tribe", chat.uuid);
tribes.delete_tribe(chat.uuid);
},
failure: function () {

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

File diff suppressed because one or more lines are too long

95
dist/api/utils/tribeBots.js

@ -0,0 +1,95 @@
"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 models_1 = require("../models");
const tribes_1 = require("./tribes");
function declare_bot({ uuid, name, description, tags, img, price_per_use, owner_pubkey, unlisted, deleted }) {
return __awaiter(this, void 0, void 0, function* () {
const host = tribes_1.getHost();
try {
yield fetch('https://' + host + '/bots', {
method: 'POST',
body: JSON.stringify({
uuid, owner_pubkey,
name, description, tags, img: img || '',
price_per_use: price_per_use || 0,
unlisted: unlisted || false,
deleted: deleted || false,
}),
headers: { 'Content-Type': 'application/json' }
});
// const j = await r.json()
// console.log('=> j',j)
}
catch (e) {
console.log('[tribes] unauthorized to declare');
throw e;
}
});
}
exports.declare_bot = declare_bot;
function makeBotsJSON(tribeID) {
return __awaiter(this, void 0, void 0, function* () {
const bots = yield models_1.models.ChatBot.findAll({
where: {
chatId: tribeID
}
});
if (!bots)
return [];
if (!bots.length)
return [];
return bots.map(b => {
const bot = b.dataValues;
if (bot.botPrefix === '/loopout') {
return loopoutBotJSON();
}
if (bot.botPrefix === '/testbot') {
return testBotJSON();
}
return {
prefix: bot.botPrefix,
price: bot.pricePerUse || 0,
commands: null,
};
});
});
}
exports.makeBotsJSON = makeBotsJSON;
function loopoutBotJSON() {
return {
prefix: '/loopout',
price: 0,
commands: [{
command: '*',
price: 0,
min_price: 250000,
max_price: 16777215,
price_index: 2,
admin_only: false
}]
};
}
function testBotJSON() {
return {
prefix: '/testbot',
price: 0,
commands: [{
command: '*',
price: 0,
min_price: 20,
max_price: 50,
price_index: 1,
admin_only: false
}]
};
}
//# sourceMappingURL=tribeBots.js.map

1
dist/api/utils/tribeBots.js.map

@ -0,0 +1 @@
{"version":3,"file":"tribeBots.js","sourceRoot":"","sources":["../../../api/utils/tribeBots.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,sCAAkC;AAClC,qCAAgC;AAEhC,SAAsB,WAAW,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,EAAE,aAAa,EAAE,YAAY,EAAE,QAAQ,EAAE,OAAO,EAAE;;QACpH,MAAM,IAAI,GAAG,gBAAO,EAAE,CAAA;QACtB,IAAI;YACF,MAAM,KAAK,CAAC,UAAU,GAAG,IAAI,GAAG,OAAO,EAAE;gBACvC,MAAM,EAAE,MAAM;gBACd,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;oBACnB,IAAI,EAAE,YAAY;oBAClB,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE;oBACvC,aAAa,EAAE,aAAa,IAAI,CAAC;oBACjC,QAAQ,EAAE,QAAQ,IAAI,KAAK;oBAC3B,OAAO,EAAE,OAAO,IAAI,KAAK;iBAC1B,CAAC;gBACF,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;aAChD,CAAC,CAAA;YACF,2BAA2B;YAC3B,wBAAwB;SACzB;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,CAA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AE,GAAG;gBACZ,KAAK,EAAE,CAAC;gBACR,SAAS,EAAE,EAAE;gBACb,SAAS,EAAE,EAAE;gBACb,WAAW,EAAE,CAAC;gBACd,UAAU,EAAE,KAAK;aAClB,CAAC;KACH,CAAA;AACH,CAAC"}

87
dist/api/utils/tribes.js

@ -16,6 +16,8 @@ const path = require("path");
const mqtt = require("mqtt");
const node_fetch_1 = require("node-fetch");
const models_1 = require("../models");
const tribeBots_1 = require("./tribeBots");
exports.declare_bot = tribeBots_1.declare_bot;
const env = process.env.NODE_ENV || 'development';
const config = require(path.join(__dirname, '../../config/app.json'))[env];
let client;
@ -123,31 +125,6 @@ function declare({ uuid, name, description, tags, img, group_key, host, price_pe
});
}
exports.declare = declare;
function declare_bot({ uuid, name, description, tags, img, price_per_use, owner_pubkey, unlisted, deleted }) {
return __awaiter(this, void 0, void 0, function* () {
const host = getHost();
try {
yield node_fetch_1.default('https://' + host + '/bots', {
method: 'POST',
body: JSON.stringify({
uuid, owner_pubkey,
name, description, tags, img: img || '',
price_per_use: price_per_use || 0,
unlisted: unlisted || false,
deleted: deleted || false,
}),
headers: { 'Content-Type': 'application/json' }
});
// const j = await r.json()
// console.log('=> j',j)
}
catch (e) {
console.log('[tribes] unauthorized to declare');
throw e;
}
});
}
exports.declare_bot = declare_bot;
function edit({ uuid, host, name, description, tags, img, price_per_message, price_to_join, owner_alias, escrow_amount, escrow_millis, unlisted, is_private, app_url, deleted }) {
return __awaiter(this, void 0, void 0, function* () {
try {
@ -183,7 +160,8 @@ function delete_tribe({ uuid }) {
const host = getHost();
try {
const token = yield genSignedTimestamp();
yield node_fetch_1.default(`https://${host}/tribe/${uuid}?token=` + token, {
console.log('=> delete_tribe', `https://${host}/tribe/${uuid}?token=${token}`);
yield node_fetch_1.default(`https://${host}/tribe/${uuid}?token=${token}`, {
method: 'DELETE',
});
// const j = await r.json()
@ -211,66 +189,11 @@ function putActivity(uuid, host) {
});
}
exports.putActivity = putActivity;
function makeBotsJSON(tribeID) {
return __awaiter(this, void 0, void 0, function* () {
const bots = yield models_1.models.ChatBot.findAll({
where: {
chatId: tribeID
}
});
if (!bots)
return [];
if (!bots.length)
return [];
return bots.map(b => {
const bot = b.dataValues;
if (bot.botPrefix === '/loopout') {
return loopoutBotJSON();
}
if (bot.botPrefix === '/testbot') {
return testBotJSON();
}
return {
prefix: bot.botPrefix,
price: bot.pricePerUse || 0,
commands: null,
};
});
});
}
function loopoutBotJSON() {
return {
prefix: '/loopout',
price: 0,
commands: [{
command: '*',
price: 0,
min_price: 250000,
max_price: 16777215,
price_index: 2,
admin_only: false
}]
};
}
function testBotJSON() {
return {
prefix: '/testbot',
price: 0,
commands: [{
command: '*',
price: 0,
min_price: 20,
max_price: 50,
price_index: 1,
admin_only: false
}]
};
}
function putstats({ uuid, host, member_count, chatId }) {
return __awaiter(this, void 0, void 0, function* () {
if (!uuid)
return;
const bots = yield makeBotsJSON(chatId);
const bots = yield tribeBots_1.makeBotsJSON(chatId);
try {
const token = yield genSignedTimestamp();
yield node_fetch_1.default('https://' + host + '/tribestats?token=' + token, {

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

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save