git ssb

1+

cheerbitch / dexbot



Tree: b626415ac9a778373cd5c4b1dcd55f753b35fac8

Files: b626415ac9a778373cd5c4b1dcd55f753b35fac8 / index.js

1639 bytesRaw
1var secretStack =require('secret-stack')
2var sublevel = require('level-sublevel')
3var hyperlog = require('hyperlog')
4var swarmlog = require('swarmlog')
5
6var util = require('./util')
7var pull = require('pull-stream')
8var str2ps = require('stream-to-pull-stream')
9
10var keer = require('ssb-keys')
11var ws = require('ssb-ws')
12
13module.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