diff --git a/.DS_Store b/.DS_Store index 6de0c4d..7514f20 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/bot.js b/bot.js index 061a917..4852d49 100644 --- a/bot.js +++ b/bot.js @@ -3,6 +3,7 @@ const Discord = require('discord.js'); const WGET = require('wget-improved'); const IPFS = require('ipfs-http-client')('localhost',Config.IPFS_API_Port,{protocol: 'http'}) const Steem = require('steem'); +const async = require('async') const Auth = require('./auth.json'); const fs = require('fs'); @@ -159,6 +160,8 @@ bot.on('message', (message) => { addHashToDatabase(message,ipfs240hash); addDTubeVideoToIPFS(message,ipfs240hash,Config.trickledag,Config.VIDEO_DOWNLOAD_COMPLETE); }); + } else { + message.channel.send(Config.IPFS_PIN_LS_ERROR + err) } }) }); @@ -224,6 +227,8 @@ bot.on('message', (message) => { addHashToDatabase(message,ipfs480hash); addDTubeVideoToIPFS(message,ipfs480hash,Config.trickledag,Config.VIDEO_DOWNLOAD_COMPLETE); }); + } else { + message.channel.send(Config.IPFS_PIN_LS_ERROR + err) } }) }); @@ -294,6 +299,8 @@ bot.on('message', (message) => { addHashToDatabase(message,ipfs720hash); addDTubeVideoToIPFS(message,ipfs720hash,Config.trickledag,Config.VIDEO_DOWNLOAD_COMPLETE); }); + } else { + message.channel.send(Config.IPFS_PIN_LS_ERROR + err) } }) }); @@ -366,6 +373,8 @@ bot.on('message', (message) => { addHashToDatabase(message,ipfs1080hash); addDTubeVideoToIPFS(message,ipfs1080hash,Config.trickledag,Config.VIDEO_DOWNLOAD_COMPLETE); }); + } else { + message.channel.send(Config.IPFS_PIN_LS_ERROR + err) } }) }); @@ -416,6 +425,8 @@ bot.on('message', (message) => { addHashToDatabase(message,dsoundhash) addDTubeVideoToIPFS(message,dsoundhash,false,Config.AUDIO_DOWNLOAD_COMPLETE) }); + } else { + message.channel.send(Config.IPFS_PIN_LS_ERROR + err) } }) }); @@ -571,6 +582,64 @@ bot.on('message', (message) => { } else { sendMessage(message,Config.ERROR_NO_PERMISSION); } + } else if (message.content == Config.commandPrefix + 'stats') { + let statops = { + bw: (cb) => { + IPFS.stats.bw((err,stat) => { + if (err != null) { + console.log(err) + cb(err,null) + return + } + let incomingbw = Math.floor(stat.rateIn / 10.24) / 100 + ' KB/s' + let outgoingbw = Math.floor(stat.rateOut / 10.24) / 100 + ' KB/s' + + if (stat.rateIn > 1000000) + incomingbw = Math.floor(stat.rateIn / 10485.76) / 100 + ' MB/s' + + if (stat.rateOut > 1000000) + outgoingbw = Math.floor(stat.rateOut / 10485.76) / 100 + ' MB/s' + cb(null,{ + in: incomingbw, + out: outgoingbw + }) + }) + }, + storage: (cb) => { + IPFS.stats.repo({human: true},(err,stat) => { + if (err != null) { + console.log(err) + cb(err,null) + return + } + let size = Math.floor(stat.repoSize / 10485.76) / 100 + ' MB' + if (stat.repoSize > 1000000000) + size = Math.floor(stat.repoSize / 10737418.24) / 100 + ' GB' + cb(null,size) + }) + }, + pincount: (cb) => { + IPFS.pin.ls({type: 'recursive'},(err,pinset) => { + if (err != null) { + console.log(err) + cb(err,null) + return + } + cb(null,pinset.length) + }) + } + } + async.parallel(statops,(err,results) => { + if (err != null) { + message.channel.send(Config.IPFS_STAT_ERROR) + } else { + let embed = new Discord.RichEmbed() + embed.setTitle(Config.IPFS_STAT_EMBED_TITLE) + embed.setDescription('Bandwidth In: ' + results.bw.in + '\nBandwidth Out: ' + results.bw.out + '\nNo. of pins: ' + results.pincount + '\nUsed storage: ' + results.storage) + embed.setColor(0x499293); + message.channel.send(embed) + } + }) } else if (message.content == (Config.commandPrefix + 'ipfshelp')) { if (Config.silentModeEnabled != true) { // Bot command list diff --git a/config.json b/config.json index 7c147cf..e6ad4d7 100644 --- a/config.json +++ b/config.json @@ -49,6 +49,8 @@ "HELP_IPFSHELP": "Shows this cheatsheet with all available commands for this bot.", "HELP_PING": "Use this to check if bots are online!", "IPFS_PIN_LS_ERROR": "IPFS API error: ", + "IPFS_STAT_ERROR": "An error occured! Check the logs for more details.", + "IPFS_STAT_EMBED_TITLE": "IPFS Node Stats", "WHITELIST_FILE404": "Hmmm the whitelist file doesn't exist in this bot. Perhaps the file could have been misplaced in the bot server? :thinking:", "WHITELIST_TRUE": "You're in the whitelist! You may pin your DTube videos at 720p, 1080p and source resolution to our IPFS node :wink:", "WHITELIST_FALSE": "Sorry, you're not in the whitelist. Perhaps contact the admins of this server to find out how to get there? :thinking:", diff --git a/package-lock.json b/package-lock.json index a0f3f74..b97e6e3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -38,13 +38,6 @@ "integrity": "sha512-H1qVYh1MYhEEFLsP97cVKqCGo7KfCyTt6uEWqsTBr9SO84oK9Uwbyd/yCW+6rKJLHksBNUVWZDAjfS+Ccx0Bbg==", "requires": { "lodash": "^4.17.11" - }, - "dependencies": { - "lodash": { - "version": "4.17.11", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", - "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==" - } } }, "async-limiter": { diff --git a/package.json b/package.json index dd7af14..db7a4a1 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "main": "bot.js", "author": "techcoderx", "dependencies": { + "async": "^2.6.2", "discord.js": "^11.4.2", "fs": "0.0.1-security", "ipfs-http-client": "^29.1.1",