Files: b626415ac9a778373cd5c4b1dcd55f753b35fac8 / index.js
1639 bytesRaw
1 | var secretStack =require('secret-stack') |
2 | var sublevel = require('level-sublevel') |
3 | var hyperlog = require('hyperlog') |
4 | var swarmlog = require('swarmlog') |
5 | |
6 | var util = require('./util') |
7 | var pull = require('pull-stream') |
8 | var str2ps = require('stream-to-pull-stream') |
9 | |
10 | var keer = require('ssb-keys') |
11 | var ws = require('ssb-ws') |
12 | |
13 | module.exports = function(bot){ |
14 | |
15 | var self = bot // u kno, u wrong! |
16 | var memdb = bot.db // db.sublevel(...) |
17 | var keys = bot.keys |
18 | bot.log = hyperlog(memdb.sublevel(bot.keys.id)) |
19 | var node |
20 | |
21 | var errLogDB = hyperlog(memdb.sublevel(bot.id + ':errLog')) |
22 | |
23 | var errLog = function(cb){ |
24 | return function(err, data){ |
25 | if(err){ // drop it in the log |
26 | errLogDB.append(JSON.stringify(err)) |
27 | } |
28 | else if(cb) cb(data) |
29 | } |
30 | } |
31 | |
32 | |
33 | var createApp = secretStack({ |
34 | appKey: bot.appKey || new Buffer('00000000000000000000000000000000'), |
35 | timers: { |
36 | inactivity: 0, |
37 | handshake: 0 |
38 | } |
39 | }).use(require('./core/')) |
40 | //.use(ws) |
41 | |
42 | var logs = {} |
43 | node = createApp({ |
44 | keys: keys, |
45 | errLogDB: errLogDB, |
46 | errLogger: errLog, |
47 | log: bot.log, |
48 | logs: logs, |
49 | db: memdb, |
50 | self: bot, |
51 | name: bot.name |
52 | }) |
53 | //console.log(node, node.address()) |
54 | bot.address = util.parseAddress(node.address()) |
55 | bot.do = {} |
56 | bot.logs = logs |
57 | bot.host = node.address() |
58 | node.auth.hook(function(auth, args){ |
59 | var bot = args[0] |
60 | var cb = args[1] |
61 | //console.log(bot) |
62 | auth(bot, function(err, perms){ |
63 | //console.log(perms) |
64 | cb(null, {'sign':true, 'log': true}) |
65 | }) |
66 | }) |
67 | Object.assign(bot.do, node.dexbot) |
68 | bot.on = node.on |
69 | bot.emit = node.emit |
70 | return bot |
71 | |
72 | } |
73 |
Built with git-ssb-web