12 changed files with 208 additions and 178 deletions
@ -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 |
||||
|
}] |
||||
|
} |
||||
|
} |
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -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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AG,CAAC,CAAC,CAAC,EAAE;YAClB,MAAM,GAAG,GAAG,CAAC,CAAC,UAAU,CAAA;YACxB,IAAI,GAAG,CAAC,SAAS,KAAK,UAAU,EAAE;gBAChC,OAAO,cAAc,EAAE,CAAA;aACxB;YACD,IAAI,GAAG,CAAC,SAAS,KAAK,UAAU,EAAE;gBAChC,OAAO,WAAW,EAAE,CAAA;aACrB;YACD,OAAgB;gBACd,MAAM,EAAE,GAAG,CAAC,SAAS;gBACrB,KAAK,EAAE,GAAG,CAAC,WAAW,IAAE,CAAC;gBACzB,QAAQ,EAAE,IAAI;aACf,CAAA;QACH,CAAC,CAAC,CAAA;IACJ,CAAC;CAAA;AAtBH,oCAsBG;AAeD,SAAS,cAAc;IACrB,OAAgB;QACd,MAAM,EAAE,UAAU;QAClB,KAAK,EAAE,CAAC;QACR,QAAQ,EAAE,CAAC;gBACT,OAAO,EAAE,GAAG;gBACZ,KAAK,EAAE,CAAC;gBACR,SAAS,EAAE,MAAM;gBACjB,SAAS,EAAE,QAAQ;gBACnB,WAAW,EAAE,CAAC;gBACd,UAAU,EAAE,KAAK;aAClB,CAAC;KACH,CAAA;AACH,CAAC;AAED,SAAS,WAAW;IAClB,OAAgB;QACd,MAAM,EAAE,UAAU;QAClB,KAAK,EAAE,CAAC;QACR,QAAQ,EAAE,CAAC;gBACT,OAAO,EAAE,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"} |
File diff suppressed because one or more lines are too long
Loading…
Reference in new issue